-
Notifications
You must be signed in to change notification settings - Fork 16
/
postupdate.sh
executable file
·126 lines (101 loc) · 4.23 KB
/
postupdate.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# Perform any script actions which need to happen after switching to the latest
# tagged release
main(){
# ensure we are in the vbit2 source directory
cd `dirname "$(readlink -f "$0")"`
# if it's an old install without auto deps we should do a complete recompile
if [ ! -f vbit2.d ]; then
# hope that presence of vbit2.d means all dep files are present
make clean
fi
# offer to upgrade old installs to new scripts (runs getvbit2)
migrate
# recompile vbit2
make
sudo apt -qq -y install python3-dialog
# remove old symlink
rm $HOME/.local/bin/runvbit2.sh 2>/dev/null
# create links
mkdir -p $HOME/.local/bin
ln -s -f `pwd`/vbit2 $HOME/.local/bin/
ln -s -f `pwd`/scripts/runvbit2.py $HOME/.local/bin/runvbit2
ln -s -f `pwd`/scripts/teletext-update.py $HOME/.local/bin/teletext-update
ln -s -f `pwd`/scripts/vbit-config.py $HOME/.local/bin/vbit-config
# install systemd user scripts
mkdir -p $HOME/.local/share/systemd/user
cp vbit2.service $HOME/.local/share/systemd/user
cp teletext-update.timer $HOME/.local/share/systemd/user
cp teletext-update.service $HOME/.local/share/systemd/user
systemctl --user daemon-reload
cleanoldunits
# warn about removing old services
migratejson
# restart vbit if service is active
if [[ `systemctl --user is-active vbit2.service` == "active" ]]; then
systemctl --user restart vbit2.service
fi
}
cleanoldunits(){
# clean up older systemd files
if [ -f $HOME/.config/systemd/user/vbit2.service ]; then
systemctl --user disable vbit2.service --now # removes old link
fi
if [ -f $HOME/.config/systemd/user/teletext-update.service ]; then
systemctl --user disable teletext-update.service --now # removes old link
fi
if [ -f $HOME/.config/systemd/user/teletext-update.timer ]; then
systemctl --user disable teletext-update.timer --now # removes old link
fi
}
migrate(){
FOUND=()
if [ -f $HOME/vb2 ]; then FOUND+=("$HOME/vb2"); fi
if [ -f $HOME/vbit2.sh ]; then FOUND+=("$HOME/vbit2.sh"); fi
if [ -f $HOME/updatePages.sh ]; then FOUND+=("$HOME/updatePages.sh"); fi
if [ -d $HOME/raspi-teletext-master ]; then FOUND+=("$HOME/raspi-teletext-master"); fi
if [ -f /etc/systemd/system/vbit2.service ]; then FOUND+=("/etc/systemd/system/vbit2.service"); fi
if [ ! ${#FOUND[@]} -eq 0 ]; then
printf 'The following files were found which relate to an old version of vbit2:' | fold -s -w `tput cols`
printf '\n%s' "${FOUND[@]}" | fold -s -w `tput cols`
printf '\n\nIt is recommended to upgrade to the new system which includes the interactive vbit-config utility.\nDo you wish to attempt to reinstall vbit2 automatically?\n\033[1mCaution: this will remove the files and directories listed above losing any local changes you have made.\033[0m\n' | fold -s -w `tput cols`
read -p "(y)es (n)o" -n 1 -s
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
printf "leaving start scripts unchanged.\n"
else
# Here Be Dragons!
# remove any updatePages.sh cron job
sudo crontab -l | grep -v 'updatePages.sh' | sudo crontab -
crontab -l | grep -v 'updatePages.sh' | crontab -
# delete the old files and directories
sudo systemctl disable vbit2 --now
sudo rm -rf ${FOUND[@]}
# run the new installer
./getvbit2
if [ -d $HOME/Pages ]; then
printf 'The directory %s is no longer required.\n' "$HOME/Pages"
fi
if [ -d $HOME/teletext ]; then
printf 'The directory %s is no longer required.\n' "$HOME/teletext"
fi
fi
exit
fi
}
migratejson(){
if [ -f $HOME/.teletext-services/config ]; then
systemctl --user stop vbit2.service
printf 'This version of VBIT2 uses a new config format and directory scheme.\nServices will not be automatically migrated so must be reinstalled.\nThe following services were found:\n'
ls -d1 ~/.teletext-services/*/
read -n 1 -s -r -p "Do you wish to create a backup of these services? (y/N)"
if [[ $REPLY =~ ^[Yy]$ ]]; then
printf '\nbacking up old services to %s\n' "$HOME/teletext-services.bak"
mv $HOME/.teletext-services $HOME/teletext-services.bak
else
rm -rf $HOME/.teletext-services/ 2>/dev/null
fi
vbit-config
fi
}
main; exit