diff --git a/.gitignore b/.gitignore index 37211d2..a77b4a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ curl/* !curl/.gitkeep +saved/* +!saved/.gitkeep + disable_peer_validation diff --git a/save.sh b/save.sh new file mode 100755 index 0000000..f019107 --- /dev/null +++ b/save.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +SAVE_DIR="saved" + +main () { + case "$1" in + # Save current config to a named directory + "save") + if [ "$#" -ne 2 ]; then + echo -e "\e[0;91mExpected: ./save.sh save \e[0m" + return 1 + fi + + local dir="$SAVE_DIR/$2" + + mkdir $dir 2>/dev/null + + shopt -s nullglob + + for file in "curl/req_"*; do + cp -- "$file" $dir + done + + shopt -u nullglob + echo "Saved current configuration to: $2" + ;; + + # Move current config to a named directory + "move") + if [ "$#" -ne 2 ]; then + echo -e "\e[0;91mExpected: ./save.sh move \e[0m" + return 1 + fi + + # Save config to destination + ./save.sh save $2 + + shopt -s nullglob + + for file in "curl/req_"*; do + rm -- "$file" + done + + shopt -u nullglob + + # Create new empty config + ./init.sh + ;; + + # Load saved config by name from directory + "load") + local dir="$SAVE_DIR/$2" + + if [ ! -d $dir ]; then + echo -e "\e[0;91mNo save with name '$2' found\e[0m" + exit 1 + fi + + # Move existing config to backup directory + ./save.sh move ._backup + + shopt -s nullglob + + for file in "$dir/req_"*; do + cp -- "$file" curl/ + done + + shopt -u nullglob + echo "Loaded configuration: $2" + ;; + + "list") + ls -l $SAVE_DIR + ;; + + *) + echo -e "\e[0;91mExpected: ./save.sh (save|move|load|list)\e[0m" + ;; + esac +} + +main $1 $2 diff --git a/saved/.gitkeep b/saved/.gitkeep new file mode 100644 index 0000000..e69de29