-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupgrade.sh
executable file
·221 lines (190 loc) · 5.46 KB
/
upgrade.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/sh -
DATE=$(date +%Y%m%dZ%H%M%S)
BASENAME=$(basename $0)
DIRNAME=$(dirname $0)
STATE=$DIRNAME/state.txt
SYSRC="sysrc -f $STATE"
touch $STATE
$SYSRC last_run=$DATE
. $STATE
UNAME=$(uname -r)
TMP=/tmp/var.out
NEW="11.3-RELEASE"
DIALOG="dialog --ascii-lines --yesno "
if [ ! "$previous_version" ]; then
$SYSRC previous_version=$UNAME
previous_version=$UNAME
fi
prv_str=$(echo $previous_version | cut -d'-' -f1 | tr '.' '_')
new_str=$(echo $NEW | cut -d'-' -f1 | tr '.' '_')
prv_major=$(echo $previous_version | cut -d'.' -f1)
new_major=$(echo $NEW | cut -d'.' -f1)
if [ "$prv_str" == "$new_str" ]; then
dialog --ascii-lines --msgbox "$(hostname) is already $NEW. Exiting" 0 0
exit
fi
if [ ! "$phase_pkg_upgrade" ]; then
$DIALOG "pkg upgrade this system?" 0 0
if [ $? -eq 0 ]; then
pkg update
pkg upgrade
fi
clear
$SYSRC phase_pkg_upgrade=1
fi
if [ ! "$phase_puppet4" ]; then
$DIALOG "install puppet5?" 0 0
if [ $? -eq 0 ]; then
pkg install -y puppet5
fi
clear
$SYSRC phase_puppet4=1
fi
if [ ! "$phase_puppetrun" ]; then
$DIALOG "do a test puppet run?" 0 0
if [ $? -eq 0 ]; then
puppet agent -t
fi
clear
$SYSRC phase_puppetrun=1
fi
if [ ! "$phase_fetchinstall" ]; then
$DIALOG "run a freebsd-update fetch install?" 0 0
if [ $? -eq 0 ]; then
freebsd-update --not-running-from-cron fetch install
fi
clear
$SYSRC phase_fetchinstall=1
fi
if [ ! "$new_version" ]; then
dialog --ascii-lines --inputbox "version to upgrade to?" 0 0 $NEW 2> $TMP
NEW=$(cat $TMP)
clear
new_version=$NEW
$SYSRC new_version=$NEW
fi
if [ ! "$phase_upgrade" ]; then
$DIALOG "run a freebsd-update -r $NEW upgrade?" 0 0
if [ $? -eq 0 ]; then
freebsd-update --not-running-from-cron -r $new_version upgrade
$SYSRC phase_upgrade=1
fi
fi
if [ ! "$phase_install" ]; then
$DIALOG "run a freebsd-update install?" 0 0
if [ $? -eq 0 ]; then
freebsd-update --not-running-from-cron install
$SYSRC phase_install=1
fi
fi
if [ ! "$phase_deactivate_jails" ]; then
$DIALOG "deactivate jails before reboot?" 0 0
if [ $? -eq 0 ]; then
sysrc ezjail_enable=NO
fi
$SYSRC phase_deactivate_jails=1
fi
if [ ! "$phase_reboot" ]; then
$DIALOG "reboot now?" 0 0
if [ $? -eq 0 ]; then
$SYSRC phase_reboot=1
reboot
fi
fi
if [ ! "$phase_reboot2" ]; then
dialog --ascii-lines --msgbox "reboot has been done!" 0 0
$SYSRC phase_reboot2=1
fi
if [ ! "$phase_reactivate_jails" ]; then
$DIALOG "reactivate jails with old basejail from $previous_version ?" 0 0
if [ $? -eq 0 ]; then
echo $prv_str
for j in $(ls /usr/local/etc/ezjail | egrep -v 'norun$'); do
sed -i -E "s/^\/var\/jails\/basejail/\/var\/jails\/old_basejail_$prv_str/" /etc/fstab.$j
done
test -d /var/jails/basejail && mv /var/jails/basejail /var/jails/old_basejail_$prv_str
test -d /var/jails/newjail && mv /var/jails/newjail /var/jails/old_newjail_$prv_str
sysrc ezjail_enable=YES
service ezjail start
$SYSRC phase_reactivate_jails=1
fi
fi
if [ ! "$phase_install_after1" ]; then
$DIALOG "run a freebsd-update install?" 0 0
if [ $? -eq 0 ]; then
freebsd-update --not-running-from-cron install
$SYSRC phase_install_after1=1
fi
fi
if [ ! "$phase_recreate_passwd" ]; then
$DIALOG "re-create passwd database? (this is sometimes needed after an upgrade)" 0 0
if [ $? -eq 0 ]; then
/usr/sbin/pwd_mkdb -p /etc/master.passwd
fi
clear
$SYSRC phase_recreate_passwd=1
fi
if [ ! "$phase_pkg_upgrade_after_reboot" ]; then
$DIALOG "pkg upgrade this system?" 0 0
if [ $? -eq 0 ]; then
pkg-static install -f pkg
pkg update
pkg upgrade
fi
clear
$SYSRC phase_pkg_upgrade_after_reboot=1
fi
if [ ! "$phase_install_after2" ]; then
$DIALOG "run a freebsd-update install again?" 0 0
if [ $? -eq 0 ]; then
freebsd-update --not-running-from-cron install
$SYSRC phase_install_after2=1
fi
fi
if [ ! "$phase_reboot3" ]; then
dialog --ascii-lines --msgbox "$(hostname) is now a $(uname -r)!" 0 0
$SYSRC phase_reboot3=1
fi
if [ ! "$phase_create_basejail" ]; then
$DIALOG "create ($(uname -r)) basejail?" 0 0
if [ $? -eq 0 ]; then
ezjail-admin install -s
$SYSRC phase_create_basejail=1
fi
fi
JAILS=$(ezjail-admin list | tail +3 | egrep ^DR | awk '{print $4}')
if [ $prv_major == $new_major ]; then
additional_msg='(no mergemaster or pkg upgrade necessary)'
fi
for j in $JAILS; do
jail_ver=$(ezjail-admin console -e 'freebsd-version' $j)
echo comparing $jail_ver with $UNAME
if [ "$jail_ver" != "$UNAME" ]; then
phase_var=$(echo phase_update_jail_$j | tr '.' '_' | tr '-' '_' )
#echo $phase_var
phase_var_name="\$$phase_var"
#echo $phase_var_name
phase_var_value=$(eval echo $phase_var_name)
#echo $phase_var_value
if [ ! "$phase_var_value" ]; then
$DIALOG "update jail $j ? $additional_msg " 0 0
if [ $? -eq 0 ]; then
jname=$(echo $j | tr '.' '_' | tr '-' '_' )
ezjail-admin stop $j
sed -i -E "s/^\/var\/jails\/old_basejail_$prv_str/\/var\/jails\/basejail/" /etc/fstab.$jname
ezjail-admin start $j
ezjail-admin console -e 'freebsd-version' $j
ezjail-admin console -e '/usr/sbin/pwd_mkdb -p /etc/master.passwd' $j
if [ $prv_major != $new_major ]; then
ezjail-admin console -e "sed -i -E s/^IGNORE/IIGNORE/ /etc/mergemaster.rc" $j
ezjail-admin console -e 'mergemaster --run-updates=always -p' $j
ezjail-admin console -e "sed -i -E s/^IIGNORE/IGNORE/ /etc/mergemaster.rc" $j
ezjail-admin console -e 'mergemaster -iU --run-updates=always' $j
ezjail-admin console -e 'pkg-static install -f pkg' $j
ezjail-admin console -e 'pkg upgrade' $j
fi
$SYSRC $phase_var=1
fi
fi
fi
done