Blame
Date:
Sat Apr 25 13:52:35 2020 UTC
Message:
time to update
001
2015-05-06
f
#!/bin/ksh
002
2015-05-06
f
#
003
2015-05-06
f
########################################################################
004
2015-05-06
f
#
005
2020-04-25
f
# snaps.sh - Check if you can upgrade your OpenBSD OS base to
006
2020-04-25
f
# last -current snapshot
007
2015-05-06
f
#
008
2020-04-25
f
# Copyright (c) 2017-2020, Fred Galusik <f AT galusik.fr>
009
2015-05-06
f
# All rights reserved.
010
2015-05-06
f
#
011
2015-05-06
f
# Redistribution and use in source and binary forms, with or without
012
2015-05-06
f
# modification, are permitted provided that the following conditions are
013
2015-05-06
f
# met:
014
2015-05-06
f
#
015
2015-05-06
f
# 1. Redistributions of source code must retain the above copyright
016
2015-05-06
f
# notice, this list of conditions and the following disclaimer.
017
2015-05-06
f
#
018
2015-05-06
f
# 2. Redistributions in binary form must reproduce the above copyright
019
2015-05-06
f
# notice, this list of conditions and the following disclaimer in the
020
2015-05-06
f
# documentation and/or other materials provided with the distribution.
021
2015-05-06
f
#
022
2015-05-06
f
# 3. Neither the name of the copyright holder nor the names of its
023
2015-05-06
f
# contributors may be used to endorse or promote products derived from
024
2015-05-06
f
# this software without specific prior written permission.
025
2015-05-06
f
#
026
2015-05-06
f
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027
2015-05-06
f
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028
2015-05-06
f
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029
2015-05-06
f
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
030
2015-05-06
f
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
031
2015-05-06
f
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
032
2015-05-06
f
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
033
2015-05-06
f
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
034
2015-05-06
f
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
035
2015-05-06
f
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
036
2015-05-06
f
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037
2015-05-06
f
#
038
2015-05-06
f
########################################################################
039
2015-05-06
f
040
2015-05-06
f
###
041
2015-05-06
f
### VARS
042
2015-05-06
f
###
043
2015-05-06
f
044
2017-08-25
dev1
VERSION=1.3
045
2015-05-09
f
046
2015-05-17
f
if [ ! $MIRROR ]; then
047
2017-03-11
f
MIRROR=$(grep -v "^#" /etc/installurl)
048
2015-05-17
f
fi
049
2017-03-06
dev1
ARCH=$(uname -m)
050
2015-05-17
f
051
2017-03-06
dev1
MIRRORB=${MIRROR}/snapshots/${ARCH}/
052
2017-03-06
dev1
MIRRORPKG=${MIRROR}/snapshots/packages/${ARCH}/
053
2015-05-17
f
054
2015-05-06
f
BSDRD=bsd.rd
055
2015-05-06
f
SHAF=SHA256
056
2015-05-06
f
SIGF=SHA256.sig
057
2015-05-06
f
058
2017-08-25
dev1
if [ ! $RL ]; then
059
2017-08-25
dev1
RL=$(uname -r | sed 's/\.//')
060
2017-08-25
dev1
fi
061
2017-08-25
dev1
SIGNPUB=/etc/signify/openbsd-${RL}-base.pub
062
2015-05-17
f
GET='ftp -n -m -C'
063
2015-05-06
f
REBOOT='/sbin/reboot'
064
2015-05-06
f
065
2015-05-06
f
LOGF=/var/log/snaps.log
066
2015-05-17
f
NOW=$(date "+ %Y-%m-%d %R")
067
2015-05-06
f
068
2016-09-11
f
REMOTESNAPS='https://framagit.org/fredg/snaps/raw/master/snaps'
069
2016-09-11
f
LASTSNAPS=/tmp/snaps
070
2016-10-15
dev1
071
2015-05-06
f
###
072
2015-05-06
f
###
073
2015-06-20
f
###
074
2015-05-06
f
075
2016-09-11
f
toupgrade() {
076
2016-10-23
dev1
echo "\n=== NEW VERSION CHECKING ==="
077
2016-09-11
dev1
# some cleanup to not let ftp warn about not supporting resume
078
2016-09-11
dev1
if [[ -f $LASTSNAPS ]]; then
079
2016-09-11
dev1
rm -f $LASTSNAPS
080
2016-09-11
dev1
fi
081
2016-10-23
dev1
082
2016-09-11
f
$GET -V -o "$LASTSNAPS" "$REMOTESNAPS"
083
2016-10-20
f
REMOTEVERSION=$(awk -F '=' '/^VERSION=/ { print $2 }' "$LASTSNAPS")
084
2016-09-11
f
085
2016-09-11
f
if [ $? -eq 0 ]; then
086
2016-09-11
f
087
2016-09-11
dev1
if [ "$VERSION" != "$REMOTEVERSION" ]; then
088
2016-09-11
dev1
echo "==> WARNING: snaps is not up-to-date !"
089
2016-09-11
dev1
echo "Last version: $REMOTEVERSION"
090
2016-09-11
f
echo "To upgrade, run 'snaps -u'"
091
2016-09-11
dev1
else
092
2016-09-11
dev1
echo "==> GOOD: snaps is up-to-date"
093
2016-09-11
f
fi
094
2016-10-23
dev1
095
2016-10-23
dev1
else
096
2016-10-23
dev1
echo "==> WARNING: Remote snaps not reachable ! Check the connection."
097
2016-09-11
f
fi
098
2016-09-11
f
}
099
2016-09-11
f
100
2016-09-11
f
upgrade() {
101
2016-10-20
dev1
SELFPATH=$(dirname $(readlink -f -- "$0"))
102
2016-09-11
f
echo "Downloading last snaps version"
103
2016-09-11
f
$GET -o "$SELFPATH" "$REMOTESNAPS"
104
2016-09-11
f
}
105
2016-09-11
f
106
2016-09-11
f
107
2015-05-09
f
usage() {
108
2016-09-11
dev1
echo ""
109
2016-05-15
dev1
echo "${0##*/} $VERSION"
110
2016-05-15
dev1
echo "Usage: ${0##*/} [-gGlh]"
111
2016-05-15
dev1
echo " -g fetch and check bsd.rd from \$MIRROR"
112
2016-05-15
dev1
echo " -G fetch, check and install bsd.rd from \$MIRROR"
113
2016-06-11
f
echo " -p update port tree to current"
114
2016-05-15
dev1
echo " -l list date and \$MIRROR of 3 last bsd.rd"
115
2016-09-11
f
echo " -u upgrade snaps to last version"
116
2016-05-15
dev1
echo " -h print this help and exit"
117
2016-05-15
dev1
echo ""
118
2017-03-06
dev1
echo "MIRROR is based upon /etc/installurl and set to: $MIRROR"
119
2016-05-15
dev1
echo ""
120
2016-05-15
dev1
echo "You can set it manually:"
121
2017-03-06
dev1
echo "\$ MIRROR=http://mirrors.ircam.fr/pub/OpenBSD doas snaps -G"
122
2016-05-15
dev1
echo ""
123
2015-05-06
f
}
124
2015-05-06
f
125
2015-05-09
f
s_root() {
126
2015-05-09
f
if [[ $(id -u) != "0" ]]; then
127
2015-05-09
f
echo "==> WARNING: You need to be root to do this" 1>&2
128
2015-05-06
f
exit 1
129
2015-05-06
f
fi
130
2015-05-06
f
}
131
2015-05-06
f
132
2015-05-06
f
133
2015-05-09
f
s_log() {
134
2016-10-15
dev1
echo "$NOW FROM $MIRRORB" >> $LOGF
135
2015-05-06
f
}
136
2015-05-06
f
137
2015-05-06
f
138
2015-05-09
f
get_log() {
139
2015-05-09
f
if [[ -f $LOGF ]]; then
140
2015-05-06
f
tail -n 3 $LOGF
141
2015-05-06
f
else
142
2015-05-09
f
echo "No $LOGF file. Seems you have not yet played with snaps"
143
2015-05-09
f
exit 1
144
2015-05-06
f
fi
145
2015-05-06
f
}
146
2015-05-06
f
147
2015-05-17
f
148
2015-05-09
f
get_rd() {
149
2015-05-06
f
echo "\n=== FETCHING FILES ==="
150
2015-05-09
f
for _i in $BSDRD $SHAF $SIGF; do
151
2015-05-09
f
if [[ -f ${_i} ]]; then
152
2015-05-09
f
echo "\nDeleted old ${_i}"
153
2015-05-09
f
rm ${_i}
154
2015-05-06
f
fi
155
2015-06-20
f
echo "==> Fetching new ${_i}"
156
2016-10-15
dev1
$GET $MIRRORB${_i} || exit 1
157
2015-05-06
f
done
158
2015-05-06
f
}
159
2015-05-06
f
160
2015-05-06
f
161
2015-05-09
f
s_check() {
162
2015-05-06
f
echo "\n=== FILE INTEGRITY CHECKING ==="
163
2016-04-23
dev1
echo "Sign key: $SIGNPUB"
164
2015-05-06
f
OK=OK
165
2015-05-06
f
# signify
166
2016-10-20
f
if [[ $(signify -C -p $SIGNPUB -x $SIGF $BSDRD | awk '/'$BSDRD'/ {print $2}') = $OK ]]; then
167
2015-05-09
f
echo "==> GOOD: $SHAF file is coming from OpenBSD"
168
2015-05-06
f
else
169
2015-05-09
f
echo "==> WARNING: $SHAF is not coming from OpenBSD, aborting!!"
170
2015-05-09
f
exit 1
171
2015-05-06
f
fi
172
2015-05-06
f
# sha256
173
2016-10-20
f
if [[ $(sha256 -c $SHAF 2>&1 | awk '/'$BSDRD'/ {print $3}') = $OK ]]; then
174
2015-05-09
f
echo "==> GOOD: bsd.rd integrity checked"
175
2015-05-06
f
else
176
2015-05-09
f
echo "==> WARNING: bsd.rd seems corrupted, aborting!!"
177
2015-05-09
f
exit 1
178
2015-05-06
f
fi
179
2015-05-06
f
}
180
2015-05-06
f
181
2015-05-06
f
182
2015-05-09
f
s_move() {
183
2015-05-06
f
echo "\n=== MOVING FILE ==="
184
2015-05-09
f
cp -p /bsd /bsd.o || exit 1
185
2015-05-09
f
mv /bsd.rd /bsd.o.rd || exit 1
186
2015-05-09
f
mv $BSDRD / || exit 1
187
2015-05-09
f
rm $SHAF
188
2015-05-09
f
rm $SIGF
189
2015-05-09
f
echo "==> New bsd.rd installed and old files saved"
190
2015-05-09
f
echo "You can reboot your OS"
191
2015-05-09
f
echo "Type bsd.rd at the boot prompt, [enter] and choose (U)pgrade"
192
2015-05-09
f
echo ""
193
2015-05-09
f
echo "If something goes wrong, you can still boot your old kernel"
194
2015-05-09
f
echo "Just type bsd.o at the boot prompt"
195
2015-05-09
f
echo ""
196
2015-05-17
f
echo -n "==> Do you want to do it now ? (y/n) "
197
2015-05-09
f
read _a
198
2015-05-09
f
case ${_a} in
199
2015-05-06
f
y|Y)
200
2015-05-17
f
echo "After the upgrade, run sysmerge(8)"
201
2015-05-09
f
echo "Then, update packages or ports"
202
2015-05-09
f
echo "==> Rebooting..."
203
2015-05-09
f
$REBOOT
204
2015-05-06
f
;;
205
2015-05-06
f
*)
206
2015-05-17
f
echo -n "Do you want to put the old bsd.rd back ? (y/n) "
207
2015-05-17
f
read _b
208
2015-05-17
f
case ${_b} in
209
2015-05-17
f
y|Y)
210
2015-05-17
f
rm /bsd.rd || exit 1
211
2015-05-17
f
rm /bsd.o || exit 1
212
2015-05-17
f
mv /bsd.o.rd /bsd.rd || exit 1
213
2015-05-17
f
echo "Done!"
214
2015-05-17
f
exit 1
215
2015-05-17
f
;;
216
2015-05-17
f
*)
217
2015-05-17
f
echo "Aborting..."
218
2015-05-17
f
exit 1
219
2015-05-17
f
;;
220
2015-05-17
f
esac
221
2015-05-06
f
;;
222
2015-05-06
f
esac
223
2015-05-06
f
}
224
2015-05-06
f
225
2016-06-11
f
s_upports() {
226
2016-06-11
f
echo "\n=== UPDATE PORTS TREE ==="
227
2016-06-11
f
cd /usr/ports || exit 1
228
2016-06-11
f
cvs up -Pd || exit 1
229
2016-06-11
f
echo "==> New port tree fetched"
230
2016-06-11
f
echo ""
231
2016-06-11
f
}
232
2016-06-11
f
233
2016-10-15
dev1
s_when() {
234
2016-10-15
dev1
# will only be done if curl from port/package is installed
235
2016-10-15
dev1
CURL=/usr/local/bin/curl
236
2016-10-15
dev1
if [[ -e $CURL ]]; then
237
2016-10-15
dev1
CURLB="$($CURL -sI ${MIRRORB}${SHAF} | grep Last-Modified)"
238
2016-10-15
dev1
CURLP="$($CURL -sI ${MIRRORPKG}${SHAF} | grep Last-Modified)"
239
2016-10-15
dev1
echo "\n=== BASE AND PACKAGES BUILD DATE ==="
240
2016-10-19
dev1
echo "From ${MIRROR}"
241
2016-10-15
dev1
echo "Base ($ARCH) => $CURLB"
242
2016-10-15
dev1
echo "Packages ($ARCH) => $CURLP"
243
2016-10-15
dev1
echo ""
244
2016-10-15
dev1
echo -n "Do you want to continue ? (y/n): "
245
2016-10-15
dev1
read _c
246
2016-10-15
dev1
case ${_c} in
247
2016-10-15
dev1
y|Y)
248
2016-10-15
dev1
;;
249
2016-10-15
dev1
*)
250
2016-10-15
dev1
echo "Aborting..."
251
2016-10-15
dev1
exit 1
252
2016-10-15
dev1
;;
253
2016-10-15
dev1
esac
254
2016-10-15
dev1
fi
255
2016-10-15
dev1
}
256
2016-10-15
dev1
257
2015-05-06
f
##
258
2015-05-06
f
## Run
259
2015-05-06
f
##
260
2016-10-15
dev1
261
2015-05-06
f
case $1 in
262
2015-05-06
f
-g)
263
2016-10-15
dev1
toupgrade
264
2015-05-06
f
get_rd
265
2015-05-09
f
s_check
266
2015-05-06
f
;;
267
2015-05-06
f
-G)
268
2015-05-09
f
s_root
269
2016-10-15
dev1
toupgrade
270
2016-10-15
dev1
s_when
271
2016-11-17
dev1
s_log
272
2015-05-06
f
get_rd
273
2015-05-09
f
s_check
274
2015-05-09
f
s_move
275
2015-05-06
f
;;
276
2016-06-11
f
-p)
277
2016-06-11
f
s_upports
278
2016-06-11
f
;;
279
2015-05-06
f
-l)
280
2015-05-30
f
get_log
281
2015-05-06
f
;;
282
2016-09-11
f
-u)
283
2016-09-11
f
upgrade
284
2016-09-11
f
;;
285
2015-05-06
f
-h|*)
286
2015-05-06
f
usage
287
2015-05-06
f
exit 1
288
2015-05-06
f
;;
289
2015-05-06
f
esac
Frédéric Galusik