check custom hooks against defaults in sxmo_migrate.sh and allow user to open editor immediately

Signed-off-by: Stacy Harper <contact@stacyharper.net>
master
Maarten van Gompel 3 years ago committed by Stacy Harper
parent 41e66a0164
commit 3ff244a3e5
No known key found for this signature in database
GPG Key ID: 5BAC92328B7C5D65
  1. 4
      Makefile
  2. 37
      scripts/core/sxmo_migrate.sh

@ -55,5 +55,7 @@ install: $(PROGRAMS)
install -D programs/sxmo_megiaudioroute $(DESTDIR)$(PREFIX)/bin/ install -D programs/sxmo_megiaudioroute $(DESTDIR)$(PREFIX)/bin/
install -D programs/sxmo_vibratepine $(DESTDIR)$(PREFIX)/bin/ install -D programs/sxmo_vibratepine $(DESTDIR)$(PREFIX)/bin/
echo "NOTICE: Do not forget to add sxmo-setpermissions to your init system, e.g. for openrc: rc-update add sxmo-setpermissions default && rc-service sxmo-setpermissions start" >&2 echo "NOTICE 1: Do not forget to add sxmo-setpermissions to your init system, e.g. for openrc: rc-update add sxmo-setpermissions default && rc-service sxmo-setpermissions start" >&2
echo "NOTICE 2: It is recommended you interactively run sxmo_migrate.sh after an upgrade to check your configuration files and custom hooks against the defaults (it will not make any changes unless explicitly told to)" >&2

@ -1,5 +1,9 @@
#!/usr/bin/env sh #!/usr/bin/env sh
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. "$(which sxmo_common.sh)"
smartdiff() { smartdiff() {
if command -v colordiff > /dev/null; then if command -v colordiff > /dev/null; then
colordiff "$@" colordiff "$@"
@ -19,13 +23,44 @@ defaultconfig() {
printf "\e[31mThe file \e[32m%s\e[31m differs\e[0m\n" "$2" printf "\e[31mThe file \e[32m%s\e[31m differs\e[0m\n" "$2"
smartdiff -ud "$2" "$1" smartdiff -ud "$2" "$1"
) | less -RF ) | less -RF
printf "\e[33mDo you want to apply the default? [y/N]\e[0m " printf "\e[33mDo you want to apply the default? [y/N], or perhaps open an editor [e]?\e[0m "
read -r reply < /dev/tty read -r reply < /dev/tty
if [ "y" = "$reply" ]; then if [ "y" = "$reply" ]; then
cp "$1" "$2" cp "$1" "$2"
elif [ "e" = "$reply" ]; then
$EDITOR "$2" "$1"
fi fi
fi fi
fi fi
} }
checkhooks() {
if [ -e "$XDG_CONFIG_HOME/sxmo/hooks/" ]; then
for hook in "$XDG_CONFIG_HOME/sxmo/hooks/"*; do
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
else
printf "\e[33mHook $hook is identical to the default, so you don't need a custom hook, remove it? [Y/n]\e[0m"
if [ "n" != "$reply" ]; then
rm "$hook"
fi
fi
fi
done
fi
}
defaultconfig /usr/share/sxmo/appcfg/xinit_template "$XDG_CONFIG_HOME/sxmo/xinit" 744 defaultconfig /usr/share/sxmo/appcfg/xinit_template "$XDG_CONFIG_HOME/sxmo/xinit" 744
checkhooks

Loading…
Cancel
Save