aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2020-02-07 11:53:08 +0100
committerSergey Poznyakoff <gray@gnu.org.ua>2020-02-07 11:58:31 +0100
commit507ae64c3e886b82435cbc963594ed5e2af3458f (patch)
tree873b009acbc94db6fd34c291fcb62603c709285a
parent06031d3add92479fce6b02971a23ad5931ee26dd (diff)
downloadslackupgrade-507ae64c3e886b82435cbc963594ed5e2af3458f.tar.gz
slackupgrade-507ae64c3e886b82435cbc963594ed5e2af3458f.tar.bz2
Implement the "safe upgrade" mode
In safe upgrade mode, all the necessary package tarballs are first downloaded to the spool directory. Once downloaded, the program starts upgrading using these tarballs. Each tarball is removed after being processed. The old ("incremental") mode is used if there is not enough disk space for full download.
-rw-r--r--slackupgrade288
-rw-r--r--slackupgrade.8158
2 files changed, 353 insertions, 93 deletions
diff --git a/slackupgrade b/slackupgrade
index 662b325..ff4d46f 100644
--- a/slackupgrade
+++ b/slackupgrade
@@ -1,12 +1,12 @@
1#!/bin/bash 1#!/bin/bash
2# slackupgrade - full upgrade of a Slackware installation 2# slackupgrade - full upgrade of a Slackware installation
3# Copyright (C) 2019 Sergey Poznyakoff. 3# Copyright (C) 2019-2020 Sergey Poznyakoff.
4# 4#
5# Slackware-upgrade-system is free software; you can redistribute it and/or 5# Slackware-upgrade-system is free software; you can redistribute it and/or
6# modify it under the terms of the GNU General Public License as published 6# modify it under the terms of the GNU General Public License as published
7# by the Free Software Foundation; either version 3, or (at your option) 7# by the Free Software Foundation; either version 3, or (at your option)
8# any later version. 8# any later version.
9# 9#
10# Slackware-upgrade-system is distributed in the hope that it will be useful, 10# Slackware-upgrade-system is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of 11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@@ -17,12 +17,13 @@
17# <http://www.gnu.org/licenses/>. 17# <http://www.gnu.org/licenses/>.
18 18
19set -e 19set -e
20 20
21# Configuration directory 21# Configuration directory
22: ${SLACKUPGRADE_CONFDIR:=/etc/slackupgrade} 22: ${SLACKUPGRADE_CONFDIR:=/etc/slackupgrade}
23: ${SLACKUPGRADE_PKGDIR:=/var/slackupgrade}
23# Slackware root directory 24# Slackware root directory
24rooturl= 25rooturl=
25# Log file name 26# Log file name
26logfile= 27logfile=
27# 'y', if dry-run mode is requested 28# 'y', if dry-run mode is requested
28dry_run= 29dry_run=
@@ -38,16 +39,31 @@ install_series=
38# Names of additional packages. 39# Names of additional packages.
39install_packages= 40install_packages=
40# Name of the keep-list file. 41# Name of the keep-list file.
41keep_file= 42keep_file=
42# Max. count of backup files to keep 43# Max. count of backup files to keep
43max_backup=4 44max_backup=4
45# Display progress bar when downloading
46progressbar=1
47# Operating mode. Possible values:
48# INCR Incremental mode. Archive for each package is downloaded prior
49# to its nstallation and removed immediately afterwards. This
50# ensures minimal disk space requirements.
51# SAFE Safe mode. All archives are first downloaded to
52# SLACKUPGRADE_PKGDIR and then installed. Each archive is removed
53# immediately after installing from it. This requires some 2.5G
54# of disk space at the beginning, which will be freed by the end
55# of upgrade.
56# AUTO Select incremental mode if there is enough disk space. If not,
57# ask the user if it is OK to proceed in incremental mode.
58opmode=AUTO
44 59
45# Internal variables 60# Internal variables
46remote= 61remote=
47tempdir=${TMP:-/tmp}/slackupg.$$ 62tempdir=${TMP:-/tmp}/slackupg.$$
63strip_series=0
48installed_list=$tempdir/installed.list 64installed_list=$tempdir/installed.list
49avail_index=$tempdir/avail.index 65avail_index=$tempdir/avail.index
50avail_list=$tempdir/avail.list 66avail_list=$tempdir/avail.list
51series_names="a 67series_names="a
52ap 68ap
53d 69d
@@ -129,129 +145,157 @@ function error() {
129 echo >&2 "$0: $*" 145 echo >&2 "$0: $*"
130 if [ -n "$logfile" ]; then 146 if [ -n "$logfile" ]; then
131 echo >>$logfile "$0: $(date): $*" 147 echo >>$logfile "$0: $(date): $*"
132 fi 148 fi
133} 149}
134 150
151# Abnormal termination: print error message, remove temporary directory
152# and terminate with status 1.
135function abend() { 153function abend() {
136 error "$@" 154 error "$@"
137 tempdir_remove 155 tempdir_remove
138 exit 1 156 exit 1
139} 157}
140 158
141function package_file_name() { 159function package_file_name() {
142 pkg=$(awk -vname=$1 '$1==name { print $2 }' $avail_index) 160 pkg=$(awk -vname=$1 '$1==name { print $2 }' $avail_index)
143 if [ -z "$pkg" ]; then 161 if [ -z "$pkg" ]; then
144 error "package $name not found in index (should not happen!)" 162 error "package $name not found in index (should not happen!)"
145 else 163 else
146 echo $pkg 164 echo $pkg
147 fi 165 fi
148}
149
150function package_name_md5sum() {
151 pkg=$(awk -vname=$1 '$1==name { print $3 }' $avail_index)
152} 166}
153 167
168# check_package_md5sum PKG ARCHIVE
169# Verifies the MD5 sum of the ARCHIVE file for Slackware package PKG
154function check_package_md5sum() { 170function check_package_md5sum() {
155 if [ -n "$checksums" ]; then 171 if [ -n "$checksums" ]; then
156 awk -vcname="$1" -vdname="$2" \ 172 awk -vcname="$1" -vdname="$2" \
157 '$2==cname { print $1 " " dname }' $checksums | \ 173 '$2==cname { print $1 " " dname }' $checksums | \
158 md5sum --status --check 174 md5sum --status --check
159 fi 175 fi
160} 176}
161 177
178# all_package_names
179# Lists all packages from the Slackware distribution.
162function all_package_names() { 180function all_package_names() {
163 grep -v '.*/kde[^/]*/' $avail_index | cut -d ' ' -f 1 181 grep -v '.*/kde[^/]*/' $avail_index | cut -d ' ' -f 1
164} 182}
165 183
184# series_package_names S
185# Lists the names of packages in Slackware series S.
166function series_package_names() { 186function series_package_names() {
167 grep '.*/'"$1/" $avail_index | cut -d ' ' -f 1 187 grep '.*/'"$1/" $avail_index | cut -d ' ' -f 1
168} 188}
169 189
170function catfile() { 190function catfile() {
171 echo $rooturl/${1#./} 191 echo $rooturl/${1#./}
172} 192}
173 193
194# download_curl FILE URL
195# Downloads file from URL to FILE using curl.
174function download_curl { 196function download_curl {
175 curl $CURL_OPTIONS -L -sS -o$1 $2 197 curl $CURL_OPTIONS -L -sS -o$1 $2
176} 198}
177 199
200# download_wget LOCAL URL
201# Downloads file from URL to FILE using wget.
178function download_wget { 202function download_wget {
179 if ! wget $WGET_OPTIONS -nv -o wget.log -O$1 $2; then 203 if ! wget $WGET_OPTIONS -nv -o wget.log -O$1 $2; then
180 grep -i "failed\|error" wget.log 204 grep -i "failed\|error" wget.log
181 /bin/false 205 /bin/false
182 fi 206 fi
183} 207}
184 208
209# dnfunc_init
210# Initializes the downloader function to wget or curl.
185function dnfunc_init() { 211function dnfunc_init() {
186 if [ -z "$dnfunc" ]; then 212 if [ -z "$dnfunc" ]; then
187 if wget --version >/dev/null 2>&1; then 213 if wget --version >/dev/null 2>&1; then
188 dnfunc=download_wget 214 dnfunc=download_wget
189 elif curl --version >/dev/null 2>&1; then 215 elif curl --version >/dev/null 2>&1; then
190 dnfunc=download_curl 216 dnfunc=download_curl
191 else 217 else
192 abend "neither curl nor wget is installed" 218 abend "neither curl nor wget is installed"
193 fi 219 fi
194 fi 220 fi
195} 221}
196 222
223# download FILE
224# Downloads package FILE from the remote server. On success, returns the
225# full pathname of the downloaded copy.
197function download() { 226function download() {
198 local name=$(basename $1) 227 local name=$SLACKUPGRADE_PKGDIR/$(basename $1)
199 local url=$(catfile $1) 228 local url=$(catfile $1)
200 if $dnfunc $name $url; then 229 if $dnfunc $name $url; then
201 echo $name 230 echo $name
202 fi 231 fi
203} 232}
204 233
234# getfile PKG [GPG]
235# Retrieves the package archive file for the package PKG. If second argument
236# is non-empty, verifies the GPG signature of the file.
237# If checksums file is available, verifies also the MD5 checksum of the file.
238#
239# Returns full pathname of the retrieved file.
205function getfile() { 240function getfile() {
206 local name=$(if [ -n "$remote" ]; then 241 local name=$(if [ -n "$remote" ]; then
207 download $1 242 download $1
208 else 243 elif [ $strip_series -eq 1 ]; then
209 catfile $1 244 catfile $(basename $1)
210 fi) 245 else
211 246 catfile $1
247 fi)
248
212 if [ -n "$2" ]; then 249 if [ -n "$2" ]; then
213 ascname=$(if [ -n "$remote" ]; then 250 ascname=$(if [ -n "$remote" ]; then
214 download $1.asc 251 download $1.asc
215 else 252 else
216 catfile $1.asc 253