diff --git a/Makefile b/Makefile index 583b598..afad09f 100644 --- a/Makefile +++ b/Makefile @@ -55,5 +55,7 @@ install: $(PROGRAMS) install -D programs/sxmo_megiaudioroute $(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 diff --git a/scripts/core/sxmo_migrate.sh b/scripts/core/sxmo_migrate.sh index d49ebf2..9e70444 100644 --- a/scripts/core/sxmo_migrate.sh +++ b/scripts/core/sxmo_migrate.sh @@ -1,5 +1,9 @@ #!/usr/bin/env sh +# include common definitions +# shellcheck source=scripts/core/sxmo_common.sh +. "$(which sxmo_common.sh)" + smartdiff() { if command -v colordiff > /dev/null; then colordiff "$@" @@ -19,13 +23,44 @@ defaultconfig() { 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]\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 if [ "y" = "$reply" ]; then cp "$1" "$2" + elif [ "e" = "$reply" ]; then + $EDITOR "$2" "$1" 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 +checkhooks