Blame
Date:
Sat May 9 15:32:47 2020 UTC
Message:
update manpage and do v2.0 tarball
001
2015-05-06
f
#!/bin/ksh
002
2015-05-06
f
#
003
2015-05-06
f
########################################################################
004
2015-05-06
f
#
005
2020-05-09
f
# snaps - 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
2020-05-08
f
set -ue
041
2020-05-08
f
042
2015-05-06
f
###
043
2015-05-06
f
### VARS
044
2015-05-06
f
###
045
2015-05-06
f
046
2020-05-09
f
VERSION=2.0
047
2015-05-09
f
048
2020-04-29
f
# choose your MIRROR
049
2020-05-09
f
true "${MIRROR:=$(grep -v "^#" /etc/installurl)}"
050
2020-04-27
f
051
2020-04-29
f
# curl is mandatory
052
2020-05-08
f
if [ ! "$(which curl 2>/dev/null)" ]; then
053
2020-05-08
f
echo "WARNING: 'curl' is requested to run this program. Aborting..."
054
2020-05-09
f
exit 1
055
2020-04-29
f
fi
056
2020-05-09
f
CURL=$(whereis curl)
057
2020-04-29
f
058
2020-04-29
f
#
059
2017-03-06
dev1
ARCH=$(uname -m)
060
2020-05-01
f
SHA=SHA256
061
2020-04-29
f
BASE=/snapshots/${ARCH}/
062
2020-05-01
f
BASEF=/snapshots/${ARCH}/${SHA}
063
2020-05-01
f
PKGSF=/snapshots/packages/${ARCH}/${SHA}
064
2020-04-29
f
065
2020-05-09
f
GET='/usr/bin/ftp -n -m -C'
066
2020-04-25
f
067
2015-05-06
f
LOGF=/var/log/snaps.log
068
2015-05-06
f
069
2015-05-06
f
###
070
2015-05-06
f
###
071
2015-06-20
f
###
072
2015-05-06
f
073
2020-04-27
f
074
2020-04-27
f
usage() {
075
2020-05-01
f
echo "${0##*/} ${VERSION}"
076
2020-05-09
f
echo "Usage: ${0##*/} [-scalfuph]"
077
2020-04-27
f
echo ""
078
2020-04-27
f
echo " -s check \$MIRROR freshness & choose to sysupgrade or not"
079
2020-05-09
f
echo " -c check BASE and PACKAGES build dates from \$MIRROR"
080
2020-05-09
f
echo " -a check BASE and PACKAGES build dates from all available mirrors"
081
2020-05-09
f
echo " -l list date and \$MIRROR of the 3 last upgrade using this script"
082
2020-05-03
f
echo " -f read the online FAQ : Following -current and using snapshots"
083
2020-04-27
f
echo " -u upgrade snaps to last version"
084
2020-05-09
f
echo " -p update ports tree to -current"
085
2020-04-27
f
echo " -h print this help and exit"
086
2020-04-27
f
echo ""
087
2020-05-01
f
echo "MIRROR is based upon /etc/installurl and set to: ${MIRROR}"
088
2020-04-27
f
echo ""
089
2020-04-27
f
echo "You can set it manually:"
090
2020-04-27
f
echo "\$ MIRROR=http://mirrors.ircam.fr/pub/OpenBSD snaps -c"
091
2020-04-27
f
echo ""
092
2020-04-27
f
}
093
2020-04-27
f
094
2020-04-27
f
095
2020-04-27
f
s_root() {
096
2020-04-27
f
if [[ $(id -u) != "0" ]]; then
097
2020-05-08
f
echo "WARNING: You need to be root to do this! Aborting..." 1>&2
098
2020-04-27
f
exit 1
099
2020-04-27
f
fi
100
2020-04-27
f
}
101
2020-04-27
f
102
2020-04-27
f
103
2020-05-09
f
s_toupgrade() {
104
2020-05-08
f
REMOTESNAPS='https://framagit.org/fredg/snaps/raw/master/snaps'
105
2020-05-08
f
LASTSNAPS=/tmp/snaps
106
2020-04-27
f
echo "Checking snaps release..."
107
2020-05-01
f
if [[ -f "${LASTSNAPS}" ]]; then
108
2020-05-08
f
rm -f "${LASTSNAPS}"
109
2016-09-11
dev1
fi
110
2020-05-01
f
if $GET -V -o "${LASTSNAPS}" "${REMOTESNAPS}"; then
111
2020-05-01
f
REMOTEVERSION=$(awk -F '=' '/^VERSION=/ { print $2 }' "${LASTSNAPS}")
112
2020-05-01
f
if [ "${VERSION}" != "${REMOTEVERSION}" ]; then
113
2020-04-27
f
echo "WARNING: snaps is not up-to-date !"
114
2020-05-01
f
echo "Last version: ${REMOTEVERSION}"
115
2016-09-11
f
echo "To upgrade, run 'snaps -u'"
116
2016-09-11
dev1
else
117
2020-04-27
f
echo "GOOD: snaps is up-to-date."
118
2016-09-11
f
fi
119
2016-10-23
dev1
else
120
2020-04-27
f
echo "WARNING: Remote snaps not reachable ! Check the connection."
121
2016-09-11
f
fi
122
2020-04-27
f
echo ""
123
2016-09-11
f
}
124
2016-09-11
f
125
2020-04-27
f
126
2020-05-09
f
s_upgrade() {
127
2020-04-27
f
SELFPATH=$(dirname "$(readlink -f -- "$0")")
128
2020-04-27
f
echo "Downloading last snaps version..."
129
2020-05-01
f
$GET -o "${SELFPATH}" "${REMOTESNAPS}"
130
2016-09-11
f
}
131
2016-09-11
f
132
2016-09-11
f
133
2015-05-09
f
get_log() {
134
2020-05-01
f
if [[ -f "${LOGF}" ]]; then
135
2020-05-01
f
tail -n 3 ${LOGF}
136
2015-05-06
f
else
137
2020-05-01
f
echo "No ${LOGF} file. Seems you have not yet played with snaps."
138
2015-05-09
f
exit 1
139
2015-05-06
f
fi
140
2015-05-06
f
}
141
2015-05-06
f
142
2015-05-17
f
143
2016-06-11
f
s_upports() {
144
2020-04-27
f
echo "Updating Ports tree..."
145
2016-06-11
f
cd /usr/ports || exit 1
146
2020-05-09
f
/usr/bin/cvs up -Pd || exit 1
147
2020-04-27
f
echo "New Ports tree fetched!"
148
2016-06-11
f
}
149
2016-06-11
f
150
2020-04-27
f
151
2020-04-27
f
s_cur() {
152
2020-05-08
f
CURRENTSYS=$(sed q /var/run/dmesg.boot)
153
2020-04-27
f
echo "=== LOCAL BASE BUILD DATE ==="
154
2020-04-27
f
echo "${CURRENTSYS}"
155
2020-04-27
f
}
156
2020-04-27
f
157
2020-04-27
f
158
2016-10-15
dev1
s_when() {
159
2020-05-09
f
CURLB="$(${CURL} -sI "${MIRROR}${BASEF}" | grep Last-Modified)"
160
2020-05-09
f
CURLP="$(${CURL} -sI "${MIRROR}${PKGSF}" | grep Last-Modified)"
161
2020-05-09
f
echo "=== ONLINE BASE AND PACKAGES BUILD DATES ==="
162
2020-04-29
f
echo "From ${MIRROR}"
163
2020-04-29
f
echo "Base (${ARCH}) => ${CURLB}"
164
2020-04-29
f
echo "Packages (${ARCH}) => ${CURLP}"
165
2016-10-15
dev1
}
166
2016-10-15
dev1
167
2020-04-27
f
168
2020-05-01
f
s_sysup() {
169
2020-05-08
f
NOW=$(date "+ %Y-%m-%d %R")
170
2020-04-27
f
echo ""
171
2020-04-27
f
echo -n "Do you want to run 'sysupgrade -s' ? (y/n): "
172
2020-04-27
f
read -r _c
173
2020-04-27
f
case ${_c} in
174
2020-04-27
f
y|Y)
175
2020-04-27
f
;;
176
2020-04-27
f
*)
177
2020-04-27
f
echo "Aborting..."
178
2020-04-27
f
exit 1
179
2020-04-27
f
;;
180
2020-04-27
f
esac
181
2020-05-01
f
echo "${NOW} FROM ${MIRROR}${BASE}" >> ${LOGF}
182
2020-05-09
f
/usr/sbin/sysupgrade -s
183
2020-04-27
f
}
184
2020-04-27
f
185
2020-04-27
f
186
2020-05-09
f
read_faq() {
187
2020-05-03
f
FAQ='https://www.openbsd.org/faq/current.html'
188
2020-05-08
f
if [ "$(which links 2>/dev/null)" ]; then
189
2020-05-03
f
READ='links -dump'
190
2020-05-08
f
elif [ "$(which lynx 2>/dev/null)" ]; then
191
2020-05-03
f
READ='lynx --dump'
192
2020-05-03
f
else
193
2020-05-09
f
echo "WARNING: You need 'links' or 'lynx' to read the online FAQ/CURRENT. Aborting..."
194
2020-05-03
f
exit 1
195
2020-05-03
f
fi
196
2020-05-03
f
${READ} ${FAQ} | less
197
2020-05-03
f
}
198
2020-05-03
f
199
2020-05-01
f
all_mirrors() {
200
2020-05-09
f
echo "Checking mirrors..."
201
2020-05-08
f
HTTPSLIST='https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/www/httpslist'
202
2020-05-09
f
MIRRORLIST=$(${CURL} ${HTTPSLIST} | awk '{print $1}')
203
2020-05-09
f
echo ""
204
2020-04-29
f
for _m in ${MIRRORLIST}
205
2020-04-29
f
do
206
2020-05-09
f
CB="$(${CURL} -sI "${_m}${BASEF}" | grep Last-Modified |\
207
2020-04-29
f
sed 's/Last-Modified: //')"
208
2020-05-09
f
CP="$(${CURL} -sI "${_m}${PKGSF}" | grep Last-Modified |\
209
2020-04-29
f
sed 's/Last-Modified: //')"
210
2020-04-29
f
# only print mirror which give an answer
211
2020-04-29
f
# FIXME try to figure out how to print 1 mirror per line
212
2020-04-29
f
if [ "${CB}" ]; then
213
2020-04-29
f
echo "${_m}"
214
2020-04-29
f
echo "${CB}"
215
2020-04-29
f
echo "${CP}"
216
2020-04-29
f
echo ""
217
2020-04-29
f
fi
218
2020-04-29
f
done
219
2020-04-29
f
}
220
2020-04-29
f
221
2020-04-29
f
222
2015-05-06
f
##
223
2015-05-06
f
## Run
224
2015-05-06
f
##
225
2016-10-15
dev1
226
2020-05-09
f
if [ $# -eq 0 ]; then
227
2020-05-09
f
usage
228
2020-05-09
f
exit 1
229
2020-05-09
f
fi
230
2020-05-09
f
231
2015-05-06
f
case $1 in
232
2020-04-27
f
-s)
233
2015-05-09
f
s_root
234
2020-05-09
f
s_toupgrade
235
2020-04-27
f
s_cur
236
2020-04-27
f
echo ""
237
2016-10-15
dev1
s_when
238
2020-04-27
f
s_sysup
239
2015-05-06
f
;;
240
2020-04-27
f
-c)
241
2020-04-27
f
s_when
242
2020-04-27
f
;;
243
2020-04-29
f
-a)
244
2020-04-29
f
all_mirrors
245
2020-04-29
f
;;
246
2015-05-06
f
-l)
247
2015-05-30
f
get_log
248
2015-05-06
f
;;
249
2020-05-09
f
-f)
250
2020-05-09
f
read_faq
251
2020-05-09
f
;;
252
2016-09-11
f
-u)
253
2020-05-09
f
s_upgrade
254
2016-09-11
f
;;
255
2020-05-09
f
-p)
256
2020-05-09
f
s_upports
257
2020-05-09
f
;;
258
2015-05-06
f
-h|*)
259
2015-05-06
f
usage
260
2015-05-06
f
exit 1
261
2015-05-06
f
;;
262
2015-05-06
f
esac
263
2020-04-27
f
Frédéric Galusik