~fredg/snaps

c5a4674bacd96a390519320eafbd2a8366795aa2 — Fred. Galusik 2 years ago 0dc1a0a
some fixes
1 files changed, 20 insertions(+), 23 deletions(-)

M snaps
M snaps => snaps +20 -23
@@ 37,6 37,8 @@
#
########################################################################

set -ue

###
### VARS
###


@@ 44,34 46,24 @@
VERSION=1.3

# choose your MIRROR
if [ ! "${MIRROR}" ]; then
    MIRROR=$(grep -v "^#" /etc/installurl)
fi
true ${MIRROR:=$(grep -v "^#" /etc/installurl)}

# curl is mandatory
CURL=/usr/local/bin/curl
if [[ ! -e ${CURL} ]]; then
    echo "{CURL} is requested to run this program. Aborting..."
if [ ! "$(which curl 2>/dev/null)" ]; then
    echo "WARNING: 'curl' is requested to run this program. Aborting..."
    exit 1
fi

# 
CURRENTSYS=$(sed q /var/run/dmesg.boot)
ARCH=$(uname -m)
SHA=SHA256
BASE=/snapshots/${ARCH}/
BASEF=/snapshots/${ARCH}/${SHA}
PKGSF=/snapshots/packages/${ARCH}/${SHA}

HTTPSLIST='https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/www/httpslist'

GET='ftp -n -m -C'

LOGF=/var/log/snaps.log
NOW=$(date "+ %Y-%m-%d %R")

REMOTESNAPS='https://framagit.org/fredg/snaps/raw/master/snaps'
LASTSNAPS=/tmp/snaps

###
###


@@ 101,16 93,18 @@ usage() {

s_root() {
    if [[ $(id -u) != "0" ]]; then
        echo "WARNING: You need to be root to do this!" 1>&2
        echo "WARNING: You need to be root to do this! Aborting..." 1>&2
        exit 1
    fi
}


toupgrade() {
    REMOTESNAPS='https://framagit.org/fredg/snaps/raw/master/snaps'
    LASTSNAPS=/tmp/snaps
    echo "Checking snaps release..."
    if [[ -f "${LASTSNAPS}" ]]; then
      rm -f ${LASTSNAPS}
      rm -f "${LASTSNAPS}"
    fi
    if $GET -V -o "${LASTSNAPS}" "${REMOTESNAPS}"; then
        REMOTEVERSION=$(awk -F '=' '/^VERSION=/ { print $2 }' "${LASTSNAPS}")


@@ 154,14 148,15 @@ s_upports() {


s_cur() {
    CURRENTSYS=$(sed q /var/run/dmesg.boot)
    echo "=== LOCAL BASE BUILD DATE ==="
    echo "${CURRENTSYS}"
}


s_when() {
    CURLB="$(${CURL} -sI "${MIRROR}${BASEF}" | grep Last-Modified)"
    CURLP="$(${CURL} -sI "${MIRROR}${PKGSF}" | grep Last-Modified)"
    CURLB="$(curl -sI "${MIRROR}${BASEF}" | grep Last-Modified)"
    CURLP="$(curl -sI "${MIRROR}${PKGSF}" | grep Last-Modified)"
    echo "=== ONLINE BASE AND PACKAGES BUILD DATE ==="
    echo "From ${MIRROR}"
    echo "Base (${ARCH})     => ${CURLB}"


@@ 170,6 165,7 @@ s_when() {


s_sysup() {
    NOW=$(date "+ %Y-%m-%d %R")
    echo ""
    echo -n "Do you want to run 'sysupgrade -s' ? (y/n): "
    read -r _c


@@ 188,24 184,25 @@ s_sysup() {

read_cur() {
    FAQ='https://www.openbsd.org/faq/current.html'
    if [ $(which links 2>/dev/null) ]; then
    if [ "$(which links 2>/dev/null)" ]; then
        READ='links -dump'
    elif [ $(which lynx 2>/dev/null) ]; then
    elif [ "$(which lynx 2>/dev/null)" ]; then
        READ='lynx --dump'
    else
        echo "You need 'links' or 'lynx' to get the FAQ/CURRENT. Aborting..."
        echo "You need 'links' or 'lynx' to read the online FAQ/CURRENT. Aborting..."
        exit 1
    fi
    ${READ} ${FAQ} | less
}

all_mirrors() {
    MIRRORLIST=$(${CURL} ${HTTPSLIST} | awk '{print $1}')
    HTTPSLIST='https://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/www/httpslist'
    MIRRORLIST=$(curl ${HTTPSLIST} | awk '{print $1}')
    for _m in ${MIRRORLIST}
    do
        CB="$(${CURL} -sI "${_m}${BASEF}" | grep Last-Modified |\
        CB="$(curl -sI "${_m}${BASEF}" | grep Last-Modified |\
            sed 's/Last-Modified: //')"
        CP="$(${CURL} -sI "${_m}${PKGSF}" | grep Last-Modified |\
        CP="$(curl -sI "${_m}${PKGSF}" | grep Last-Modified |\
            sed 's/Last-Modified: //')"
        # only print mirror which give an answer
        # FIXME try to figure out how to print 1 mirror per line