003
2015-05-06
f
########################################################################
005
2015-05-06
f
# snaps.sh - Upgrade your OpenBSD OS base to last -current snapshot
007
2017-03-06
dev1
# Copyright (c) 2017, Fred Galusik <f AT galusik.xyz>
008
2015-05-06
f
# All rights reserved.
010
2015-05-06
f
# Redistribution and use in source and binary forms, with or without
011
2015-05-06
f
# modification, are permitted provided that the following conditions are
014
2015-05-06
f
# 1. Redistributions of source code must retain the above copyright
015
2015-05-06
f
# notice, this list of conditions and the following disclaimer.
017
2015-05-06
f
# 2. Redistributions in binary form must reproduce the above copyright
018
2015-05-06
f
# notice, this list of conditions and the following disclaimer in the
019
2015-05-06
f
# documentation and/or other materials provided with the distribution.
021
2015-05-06
f
# 3. Neither the name of the copyright holder nor the names of its
022
2015-05-06
f
# contributors may be used to endorse or promote products derived from
023
2015-05-06
f
# this software without specific prior written permission.
025
2015-05-06
f
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026
2015-05-06
f
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027
2015-05-06
f
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028
2015-05-06
f
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
029
2015-05-06
f
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
030
2015-05-06
f
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
031
2015-05-06
f
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
032
2015-05-06
f
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
033
2015-05-06
f
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
034
2015-05-06
f
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
035
2015-05-06
f
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037
2015-05-06
f
########################################################################
043
2017-04-17
dev1
VERSION=1.2
045
2015-05-17
f
if [ ! $MIRROR ]; then
046
2017-03-11
f
MIRROR=$(grep -v "^#" /etc/installurl)
048
2017-03-06
dev1
ARCH=$(uname -m)
050
2017-03-06
dev1
MIRRORB=${MIRROR}/snapshots/${ARCH}/
051
2017-03-06
dev1
MIRRORPKG=${MIRROR}/snapshots/packages/${ARCH}/
053
2015-05-06
f
BSDRD=bsd.rd
054
2015-05-06
f
SHAF=SHA256
055
2015-05-06
f
SIGF=SHA256.sig
057
2017-03-18
f
SIGNPUB=/etc/signify/openbsd-$(uname -r | sed 's/\.//')-base.pub
058
2015-05-17
f
GET='ftp -n -m -C'
059
2015-05-06
f
REBOOT='/sbin/reboot'
061
2015-05-06
f
LOGF=/var/log/snaps.log
062
2015-05-17
f
NOW=$(date "+ %Y-%m-%d %R")
064
2016-09-11
f
REMOTESNAPS='https://framagit.org/fredg/snaps/raw/master/snaps'
065
2016-09-11
f
LASTSNAPS=/tmp/snaps
071
2016-09-11
f
toupgrade() {
072
2016-10-23
dev1
echo "\n=== NEW VERSION CHECKING ==="
073
2016-09-11
dev1
# some cleanup to not let ftp warn about not supporting resume
074
2016-09-11
dev1
if [[ -f $LASTSNAPS ]]; then
075
2016-09-11
dev1
rm -f $LASTSNAPS
078
2016-09-11
f
$GET -V -o "$LASTSNAPS" "$REMOTESNAPS"
079
2016-10-20
f
REMOTEVERSION=$(awk -F '=' '/^VERSION=/ { print $2 }' "$LASTSNAPS")
081
2016-09-11
f
if [ $? -eq 0 ]; then
083
2016-09-11
dev1
if [ "$VERSION" != "$REMOTEVERSION" ]; then
084
2016-09-11
dev1
echo "==> WARNING: snaps is not up-to-date !"
085
2016-09-11
dev1
echo "Last version: $REMOTEVERSION"
086
2016-09-11
f
echo "To upgrade, run 'snaps -u'"
088
2016-09-11
dev1
echo "==> GOOD: snaps is up-to-date"
092
2016-10-23
dev1
echo "==> WARNING: Remote snaps not reachable ! Check the connection."
096
2016-09-11
f
upgrade() {
097
2016-10-20
dev1
SELFPATH=$(dirname $(readlink -f -- "$0"))
098
2016-09-11
f
echo "Downloading last snaps version"
099
2016-09-11
f
$GET -o "$SELFPATH" "$REMOTESNAPS"
104
2016-09-11
dev1
echo ""
105
2016-05-15
dev1
echo "${0##*/} $VERSION"
106
2016-05-15
dev1
echo "Usage: ${0##*/} [-gGlh]"
107
2016-05-15
dev1
echo " -g fetch and check bsd.rd from \$MIRROR"
108
2016-05-15
dev1
echo " -G fetch, check and install bsd.rd from \$MIRROR"
109
2016-06-11
f
echo " -p update port tree to current"
110
2016-05-15
dev1
echo " -l list date and \$MIRROR of 3 last bsd.rd"
111
2016-09-11
f
echo " -u upgrade snaps to last version"
112
2016-05-15
dev1
echo " -h print this help and exit"
113
2016-05-15
dev1
echo ""
114
2017-03-06
dev1
echo "MIRROR is based upon /etc/installurl and set to: $MIRROR"
115
2016-05-15
dev1
echo ""
116
2016-05-15
dev1
echo "You can set it manually:"
117
2017-03-06
dev1
echo "\$ MIRROR=http://mirrors.ircam.fr/pub/OpenBSD doas snaps -G"
118
2016-05-15
dev1
echo ""
122
2015-05-09
f
if [[ $(id -u) != "0" ]]; then
123
2015-05-09
f
echo "==> WARNING: You need to be root to do this" 1>&2
130
2016-10-15
dev1
echo "$NOW FROM $MIRRORB" >> $LOGF
134
2015-05-09
f
get_log() {
135
2015-05-09
f
if [[ -f $LOGF ]]; then
136
2015-05-06
f
tail -n 3 $LOGF
138
2015-05-09
f
echo "No $LOGF file. Seems you have not yet played with snaps"
145
2015-05-06
f
echo "\n=== FETCHING FILES ==="
146
2015-05-09
f
for _i in $BSDRD $SHAF $SIGF; do
147
2015-05-09
f
if [[ -f ${_i} ]]; then
148
2015-05-09
f
echo "\nDeleted old ${_i}"
151
2015-06-20
f
echo "==> Fetching new ${_i}"
152
2016-10-15
dev1
$GET $MIRRORB${_i} || exit 1
157
2015-05-09
f
s_check() {
158
2015-05-06
f
echo "\n=== FILE INTEGRITY CHECKING ==="
159
2016-04-23
dev1
echo "Sign key: $SIGNPUB"
162
2016-10-20
f
if [[ $(signify -C -p $SIGNPUB -x $SIGF $BSDRD | awk '/'$BSDRD'/ {print $2}') = $OK ]]; then
163
2015-05-09
f
echo "==> GOOD: $SHAF file is coming from OpenBSD"
165
2015-05-09
f
echo "==> WARNING: $SHAF is not coming from OpenBSD, aborting!!"
169
2016-10-20
f
if [[ $(sha256 -c $SHAF 2>&1 | awk '/'$BSDRD'/ {print $3}') = $OK ]]; then
170
2015-05-09
f
echo "==> GOOD: bsd.rd integrity checked"
172
2015-05-09
f
echo "==> WARNING: bsd.rd seems corrupted, aborting!!"
179
2015-05-06
f
echo "\n=== MOVING FILE ==="
180
2015-05-09
f
cp -p /bsd /bsd.o || exit 1
181
2015-05-09
f
mv /bsd.rd /bsd.o.rd || exit 1
182
2015-05-09
f
mv $BSDRD / || exit 1
185
2015-05-09
f
echo "==> New bsd.rd installed and old files saved"
186
2015-05-09
f
echo "You can reboot your OS"
187
2015-05-09
f
echo "Type bsd.rd at the boot prompt, [enter] and choose (U)pgrade"
189
2015-05-09
f
echo "If something goes wrong, you can still boot your old kernel"
190
2015-05-09
f
echo "Just type bsd.o at the boot prompt"
192
2015-05-17
f
echo -n "==> Do you want to do it now ? (y/n) "
194
2015-05-09
f
case ${_a} in
196
2015-05-17
f
echo "After the upgrade, run sysmerge(8)"
197
2015-05-09
f
echo "Then, update packages or ports"
198
2015-05-09
f
echo "==> Rebooting..."
202
2015-05-17
f
echo -n "Do you want to put the old bsd.rd back ? (y/n) "
204
2015-05-17
f
case ${_b} in
206
2015-05-17
f
rm /bsd.rd || exit 1
207
2015-05-17
f
rm /bsd.o || exit 1
208
2015-05-17
f
mv /bsd.o.rd /bsd.rd || exit 1
209
2015-05-17
f
echo "Done!"
213
2015-05-17
f
echo "Aborting..."
221
2016-06-11
f
s_upports() {
222
2016-06-11
f
echo "\n=== UPDATE PORTS TREE ==="
223
2016-06-11
f
cd /usr/ports || exit 1
224
2016-06-11
f
cvs up -Pd || exit 1
225
2016-06-11
f
echo "==> New port tree fetched"
229
2016-10-15
dev1
s_when() {
230
2016-10-15
dev1
# will only be done if curl from port/package is installed
231
2016-10-15
dev1
CURL=/usr/local/bin/curl
232
2016-10-15
dev1
if [[ -e $CURL ]]; then
233
2016-10-15
dev1
CURLB="$($CURL -sI ${MIRRORB}${SHAF} | grep Last-Modified)"
234
2016-10-15
dev1
CURLP="$($CURL -sI ${MIRRORPKG}${SHAF} | grep Last-Modified)"
235
2016-10-15
dev1
echo "\n=== BASE AND PACKAGES BUILD DATE ==="
236
2016-10-19
dev1
echo "From ${MIRROR}"
237
2016-10-15
dev1
echo "Base ($ARCH) => $CURLB"
238
2016-10-15
dev1
echo "Packages ($ARCH) => $CURLP"
239
2016-10-15
dev1
echo ""
240
2016-10-15
dev1
echo -n "Do you want to continue ? (y/n): "
241
2016-10-15
dev1
read _c
242
2016-10-15
dev1
case ${_c} in
246
2016-10-15
dev1
echo "Aborting..."
259
2016-10-15
dev1
toupgrade
265
2016-10-15
dev1
toupgrade