Commit Diff
Diff:
cd6c349b9102a05b100e52618c2284d333f2c1a5
2ab8393b1b8f2aaefae8ec60eb38af2737fea0a4
Commit:
2ab8393b1b8f2aaefae8ec60eb38af2737fea0a4
Tree:
7d9e77c4f59b120b82206b19a13e06c85ae9139e
Author:
Fred. Galusik <f@galusik.fr>
Committer:
Fred. Galusik <f@galusik.fr>
Date:
Mon Apr 27 20:45:40 2020 UTC
Message:
Some cleanup to take care of sysupgrade
blob - b295101d3330458a0a341dbf5a8f99fd2b2063f2
blob + e6d78a3614ba69f59507f81c33ffe23451e72194
--- snaps
+++ snaps
@@ -43,11 +43,12 @@
VERSION=1.3
-if [ ! $MIRROR ]; then
+if [ ! "$MIRROR" ]; then
MIRROR=$(grep -v "^#" /etc/installurl)
fi
+
+CURRENTSYS=$(sed 1q /var/run/dmesg.boot)
ARCH=$(uname -m)
-
MIRRORB=${MIRROR}/snapshots/${ARCH}/
MIRRORPKG=${MIRROR}/snapshots/packages/${ARCH}/
@@ -65,206 +66,136 @@ LASTSNAPS=/tmp/snaps
###
###
+
+usage() {
+ echo "${0##*/} $VERSION"
+ echo "Usage: ${0##*/} [-scpluh]"
+ echo ""
+ echo " -s check \$MIRROR freshness & choose to sysupgrade or not"
+ echo " -c check BASE and PACKAGES build date from \$MIRROR"
+ echo " -p update port tree to -current"
+ echo " -l list date and \$MIRROR of the 3 last upgrade with this script"
+ echo " -u upgrade snaps to last version"
+ echo " -h print this help and exit"
+ echo ""
+ echo "MIRROR is based upon /etc/installurl and set to: $MIRROR"
+ echo ""
+ echo "You can set it manually:"
+ echo "\$ MIRROR=http://mirrors.ircam.fr/pub/OpenBSD snaps -c"
+ echo ""
+}
+
+
+s_root() {
+ if [[ $(id -u) != "0" ]]; then
+ echo "WARNING: You need to be root to do this!" 1>&2
+ exit 1
+ fi
+}
+
+
toupgrade() {
- printf "\n %s" "=== NEW VERSION CHECKING ==="
- # some cleanup to not let ftp warn about not supporting resume
- if [[ -f $LASTSNAPS ]]; then
+ echo "Checking snaps release..."
+ if [[ -f "$LASTSNAPS" ]]; then
rm -f $LASTSNAPS
fi
-
if $GET -V -o "$LASTSNAPS" "$REMOTESNAPS"; then
-
REMOTEVERSION=$(awk -F '=' '/^VERSION=/ { print $2 }' "$LASTSNAPS")
-
if [ "$VERSION" != "$REMOTEVERSION" ]; then
- echo "==> WARNING: snaps is not up-to-date !"
+ echo "WARNING: snaps is not up-to-date !"
echo "Last version: $REMOTEVERSION"
echo "To upgrade, run 'snaps -u'"
else
- echo "==> GOOD: snaps is up-to-date"
+ echo "GOOD: snaps is up-to-date."
fi
-
else
- echo "==> WARNING: Remote snaps not reachable ! Check the connection."
+ echo "WARNING: Remote snaps not reachable ! Check the connection."
fi
+ echo ""
}
+
upgrade() {
- SELFPATH=$(dirname $(readlink -f -- "$0"))
- echo "Downloading last snaps version"
+ SELFPATH=$(dirname "$(readlink -f -- "$0")")
+ echo "Downloading last snaps version..."
$GET -o "$SELFPATH" "$REMOTESNAPS"
}
-usage() {
- echo ""
- echo "${0##*/} $VERSION"
- echo "Usage: ${0##*/} [-gGlh]"
- echo " -g fetch and check bsd.rd from \$MIRROR"
- echo " -G fetch, check and install bsd.rd from \$MIRROR"
- echo " -p update port tree to current"
- echo " -l list date and \$MIRROR of 3 last bsd.rd"
- echo " -u upgrade snaps to last version"
- echo " -h print this help and exit"
- echo ""
- echo "MIRROR is based upon /etc/installurl and set to: $MIRROR"
- echo ""
- echo "You can set it manually:"
- echo "\$ MIRROR=http://mirrors.ircam.fr/pub/OpenBSD doas snaps -G"
- echo ""
-}
-
-s_root() {
- if [[ $(id -u) != "0" ]]; then
- echo "==> WARNING: You need to be root to do this" 1>&2
- exit 1
- fi
-}
-
-
-s_log() {
- echo "$NOW FROM $MIRRORB" >> $LOGF
-}
-
-
get_log() {
- if [[ -f $LOGF ]]; then
+ if [[ -f "$LOGF" ]]; then
tail -n 3 $LOGF
else
- echo "No $LOGF file. Seems you have not yet played with snaps"
+ echo "No $LOGF file. Seems you have not yet played with snaps."
exit 1
fi
}
-get_rd() {
- echo "\n=== FETCHING FILES ==="
- for _i in $BSDRD $SHAF $SIGF; do
- if [[ -f ${_i} ]]; then
- echo "\nDeleted old ${_i}"
- rm ${_i}
- fi
- echo "==> Fetching new ${_i}"
- $GET $MIRRORB${_i} || exit 1
- done
-}
-
-
-s_check() {
- echo "\n=== FILE INTEGRITY CHECKING ==="
- echo "Sign key: $SIGNPUB"
- OK=OK
- # signify
- if [[ $(signify -C -p $SIGNPUB -x $SIGF $BSDRD | awk '/'$BSDRD'/ {print $2}') = $OK ]]; then
- echo "==> GOOD: $SHAF file is coming from OpenBSD"
- else
- echo "==> WARNING: $SHAF is not coming from OpenBSD, aborting!!"
- exit 1
- fi
- # sha256
- if [[ $(sha256 -c $SHAF 2>&1 | awk '/'$BSDRD'/ {print $3}') = $OK ]]; then
- echo "==> GOOD: bsd.rd integrity checked"
- else
- echo "==> WARNING: bsd.rd seems corrupted, aborting!!"
- exit 1
- fi
-}
-
-
-s_move() {
- echo "\n=== MOVING FILE ==="
- cp -p /bsd /bsd.o || exit 1
- mv /bsd.rd /bsd.o.rd || exit 1
- mv $BSDRD / || exit 1
- rm $SHAF
- rm $SIGF
- echo "==> New bsd.rd installed and old files saved"
- echo "You can reboot your OS"
- echo "Type bsd.rd at the boot prompt, [enter] and choose (U)pgrade"
- echo ""
- echo "If something goes wrong, you can still boot your old kernel"
- echo "Just type bsd.o at the boot prompt"
- echo ""
- echo -n "==> Do you want to do it now ? (y/n) "
- read _a
- case ${_a} in
- y|Y)
- echo "After the upgrade, run sysmerge(8)"
- echo "Then, update packages or ports"
- echo "==> Rebooting..."
- $REBOOT
- ;;
- *)
- echo -n "Do you want to put the old bsd.rd back ? (y/n) "
- read _b
- case ${_b} in
- y|Y)
- rm /bsd.rd || exit 1
- rm /bsd.o || exit 1
- mv /bsd.o.rd /bsd.rd || exit 1
- echo "Done!"
- exit 1
- ;;
- *)
- echo "Aborting..."
- exit 1
- ;;
- esac
- ;;
- esac
-}
-
s_upports() {
- echo "\n=== UPDATE PORTS TREE ==="
+ echo "Updating Ports tree..."
cd /usr/ports || exit 1
cvs up -Pd || exit 1
- echo "==> New port tree fetched"
- echo ""
+ echo "New Ports tree fetched!"
}
+
+s_cur() {
+ echo "=== LOCAL BASE BUILD DATE ==="
+ echo "${CURRENTSYS}"
+}
+
+
s_when() {
# will only be done if curl from port/package is installed
CURL=/usr/local/bin/curl
- if [[ -e $CURL ]]; then
- CURLB="$($CURL -sI ${MIRRORB}${SHAF} | grep Last-Modified)"
- CURLP="$($CURL -sI ${MIRRORPKG}${SHAF} | grep Last-Modified)"
- echo "\n=== BASE AND PACKAGES BUILD DATE ==="
+ if [[ -e ${CURL} ]]; then
+ CURLB="$(${CURL} -sI "${MIRRORB}${SHAF}" | grep Last-Modified)"
+ CURLP="$(${CURL} -sI "${MIRRORPKG}${SHAF}" | grep Last-Modified)"
+ echo "=== ONLINE BASE AND PACKAGES BUILD DATE ==="
echo "From ${MIRROR}"
- echo "Base ($ARCH) => $CURLB"
- echo "Packages ($ARCH) => $CURLP"
- echo ""
- echo -n "Do you want to continue ? (y/n): "
- read _c
- case ${_c} in
- y|Y)
- ;;
- *)
- echo "Aborting..."
- exit 1
- ;;
- esac
+ echo "Base (${ARCH}) => ${CURLB}"
+ echo "Packages (${ARCH}) => ${CURLP}"
+ else
+ echo "${CURL} is required to run this program. Aborting..."
+ exit 1
fi
}
+
+s_sysup () {
+ echo ""
+ echo -n "Do you want to run 'sysupgrade -s' ? (y/n): "
+ read -r _c
+ case ${_c} in
+ y|Y)
+ ;;
+ *)
+ echo "Aborting..."
+ exit 1
+ ;;
+ esac
+ echo "${NOW} FROM ${MIRRORB}" >> ${LOGF}
+ sysupgrade -s
+}
+
+
##
## Run
##
case $1 in
- -g)
- toupgrade
- get_rd
- s_check
- ;;
- -G)
+ -s)
s_root
toupgrade
+ s_cur
+ echo ""
s_when
- s_log
- get_rd
- s_check
- s_move
+ s_sysup
;;
+ -c)
+ s_when
+ ;;
-p)
s_upports
;;
@@ -279,3 +210,4 @@ case $1 in
exit 1
;;
esac
+
Frédéric Galusik