101 lines
2.8 KiB
Bash
Executable File
101 lines
2.8 KiB
Bash
Executable File
#!/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() {
|
|
|
|
# Key Options for Copy:
|
|
# -r (recursive): Recursive copying.
|
|
# -v (verbose): Show each file as it is copied.
|
|
# -p (preserve): Keep original file permissions, ownership, and timestamps.
|
|
# -i (interactive): Prompt before overwriting existing files.
|
|
# -n (no-clobber): Skip copying if the destination file exists.
|
|
# -u (update): Copy only when the source is newer than the destination.
|
|
|
|
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 -v ${file} ${repo_dir}/
|
|
done
|
|
|
|
else
|
|
echo "operation cancelled."
|
|
fi
|
|
|
|
|
|
elif [[ "${operation}" == "restore" ]]; then
|
|
|
|
echo "restoring config files (copy from repo) and restarting nwg-panel..."
|
|
|
|
cp -v -r ${repo_dir}/* ${nwgp_dir}
|
|
pkill nwg-panel > /dev/null 2>&1
|
|
nwg-panel > /dev/null 2>&1 &
|
|
|
|
elif [[ "${operation}" == "restart" ]]; then
|
|
|
|
echo "restarting nwg-panel..."
|
|
|
|
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|restore|restart} is missing."
|
|
echo "usage: '$this_file_name {backup|restore|restart}'"
|
|
exit 1
|
|
fi
|
|
|
|
backupDeploy $1
|