diff options
| author | emmett1 <emmett1.2miligrams@protonmail.com> | 2024-04-15 11:38:09 +0800 |
|---|---|---|
| committer | emmett1 <emmett1.2miligrams@protonmail.com> | 2024-04-15 11:38:09 +0800 |
| commit | cf7e15afc0af0b15436a79d125703af5105be67b (patch) | |
| tree | be3179eb36c5da9bd8f65c0f5da580d534d6289f /updateconf | |
| parent | cf41ee19b9776b02b814dfde6bcd5051481d04c2 (diff) | |
| download | autils-cf7e15afc0af0b15436a79d125703af5105be67b.tar.gz autils-cf7e15afc0af0b15436a79d125703af5105be67b.zip | |
updated
Diffstat (limited to 'updateconf')
| -rwxr-xr-x | updateconf | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/updateconf b/updateconf new file mode 100755 index 0000000..330c93c --- /dev/null +++ b/updateconf @@ -0,0 +1,64 @@ +#!/bin/sh + +EDITOR=${EDITOR:-vi} + +command -v $EDITOR >/dev/null || { + echo "Editor '$EDITOR' not exist. Append 'EDITOR=<your editor>' to ${0##*/}." + exit 2 +} + +[ "$(id -u)" = 0 ] || { + echo "This operation need root access. Exiting..." + exit 1 +} + +spkgnew=$(find /etc -regextype posix-extended -regex ".+\.new" 2> /dev/null) + +[ "$spkgnew" ] || { + echo "Nothing to do. Exiting..." + exit 0 +} + +for file in $spkgnew; do + currentfile=${file%.*} + if [ ! -e "$currentfile" ]; then + echo "Remove '$file', '$currentfile' not exist." + rm -f "$file" + sleep 0.5 + continue + fi + while true; do + clear + diff -u $currentfile $file --color=always + if [ $? = 0 ]; then + echo "Remove '$file', no diff found." + rm -f "$file" + sleep 1 + break + fi + echo + echo "File: $currentfile" + echo + printf "[U]pdate [D]iscard [E]dit [K]eep ?: " + read ACTION + echo + case $ACTION in + U|u) echo "Replace '$currentfile' with '$file'." + mv -f "$file" "$currentfile" + break;; + D|d) echo "Remove '$file'." + rm -f "$file" + break;; + E|e) vim "$currentfile";; + K|k) echo "Keeping both." + break;; + esac + done + sleep 0.5 +done + +clear + +echo "Done updating package's configuration files." + +exit 0 |