forked from jblakeman/apt-select
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·70 lines (64 loc) · 1.5 KB
/
update.sh
File metadata and controls
executable file
·70 lines (64 loc) · 1.5 KB
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
#!/bin/bash
apt="/etc/apt"
file="sources.list"
apt_file=${apt}/${file}
backup=${apt_file}.backup
needSudo (){
if [ $EUID -ne 0 ]; then
echo "$0 needs sudoer priveleges to modify '${apt_file}'"
echo "Enter sudo password to continue"
fi
}
updateApt (){
sudo mv $file $apt_file && echo "apt has been updated"
}
updateBackup (){
sudo mv $apt_file $backup && echo "Current file backed up to '$backup'" &&
updateApt
exit 0
}
isBackup (){
local query options opt
query="A backup file already exists.\n"
query+="Choose one of the following options:\n"
echo -e "$query"
options=(
"Replace current backup"
"Replace 'sources.list' without backing up"
"Quit"
)
select opt in "${options[@]}"
do
case $opt in
"${options[0]}")
needSudo
updateBackup
break
;;
"${options[1]}")
needSudo
updateApt
break
;;
"${options[2]}")
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
if [ -f "$backup" ]; then
isBackup
else
needSudo && updateBackup
fi
else
echo "File '$file' must exist in the current directory"
exit 1
fi
fi