mirror of
https://codeberg.org/vlw/curl.git
synced 2026-04-12 18:29:38 +02:00
In this PR we add the ability to save, move, and load configurations with a new `save.sh` script. Reviewed-on: https://codeberg.org/vlw/curl/pulls/5 Co-authored-by: vlw <victor@vlw.se> Co-committed-by: vlw <victor@vlw.se>
82 lines
1.3 KiB
Bash
Executable file
82 lines
1.3 KiB
Bash
Executable file
#!/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 <name>\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 <name>\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
|