003
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
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..."
058
2017-03-06
dev1
ARCH=$(uname -m)
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}
064
2020-04-25
f
GET='ftp -n -m -C'
066
2015-05-06
f
LOGF=/var/log/snaps.log
074
2020-05-01
f
echo "${0##*/} ${VERSION}"
075
2020-05-03
f
echo "Usage: ${0##*/} [-scaplfuh]"
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"
086
2020-05-01
f
echo "MIRROR is based upon /etc/installurl and set to: ${MIRROR}"
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"
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
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}"
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'"
116
2020-04-27
f
echo "GOOD: snaps is up-to-date."
119
2020-04-27
f
echo "WARNING: Remote snaps not reachable ! Check the connection."
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}"
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}
136
2020-05-01
f
echo "No ${LOGF} file. Seems you have not yet played with snaps."
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!"
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}"
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}"
167
2020-05-01
f
s_sysup() {
168
2020-05-08
f
NOW=$(date "+ %Y-%m-%d %R")
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
176
2020-04-27
f
echo "Aborting..."
180
2020-05-01
f
echo "${NOW} FROM ${MIRROR}${BASE}" >> ${LOGF}
181
2020-04-27
f
sysupgrade -s
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'
192
2020-05-09
f
echo "WARNING: You need 'links' or 'lynx' to read the online FAQ/CURRENT. Aborting..."
195
2020-05-03
f
${READ} ${FAQ} | less
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}
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}"
223
2020-05-09
f
if [ $# -eq 0 ]; then
231
2020-05-09
f
s_toupgrade
244
2020-04-29
f
all_mirrors