-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathupdate.sh
executable file
·84 lines (77 loc) · 1.75 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
apt=/etc/apt
file=sources.list
apt_file=${apt}/${file}
backup=${apt_file}.backup
if [ $EUID -ne 0 ]; then
echo "$0 needs sudoer priveleges to modify ${apt_file}"
echo "please run script as super user (root)"
exit 1
fi
updateApt (){
mv $file $apt_file &&
echo "apt has been updated"
}
updateBackup (){
mv $apt_file $backup &&
echo "$apt_file backed up to $backup"
updateApt
}
examine (){
less $1 2>/dev/null
isBackup
break
}
isBackup (){
local query options opt
query="Backup file $backup already exists.\n"
query+="Choose one of the following options:"
echo -e "$query"
options=(
"Replace backup and update apt"
"Update apt without backing up"
"Examine $backup"
"Examine $apt_file"
"Examine $PWD/$file"
"Quit"
)
select opt in "${options[@]}"; do
case $opt in
"${options[0]}")
updateBackup
break
;;
"${options[1]}")
updateApt
break
;;
"${options[2]}")
examine $backup
;;
"${options[3]}")
examine $apt_file
;;
"${options[4]}")
examine $file
;;
"${options[5]}")
break
;;
*)
echo invalid option
;;
esac
done
}
if [ "$PWD" = "$apt" ]; then
echo "Please run the update from a directory other than $apt"
exit 1
else
if [ -f "$file" ]; then
[ -f "$backup" ] && isBackup || updateBackup
else
echo "$file must exist in the working directory"
exit 1
fi
fi
exit 0