003
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
008
2020-04-25
f
# Copyright (c) 2017-2020, Fred Galusik <f AT galusik.fr>
009
2015-05-06
f
# All rights reserved.
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
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.
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.
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.
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.
038
2015-05-06
f
########################################################################
046
2017-08-25
dev1
VERSION=1.3
048
2020-04-29
f
# choose your MIRROR
049
2020-05-09
f
true "${MIRROR:=$(grep -v "^#" /etc/installurl)}"
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..."
056
2020-05-09
f
CURL=$(whereis curl)
059
2017-03-06
dev1
ARCH=$(uname -m)
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}
065
2020-05-09
f
GET='/usr/bin/ftp -n -m -C'
067
2015-05-06
f
LOGF=/var/log/snaps.log
075
2020-05-01
f
echo "${0##*/} ${VERSION}"
076
2020-05-09
f
echo "Usage: ${0##*/} [-scalfuph]"
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"
087
2020-05-01
f
echo "MIRROR is based upon /etc/installurl and set to: ${MIRROR}"
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"
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
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}"
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'"
117
2020-04-27
f
echo "GOOD: snaps is up-to-date."
120
2020-04-27
f
echo "WARNING: Remote snaps not reachable ! Check the connection."
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}"
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}
137
2020-05-01
f
echo "No ${LOGF} file. Seems you have not yet played with snaps."
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!"
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}"
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}"
168
2020-05-01
f
s_sysup() {
169
2020-05-08
f
NOW=$(date "+ %Y-%m-%d %R")
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
177
2020-04-27
f
echo "Aborting..."
181
2020-05-01
f
echo "${NOW} FROM ${MIRROR}${BASE}" >> ${LOGF}
182
2020-05-09
f
/usr/sbin/sysupgrade -s
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'
193
2020-05-09
f
echo "WARNING: You need 'links' or 'lynx' to read the online FAQ/CURRENT. Aborting..."
196
2020-05-03
f
${READ} ${FAQ} | less
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}')
204
2020-04-29
f
for _m in ${MIRRORLIST}
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}"
226
2020-05-09
f
if [ $# -eq 0 ]; then
234
2020-05-09
f
s_toupgrade
244
2020-04-29
f
all_mirrors