#!/bin/sh version="0.4" if ! which dialog > /dev/null 2>&1; then echo "Could not find dialog, do 'pacman -S dialog'." 1>&2 exit 4 fi for e in "$EDITOR" "$VISUAL" vim vi joe mcedit nano pico e3 jed ne emacs; do w=$(which $e 2> /dev/null) if [ -n "$w" -a -x "$w" ]; then texted="$w" break fi done if [ ! -x "$texted" ]; then echo "Could not find any text editor." 1>&2 exit 2 fi tmpdir=$(mktemp -d 2> /dev/null) if [ $? != 0 ]; then echo "Unable to create a temporary directory." 1>&2 exit 1 fi menu_common() { cat << EOF > $tmpdir/dialog --backtitle "dotpac $version - get rid of /{boot,etc}/*.pac* files, \ by swiergot@gmail.com" --no-shadow --begin $1 $2 EOF } menu_main() { rm -f $tmpdir/files i=1 for cf in $(find /etc /boot -name '*.pac*' | sort); do echo "$i $cf" >> $tmpdir/files i=$(expr $i + 1) done if [ ! -s $tmpdir/files ]; then menu_common 10 5 cat << EOF >> $tmpdir/dialog --ok-label "Exit" --msgbox "No *.pac* files have been found in /etc and /boot." 5 70 EOF dialog --file $tmpdir/dialog return 1 fi menu_common 3 15 cat << EOF >> $tmpdir/dialog --ok-label "Next" --menu "The following backup files have been found in /etc and /boot. \ Please select a file you want to process." 20 50 11 EOF cat $tmpdir/files >> $tmpdir/dialog dialog --file $tmpdir/dialog 2> $tmpdir/exitcode if [ $? != 0 ]; then return 1 fi choice=$(cat $tmpdir/exitcode) choice=$(expr $choice + 6) file=$(sed -n ${choice}p $tmpdir/dialog | cut -d ' ' -f 2) if [[ "$file" == *.pacnew ]]; then menu_pacnew "$file" elif [[ "$file" == *.pacsave ]]; then menu_pacsave "$file" else echo "It looks like you have found a bug. Please contact the author." 1>&2 exit 3 fi } menu_actions() { diff -u "$2" "$1" > $tmpdir/diff if [ -s $tmpdir/diff ]; then menu_common 3 1 cat << EOF >> $tmpdir/dialog --exit-label "Next" --textbox $tmpdir/diff 21 78 EOF dialog --file $tmpdir/dialog menu_common 6 12 cat << EOF >> $tmpdir/dialog --ok-label "Finish" --menu "Now that you know why $1 was left and you have seen the differences \ between the two files, you can decide what to do with them. What would you like to do?" 15 56 5 1 "Remove the $3 file." 2 "Remove the $3 file and edit the $4 one." 3 "Replace the $4 file with the $5 and edit." 4 "Just replace the $4 file with the $5." 5 "Nothing." EOF dialog --file $tmpdir/dialog 2> $tmpdir/exitcode if [ $? != 0 ]; then return 0 fi choice=$(cat $tmpdir/exitcode) if [ $choice == 5 ]; then return 0 elif [ $choice == 1 ]; then rm -f "$1" elif [ $choice == 2 ]; then rm -f "$1" "$texted" "$2" elif [ $choice == 3 ]; then mv -f "$1" "$2" "$texted" "$2" elif [ $choice == 4 ]; then mv -f "$1" "$2" fi return 0 else menu_common 8 15 cat << EOF >> $tmpdir/dialog --yesno "Both files:\n\n $2\n $1\n\nare exactly the same. It is safe to remove \ the latter. Do you want to do this?" 11 50 EOF dialog --file $tmpdir/dialog if [ $? == 0 ]; then rm -f "$1" fi return 0 fi } menu_pacnew() { file=$(dirname "$1")/$(basename "$1" .pacnew) menu_common 9 3 cat << EOF >> $tmpdir/dialog --ok-label "Next" --msgbox "During the last upgrade of a package that owns $file, pacman did not \ touch the file because it had been marked as NoUpgrade in /etc/pacman.conf. \ \n\nDifferences between both files will now be displayed." 9 74 EOF dialog --file $tmpdir/dialog menu_actions "$1" "$file" "new" "old" "new one" } menu_pacsave() { file=$(dirname "$1")/$(basename "$1" .pacsave) if [ -f "$file" ]; then menu_common 7 3 cat << EOF >> $tmpdir/dialog --ok-label "Next" --msgbox "During the last upgrade of a package that owns $file, the file was \ backed up as $1 and replaced with a new one. The new file differs from its \ previous original version that you had modified. You need to make your changes \ again, taking these differences into account.\n\nDifferences between both files \ will now be displayed." 12 74 EOF dialog --file $tmpdir/dialog menu_actions "$1" "$file" "backup" "new" "backup" else menu_common 9 3 cat << EOF >> $tmpdir/dialog --ok-label "Next" --msgbox "Since $1 has not been found, it can be assumed that $file was created \ during removal of a package that owned the original file." 8 74 EOF dialog --file $tmpdir/dialog menu_common 3 1 cat << EOF >> $tmpdir/dialog --exit-label "Next" --textbox "$1" 21 78 EOF dialog --file $tmpdir/dialog menu_common 9 15 cat << EOF >> $tmpdir/dialog --yesno "You can safely remove $1 if you are sure you will not need it anymore. \ Do you want to do this?" 8 50 EOF dialog --file $tmpdir/dialog if [ $? == 0 ]; then rm -f "$1" fi return 0 fi } bye=0 while [ $bye == 0 ]; do menu_main bye=$? done rm -rf $tmpdir clear