Script file and ReadMe
parent
a185588a4c
commit
a29678b0ff
|
|
@ -0,0 +1,136 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# ============================================================================================
|
||||||
|
# Script for Bulk Creating Pass Entries Based on a JSON File
|
||||||
|
# ============================================================================================
|
||||||
|
#
|
||||||
|
: '
|
||||||
|
|
||||||
|
Title :
|
||||||
|
PassBatchInsert.sh
|
||||||
|
|
||||||
|
Usage :
|
||||||
|
Automate inserts of pass (password-store) entries based on a JSON file or input.
|
||||||
|
|
||||||
|
Requires:
|
||||||
|
|
||||||
|
jq
|
||||||
|
> brew install jq
|
||||||
|
|
||||||
|
Model :
|
||||||
|
{
|
||||||
|
filename:'',
|
||||||
|
password:'',
|
||||||
|
url:'',
|
||||||
|
user:''
|
||||||
|
}
|
||||||
|
|
||||||
|
';
|
||||||
|
|
||||||
|
|
||||||
|
###################### VARS ######################
|
||||||
|
|
||||||
|
|
||||||
|
DATE_CUR=$(date '+%Y-%m-%d__%H:%M:%S');
|
||||||
|
|
||||||
|
SCRIPT_NAME="PassBatchInsert";
|
||||||
|
|
||||||
|
SCRIPT_DIR=$(dirname "$0");
|
||||||
|
|
||||||
|
JSON_FILE=$SCRIPT_DIR/input/$SCRIPT_NAME.json;
|
||||||
|
|
||||||
|
SCRIPT_TMP="$SCRIPT_DIR/log/$SCRIPT_NAME.tmp";
|
||||||
|
|
||||||
|
SCRIPT_LOG="$SCRIPT_DIR/log/$SCRIPT_NAME.log";
|
||||||
|
|
||||||
|
LOG_BEGIN="
|
||||||
|
=================================================================
|
||||||
|
|| ||
|
||||||
|
|| $SCRIPT_NAME ||
|
||||||
|
|| $DATE_CUR ||
|
||||||
|
|| ||
|
||||||
|
=================================================================";
|
||||||
|
|
||||||
|
LOG_END="
|
||||||
|
=================================================================
|
||||||
|
||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||
|
||||||
|
=================================================================";
|
||||||
|
|
||||||
|
|
||||||
|
################## LOG STUFF ####################
|
||||||
|
|
||||||
|
|
||||||
|
function start_log() {
|
||||||
|
echo -e "$LOG_BEGIN" | tee -a $SCRIPT_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
function end_log() {
|
||||||
|
echo -e "$LOG_END" | tee -a $SCRIPT_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
function echo_log() {
|
||||||
|
echo -e "\n -:- $1\n" | tee -a $SCRIPT_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
function echo_error() {
|
||||||
|
echo -e "\n$SCRIPT_NAME ~ GENERAL SCRIPT ERROR: \n$1\n" | tee -a $SCRIPT_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
function arg_error() {
|
||||||
|
echo -e "\n$SCRIPT_NAME ~ REQUIRED ARGUMENT NOT FOUND: \n$1\n" | tee -a $SCRIPT_LOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
################## PROCEDURES ####################
|
||||||
|
|
||||||
|
|
||||||
|
function process_json_entries() {
|
||||||
|
|
||||||
|
# Load JSON Input
|
||||||
|
JSON_LENGTH=$(jq -r '. | length' $JSON_FILE);
|
||||||
|
|
||||||
|
# Loop Through JSON_INPUT And Insert Pass Entries
|
||||||
|
if [[ JSON_LENGTH > 0 ]]; then
|
||||||
|
for (( i=0; i<$JSON_LENGTH; i++ )); do
|
||||||
|
path=$(jq -r ".[${i}].path" $JSON_FILE);
|
||||||
|
filename=$(jq -r ".[${i}].filename" $JSON_FILE);
|
||||||
|
password=$(jq -r ".[${i}].password" $JSON_FILE);
|
||||||
|
url=$(jq -r ".[${i}].url" $JSON_FILE);
|
||||||
|
user=$(jq -r ".[${i}].user" $JSON_FILE);
|
||||||
|
|
||||||
|
# Start Log
|
||||||
|
echo -e "\nProcessing Entry for: $user at $url" | tee -a $SCRIPT_LOG;
|
||||||
|
|
||||||
|
# Check If Entry Exists
|
||||||
|
check_for_entry=$(pass ls "$path/$filename");
|
||||||
|
|
||||||
|
# If New, Enter
|
||||||
|
if [ -z "$check_for_entry" ]; then
|
||||||
|
echo -e "-- Adding New Entry -- $path/$filename." | tee -a $SCRIPT_LOG;
|
||||||
|
echo -e "$password\nurl: $url\nuser: $user" | pass insert -m "$path/$filename";
|
||||||
|
else
|
||||||
|
echo -e "-- Skipping Entry -- entry already exists." | tee -a $SCRIPT_LOG;
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo -e "\n\n !!! Init Fail -- Unable to load the JSON file !!!\n" | tee -a $SCRIPT_LOG;
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
##################### MAIN ######################
|
||||||
|
|
||||||
|
|
||||||
|
function main_process() {
|
||||||
|
process_json_entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
###################### INIT ######################
|
||||||
|
|
||||||
|
|
||||||
|
start_log;
|
||||||
|
main_process;
|
||||||
|
end_log;
|
||||||
|
exit 1;
|
||||||
51
README.md
51
README.md
|
|
@ -1,3 +1,50 @@
|
||||||
# PassBatchInsert
|
# [PassBatchInsert](https://gitea.dubtempo.com/DT/PassBatchInsert)
|
||||||
|
|
||||||
This script is used to batch import passwords from a json file into the password management program: password-store, aka "pass".
|
This script is used to batch import passwords from a json file into the password management program: password-store, aka "pass".
|
||||||
|
|
||||||
|
<br \>
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
Make sure all dependencies have been installed before using this script:
|
||||||
|
* [Password Store](https://www.passwordstore.org/) >= 1.7.4 -- prior untested
|
||||||
|
|
||||||
|
<br \>
|
||||||
|
|
||||||
|
## Project Installation
|
||||||
|
|
||||||
|
Install this project via git pull:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# from your new project parent dir
|
||||||
|
$ git clone https://gitea.dubtempo.com/DT/PassBatchInsert.git
|
||||||
|
```
|
||||||
|
|
||||||
|
Make sure the script file is executable.
|
||||||
|
|
||||||
|
## Password Details Model
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
filename:'',
|
||||||
|
password:'',
|
||||||
|
url:'',
|
||||||
|
user:''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
<br \>
|
||||||
|
|
||||||
|
## Project Usage
|
||||||
|
|
||||||
|
To use this codebase, complete the following steps.
|
||||||
|
|
||||||
|
1. Add your passwords to the PassBatchInser.json file following the model.
|
||||||
|
|
||||||
|
1. Run the script using the following command:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ PassBatchInsert.sh
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"path": "",
|
||||||
|
"filename": "",
|
||||||
|
"password": "",
|
||||||
|
"url": "",
|
||||||
|
"user": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
Loading…
Reference in New Issue