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