diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2019-09-14 22:51:18 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2019-09-14 22:51:18 +0200 |
commit | 5b2aff639e7ffed125dbe1832608a63e77fe7ffe (patch) | |
tree | 24634adc0269c3477de2590354cf2f80dc0a5a7a | |
parent | d3e2ccb0118b9c878efad9b45c19c4869f986133 (diff) | |
download | slackupgrade-5b2aff639e7ffed125dbe1832608a63e77fe7ffe.tar.gz slackupgrade-5b2aff639e7ffed125dbe1832608a63e77fe7ffe.tar.bz2 |
Try to locate the next distribution automatically
-rw-r--r-- | slackware-upgrade-system | 123 | ||||
-rw-r--r-- | slackware-upgrade-system.8 | 6 |
2 files changed, 79 insertions, 50 deletions
diff --git a/slackware-upgrade-system b/slackware-upgrade-system index bc55bca..89bb3fc 100644 --- a/slackware-upgrade-system +++ b/slackware-upgrade-system @@ -19,7 +19,7 @@ set -e # Slackware root directory -rootdir=/root/slackware +rooturl= # Log file name logfile= # 'y', if dry-run mode is requested @@ -112,11 +112,23 @@ function getyn() { fi } +function error { + echo >&2 "$0: $*" + if [ -n "$logfile" ]; then + echo >$logfile "$0: $*" + fi +} + +function abend { + error "$@" + tempdir_remove + exit 1 +} + function package_file_name() { pkg=$(awk -vname=$1 '$1==name { print $2 }' $avail_index) if [ -z "$pkg" ]; then - echo >&2 "$0: package $name not found in index (should not happen!)" - echo >$logfile "$0: package $name not found in index (should not happen!)" + error "package $name not found in index (should not happen!)" else echo $pkg fi @@ -131,11 +143,11 @@ function series_package_names() { } function catfile() { - echo $rootdir/${1#./} + echo $rooturl/${1#./} } function download_curl { - curl -sS -o$1 $2 + curl -L -sS -o$1 $2 } function download_wget { @@ -145,6 +157,18 @@ function download_wget { fi } +function dnfunc_init() { + if [ -z "$dnfunc" ]; then + if curl --version >/dev/null 2>&1; then + dnfunc=download_curl + elif wget --version >/dev/null 2>&1; then + dnfunc=download_wget + else + abend "neither curl nor wget is installed" + fi + fi +} + function download() { local name=$(basename $1) local url=$(catfile $1) @@ -154,7 +178,7 @@ function download() { && ${GPG:-gpg2} --verify $name.asc $name 2>/dev/null; then : else - echo >&2 "$0: gpg verification failed for $name" + error "gpg verification failed for $name" return fi fi @@ -214,92 +238,95 @@ done shift $(($OPTIND - 1)) case $# in 0) ;; - 1) rootdir=$1;; - *) echo >&2 "$0: unexpected arguments" + 1) rooturl=$1;; + *) error "unexpected arguments" usage >&2 exit 1 esac if [ $(id -u) != "0" ]; then - echo >&2 "$0: must be root" - exit 1 + abend "must be root" fi # Sanity check if [ ! -s /etc/os-release ]; then - echo >&2 "$0: /etc/os-release doesn't exist" - exit 1 + abend "/etc/os-release doesn't exist" fi . /etc/os-release if [ "$ID" != "slackware" ]; then - echo >&2 "$0: this doesn't seem to be a Slackware installation" - exit 1 + abend "this doesn't seem to be a Slackware installation" fi case "$(uname -m)" in i?86) ARCH=;; x86_64) ARCH=64;; - *) echo >&2 "$0: architecture $(uname -m) is not yet supported" - exit + *) abend "architecture $(uname -m) is not yet supported" esac -# Check if rootdir is local or remote -case $rootdir in +tempdir_create +cd $tempdir + +mirrors_url=https://mirrors.slackware.com/slackware +if [ -z "$rooturl" ]; then + dnfunc_init + if ! $dnfunc index.html $mirrors_url; then + abend "exiting" + exit 1 + fi + version_rx=$(echo $VERSION | sed -e 's/\./\\./g') + new_version=$(cat index.html |\ + tr '<' '\n' |\ + sed -n -r \ + -e 's/.*^a href="slackware'$ARCH'-([[:digit:].]+)\/?".*/\1/p'|\ + sed -n -e "/$version_rx/{" -en -ep -e '}' ) + if [ -n "$new_version" ]; then + rooturl="$mirrors_url/slackware$ARCH-$new_version" + error "info: using $rooturl as distribution top-level URL" + else + error "no URL supplied" + fi +fi + +# Check if rooturl is local or remote +case $rooturl in /*) unset remote ;; http://*|https://*|ftp://*|ftps://*) - if curl --version >/dev/null 2>&1; then - dnfunc=download_curl - elif wget --version >/dev/null 2>&1; then - dnfunc=download_wget - else - echo >&2 "$0: neither curl nor wget is installed" - echo >&2 "$0: can't continue" - exit 1 - fi + dnfunc_init remote=1 ;; - *) echo >&2 "$0: root directory must be absolute file name or URL" - exit 1 + *) abend "root directory must be absolute file name or URL" esac if [ -z "$remote" ]; then - # Check if rootdir exists and contains the necessary files and directories - if [ ! -d $rootdir ]; then - echo >&2 "$0: $rootdir does not exist" - exit 1 + # Check if rooturl exists and contains the necessary files and directories + if [ ! -d $rooturl ]; then + abend "$rooturl does not exist" fi fi -tempdir_create -cd $tempdir - -# Check if rootdir contains all we need +# Check if rooturl contains all we need checksums=$(getfile CHECKSUMS.md5) if [ -z "$checksums" ]; then - echo >&2 "$0: CHECKSUMS.md5 not found in $rootdir" - exit 1 + abend "CHECKSUMS.md5 not found in $rooturl" fi announce=$(tail +13 $checksums | \ sed -n -r\ -e 's/^[0-9a-fA-F]+[[:space:]]+\.\/(ANNOUNCE\.[[:digit:]_]+)$/\1/p') if [ -z "$announce" ]; then - echo >&2 "$0: ANNOUNCE not found in $rootdir" - exit 1 + abend "ANNOUNCE not found in $rooturl" fi file=$(getfile $announce) if [ -z "$file" ]; then - echo >&2 "$0: file $announce not found in $rootdir" - exit 1 + abend "file $announce not found in $rooturl" fi newversion=$(echo "$announce" | sed -e 's/ANNOUNCE\.//' -e 's/_/./g') if [ -z "$newversion" ]; then - echo >&2 "$0: cannot determine new version" - exit 1 + abend "cannot determine new version" fi # Create list and index of available files @@ -318,13 +345,11 @@ for series in $series_names do n=$(sed -n -r -e 's/^[0-9a-fA-F]+[[:space:]]+(\.\/slackware(64)?\/l\/.*\.t.z)$/\1/p' $avail_index | head -1) if [ -z "$n" ]; then - echo >&2 "$0: no files in series $series" - exit 1 + abend "no files in series $series" fi file=$(getfile $n) if [ -z "$file" ]; then - echo >&2 "$0: exiting" - exit + abend "exiting" fi dropfile $file done diff --git a/slackware-upgrade-system.8 b/slackware-upgrade-system.8 index 01bc25b..fcbdbda 100644 --- a/slackware-upgrade-system.8 +++ b/slackware-upgrade-system.8 @@ -31,7 +31,11 @@ slackware\-upgrade\-system \- do a full upgrade of a Slackware installation Upgrades the Slackware installation to a new release. The \fIURL\fR argument supplies the URL of the Slackware distribution or the directory on the local filesystem where it can be found. If not -given, \fB/root/slackware\fR is assumed. +given, the program will use the nearest next version distribution +from +.nh +.BR https://mirrors.slackware.com . +.hy .PP When started, the program first verifies that it runs with root privileges on a Slackware installation and determines the current |