Blame
Date:
Sun Sep 11 11:39:17 2016 UTC
Message:
take care of AUTHORS
001
2015-05-06
f
#!/bin/ksh
002
2015-05-06
f
#
003
2015-05-06
f
########################################################################
004
2015-05-06
f
#
005
2015-05-06
f
# snaps.sh - Upgrade your OpenBSD OS base to last -current snapshot
006
2015-05-06
f
#
007
2015-05-06
f
# Copyright (c) 2015, Fred Galusik <f AT galusik.xyz>
008
2015-05-06
f
# All rights reserved.
009
2015-05-06
f
#
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
012
2015-05-06
f
# met:
013
2015-05-06
f
#
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.
016
2015-05-06
f
#
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.
020
2015-05-06
f
#
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.
024
2015-05-06
f
#
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.
036
2015-05-06
f
#
037
2015-05-06
f
########################################################################
038
2015-05-06
f
039
2015-05-06
f
###
040
2015-05-06
f
### VARS
041
2015-05-06
f
###
042
2015-05-06
f
043
2016-09-03
dev1
VERSION=0.8
044
2015-05-09
f
045
2016-05-15
dev1
MIRRORSOURCE=$(awk -F '=' '/^installpath/ { gsub(/ /,"",$2); print $2 }' /etc/pkg.conf)
046
2015-09-20
f
ARCH=$(uname -m)
047
2015-05-09
f
048
2015-05-17
f
if [ ! $MIRROR ]; then
049
2016-09-03
f
#MIRROR=$(echo $MIRRORSOURCE | sed -e 's@installpath = @@' -e "s@\%c\/packages\/\%a@snapshots\/${ARCH}@")
050
2016-09-03
f
MIRROR="$(echo $MIRRORSOURCE | cut -d'/' -f-3)/pub/OpenBSD/snapshots/${ARCH}/"
051
2015-05-17
f
fi
052
2015-05-17
f
053
2016-05-14
dev1
RL=60 # signify var
054
2015-05-17
f
055
2015-05-06
f
BSDRD=bsd.rd
056
2015-05-06
f
SHAF=SHA256
057
2015-05-06
f
SIGF=SHA256.sig
058
2015-05-06
f
059
2015-05-06
f
SIGNPUB=/etc/signify/openbsd-$RL-base.pub
060
2015-05-17
f
GET='ftp -n -m -C'
061
2015-05-06
f
REBOOT='/sbin/reboot'
062
2015-05-06
f
063
2015-05-06
f
LOGF=/var/log/snaps.log
064
2015-05-17
f
NOW=$(date "+ %Y-%m-%d %R")
065
2015-05-06
f
066
2016-09-11
f
REMOTESNAPS='https://framagit.org/fredg/snaps/raw/master/snaps'
067
2016-09-11
f
LASTSNAPS=/tmp/snaps
068
2015-05-06
f
###
069
2015-05-06
f
###
070
2015-06-20
f
###
071
2015-05-06
f
072
2016-09-11
f
toupgrade() {
073
2016-09-11
f
echo "Checking for new version..."
074
2016-09-11
f
$GET -V -o "$LASTSNAPS" "$REMOTESNAPS"
075
2016-09-11
f
REMOTEVERSION=$(grep "VERSION=" "$LASTSNAPS" | cut -d'=' -f2)
076
2016-09-11
f
077
2016-09-11
f
if [ $? -eq 0 ]; then
078
2016-09-11
f
079
2016-09-11
f
if [ "$VERSION" != "$REMOTEVERSION" ]; then
080
2016-09-11
f
echo "---"
081
2016-09-11
f
echo "This is not the last version of snaps".
082
2016-09-11
f
echo "Last version : $REMOTEVERSION"
083
2016-09-11
f
echo "To upgrade, run 'snaps -u'"
084
2016-09-11
f
echo "---"
085
2016-09-11
f
fi
086
2016-09-11
f
fi
087
2016-09-11
f
}
088
2016-09-11
f
089
2016-09-11
f
upgrade() {
090
2016-09-11
f
SELFPATH=$(readlink -f $0)
091
2016-09-11
f
echo "Downloading last snaps version"
092
2016-09-11
f
$GET -o "$SELFPATH" "$REMOTESNAPS"
093
2016-09-11
f
}
094
2016-09-11
f
095
2016-09-11
f
096
2015-05-09
f
usage() {
097
2016-05-15
dev1
echo "${0##*/} $VERSION"
098
2016-05-15
dev1
echo "Usage: ${0##*/} [-gGlh]"
099
2016-05-15
dev1
echo " -g fetch and check bsd.rd from \$MIRROR"
100
2016-05-15
dev1
echo " -G fetch, check and install bsd.rd from \$MIRROR"
101
2016-06-11
f
echo " -p update port tree to current"
102
2016-05-15
dev1
echo " -l list date and \$MIRROR of 3 last bsd.rd"
103
2016-09-11
f
echo " -u upgrade snaps to last version"
104
2016-05-15
dev1
echo " -h print this help and exit"
105
2016-05-15
dev1
echo ""
106
2016-05-15
dev1
echo "MIRROR is based upon /etc/pkg.conf and set to: $MIRROR"
107
2016-05-15
dev1
echo ""
108
2016-05-15
dev1
echo "You can set it manually:"
109
2016-05-15
dev1
echo "\$ doas MIRROR=http://mirrors.ircam.fr/pub/OpenBSD/snapshots/amd64/ snaps -G"
110
2016-05-15
dev1
echo ""
111
2015-05-06
f
}
112
2015-05-06
f
113
2015-05-09
f
s_root() {
114
2015-05-09
f
if [[ $(id -u) != "0" ]]; then
115
2015-05-09
f
echo "==> WARNING: You need to be root to do this" 1>&2
116
2015-05-06
f
exit 1
117
2015-05-06
f
fi
118
2015-05-06
f
}
119
2015-05-06
f
120
2015-05-06
f
121
2015-05-09
f
s_log() {
122
2015-06-20
f
echo "$NOW FROM $MIRROR" >> $LOGF
123
2015-05-06
f
}
124
2015-05-06
f
125
2015-05-06
f
126
2015-05-09
f
get_log() {
127
2015-05-09
f
if [[ -f $LOGF ]]; then
128
2015-05-06
f
tail -n 3 $LOGF
129
2015-05-06
f
else
130
2015-05-09
f
echo "No $LOGF file. Seems you have not yet played with snaps"
131
2015-05-09
f
exit 1
132
2015-05-06
f
fi
133
2015-05-06
f
}
134
2015-05-06
f
135
2015-05-17
f
136
2015-05-09
f
get_rd() {
137
2015-05-06
f
echo "\n=== FETCHING FILES ==="
138
2015-05-09
f
for _i in $BSDRD $SHAF $SIGF; do
139
2015-05-09
f
if [[ -f ${_i} ]]; then
140
2015-05-09
f
echo "\nDeleted old ${_i}"
141
2015-05-09
f
rm ${_i}
142
2015-05-06
f
fi
143
2015-06-20
f
echo "==> Fetching new ${_i}"
144
2015-05-09
f
$GET $MIRROR${_i} || exit 1
145
2015-05-06
f
done
146
2015-05-06
f
}
147
2015-05-06
f
148
2015-05-06
f
149
2015-05-09
f
s_check() {
150
2015-05-06
f
echo "\n=== FILE INTEGRITY CHECKING ==="
151
2016-04-23
dev1
echo "Sign key: $SIGNPUB"
152
2015-05-06
f
OK=OK
153
2015-05-06
f
# signify
154
2016-04-23
dev1
if [[ $(signify -C -p $SIGNPUB -x $SIGF $BSDRD 2>&1 | grep OK | awk '{print $2}') = $OK ]]; then
155
2015-05-09
f
echo "==> GOOD: $SHAF file is coming from OpenBSD"
156
2015-05-06
f
else
157
2015-05-09
f
echo "==> WARNING: $SHAF is not coming from OpenBSD, aborting!!"
158
2015-05-09
f
exit 1
159
2015-05-06
f
fi
160
2015-05-06
f
# sha256
161
2015-05-09
f
if [[ $(sha256 -c $SHAF 2>&1 | grep OK | awk '{print $3}') = $OK ]]; then
162
2015-05-09
f
echo "==> GOOD: bsd.rd integrity checked"
163
2015-05-06
f
else
164
2015-05-09
f
echo "==> WARNING: bsd.rd seems corrupted, aborting!!"
165
2015-05-09
f
exit 1
166
2015-05-06
f
fi
167
2015-05-06
f
}
168
2015-05-06
f
169
2015-05-06
f
170
2015-05-09
f
s_move() {
171
2015-05-06
f
echo "\n=== MOVING FILE ==="
172
2015-05-09
f
cp -p /bsd /bsd.o || exit 1
173
2015-05-09
f
mv /bsd.rd /bsd.o.rd || exit 1
174
2015-05-09
f
mv $BSDRD / || exit 1
175
2015-05-09
f
rm $SHAF
176
2015-05-09
f
rm $SIGF
177
2015-05-09
f
echo "==> New bsd.rd installed and old files saved"
178
2015-05-09
f
echo "You can reboot your OS"
179
2015-05-09
f
echo "Type bsd.rd at the boot prompt, [enter] and choose (U)pgrade"
180
2015-05-09
f
echo ""
181
2015-05-09
f
echo "If something goes wrong, you can still boot your old kernel"
182
2015-05-09
f
echo "Just type bsd.o at the boot prompt"
183
2015-05-09
f
echo ""
184
2015-05-17
f
echo -n "==> Do you want to do it now ? (y/n) "
185
2015-05-09
f
read _a
186
2015-05-09
f
case ${_a} in
187
2015-05-06
f
y|Y)
188
2015-05-17
f
echo "After the upgrade, run sysmerge(8)"
189
2015-05-09
f
echo "Then, update packages or ports"
190
2015-05-09
f
echo "==> Rebooting..."
191
2015-05-09
f
$REBOOT
192
2015-05-06
f
;;
193
2015-05-06
f
*)
194
2015-05-17
f
echo -n "Do you want to put the old bsd.rd back ? (y/n) "
195
2015-05-17
f
read _b
196
2015-05-17
f
case ${_b} in
197
2015-05-17
f
y|Y)
198
2015-05-17
f
rm /bsd.rd || exit 1
199
2015-05-17
f
rm /bsd.o || exit 1
200
2015-05-17
f
mv /bsd.o.rd /bsd.rd || exit 1
201
2015-05-17
f
echo "Done!"
202
2015-05-17
f
exit 1
203
2015-05-17
f
;;
204
2015-05-17
f
*)
205
2015-05-17
f
echo "Aborting..."
206
2015-05-17
f
exit 1
207
2015-05-17
f
;;
208
2015-05-17
f
esac
209
2015-05-06
f
;;
210
2015-05-06
f
esac
211
2015-05-06
f
}
212
2015-05-06
f
213
2016-06-11
f
s_upports() {
214
2016-06-11
f
echo "\n=== UPDATE PORTS TREE ==="
215
2016-06-11
f
cd /usr/ports || exit 1
216
2016-06-11
f
cvs up -Pd || exit 1
217
2016-06-11
f
echo "==> New port tree fetched"
218
2016-06-11
f
echo ""
219
2016-06-11
f
}
220
2016-06-11
f
221
2015-05-06
f
##
222
2015-05-06
f
## Run
223
2015-05-06
f
##
224
2016-09-11
f
toupgrade
225
2015-05-06
f
case $1 in
226
2015-05-06
f
-g)
227
2015-05-06
f
get_rd
228
2015-05-09
f
s_check
229
2015-05-06
f
;;
230
2015-05-06
f
-G)
231
2015-05-09
f
s_root
232
2015-05-09
f
s_log
233
2015-05-06
f
get_rd
234
2015-05-09
f
s_check
235
2015-05-09
f
s_move
236
2015-05-06
f
;;
237
2016-06-11
f
-p)
238
2016-06-11
f
s_upports
239
2016-06-11
f
;;
240
2015-05-06
f
-l)
241
2015-05-30
f
get_log
242
2015-05-06
f
;;
243
2016-09-11
f
-u)
244
2016-09-11
f
upgrade
245
2016-09-11
f
;;
246
2015-05-06
f
-h|*)
247
2015-05-06
f
usage
248
2015-05-06
f
exit 1
249
2015-05-06
f
;;
250
2015-05-06
f
esac
Frédéric Galusik