81 lines
2.1 KiB
Bash
81 lines
2.1 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
|
||
|
|
# 26.03.05 :: klevstul
|
||
|
|
|
||
|
|
|
||
|
|
continue_if_yes() {
|
||
|
|
# -n 1: Reads only one character.
|
||
|
|
# -r: Prevents backslash interpretation.
|
||
|
|
# Case handling: Accepts both uppercase and lowercase y/Y and n/N.
|
||
|
|
# Default behavior: Pressing Enter defaults to n, avoiding accidental continuation.
|
||
|
|
# Loop: Repeats until valid input is given.
|
||
|
|
local prompt="${1:-continue?: }"
|
||
|
|
while true; do
|
||
|
|
echo ""
|
||
|
|
read -r -n 1 -p "$prompt [y/n]:" answer
|
||
|
|
case "$answer" in
|
||
|
|
[Yy])
|
||
|
|
echo # Move to next line after input
|
||
|
|
return 0 # Continue execution
|
||
|
|
;;
|
||
|
|
[Nn]|"")
|
||
|
|
echo # Move to next line
|
||
|
|
return 1 # Exit or skip action
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
echo -e "\nplease answer 'y' or 'n'."
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
done
|
||
|
|
}
|
||
|
|
|
||
|
|
backupDeploy() {
|
||
|
|
|
||
|
|
local operation=$1
|
||
|
|
local repo_dir="/home/poq/syncDir/gitRepos/gi.op.fo/lnx-arch/dots/nwg-panel"
|
||
|
|
local nwgp_dir="/home/poq/.config/nwg-panel"
|
||
|
|
local filenames=("common-settings.json" "config" "style.css")
|
||
|
|
local files=()
|
||
|
|
|
||
|
|
if [[ "${operation}" == "backup" ]]; then
|
||
|
|
echo -e "\nthe following files will be copied to the repository (old files in the repo will be overwritten):"
|
||
|
|
|
||
|
|
for filename in "${filenames[@]}"; do
|
||
|
|
local file="${nwgp_dir}/${filename}"
|
||
|
|
echo "- ${file}"
|
||
|
|
files+=(${file})
|
||
|
|
done
|
||
|
|
|
||
|
|
if continue_if_yes "would you like to proceed?"; then
|
||
|
|
|
||
|
|
echo "proceeding..."
|
||
|
|
|
||
|
|
for file in "${files[@]}"; do
|
||
|
|
cp ${file} ${repo_dir}/
|
||
|
|
done
|
||
|
|
|
||
|
|
else
|
||
|
|
echo "operation cancelled."
|
||
|
|
fi
|
||
|
|
|
||
|
|
|
||
|
|
elif [[ "${operation}" == "deploy" ]]; then
|
||
|
|
echo "deploy"
|
||
|
|
|
||
|
|
# pkill nwg-panel
|
||
|
|
# nwg-panel &
|
||
|
|
else
|
||
|
|
echo "error: unknown operation '${operation}'"
|
||
|
|
fi
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
this_file_name=`basename "$0"`
|
||
|
|
if [ $# -lt 1 ]; then
|
||
|
|
echo "error: operation {backup|deploy} is missing."
|
||
|
|
echo "usage: '$this_file_name {backup|deploy}'"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
backupDeploy $1
|