Refactorise a little bit sxmo_migrate.sh

Some code could be deduplicated.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
master
Stacy Harper 3 years ago committed by Maarten van Gompel
parent cfa15765e2
commit 6dce18e579
  1. 42
      scripts/core/sxmo_migrate.sh

@ -12,6 +12,24 @@ smartdiff() {
fi
}
resolvedifference() {
userfile="$1"
defaultfile="$2"
(
printf "\e[31mThe file \e[32m%s\e[31m differs\e[0m\n" "$userfile"
smartdiff -ud "$userfile" "$defaultfile"
) | less -RF
printf "\e[33mDo you want to apply the default? [y/N], or perhaps open an editor [e]?\e[0m "
read -r reply < /dev/tty
if [ "y" = "$reply" ]; then
cp "$defaultfile" "$userfile"
elif [ "e" = "$reply" ]; then
$EDITOR "$userfile" "$defaultfile"
fi
}
defaultconfig() {
if [ ! -r "$2" ]; then
mkdir -p "$(dirname "$2")"
@ -19,17 +37,7 @@ defaultconfig() {
chmod "$3" "$2"
else
if ! diff "$2" "$1" > /dev/null; then
(
printf "\e[31mThe file \e[32m%s\e[31m differs\e[0m\n" "$2"
smartdiff -ud "$2" "$1"
) | less -RF
printf "\e[33mDo you want to apply the default? [y/N], or perhaps open an editor [e]?\e[0m "
read -r reply < /dev/tty
if [ "y" = "$reply" ]; then
cp "$1" "$2"
elif [ "e" = "$reply" ]; then
$EDITOR "$2" "$1"
fi
resolvedifference "$2" "$1"
fi
fi
}
@ -40,17 +48,7 @@ checkhooks() {
defaulthook="/usr/share/sxmo/default_hooks/$(basename "$hook")"
if [ -f "$defaulthook" ]; then
if ! diff "$hook" "$defaulthook" > /dev/null; then
(
printf "\e[31mThe file \e[32m%s\e[31m differs\e[0m\n" "$hook"
smartdiff -ud "$hook" "$defaulthook"
) | less -RF
printf "\e[33mDo you want to remove the custom hook and fall back to the default? [y/N], or perhaps open an editor [e]?\e[0m"
read -r reply < /dev/tty
if [ "y" = "$reply" ]; then
rm "$hook"
elif [ "e" = "$reply" ]; then
$EDITOR "$hook" "$defaulthook"
fi
resolvedifference "$hook" "$defaulthook"
else
printf "\e[33mHook %s is identical to the default, so you don't need a custom hook, remove it? [Y/n]\e[0m" "$hook"
if [ "n" != "$reply" ]; then

Loading…
Cancel
Save