aboutsummaryrefslogtreecommitdiff
path: root/slackware-upgrade-system
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2019-09-14 21:46:40 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2019-09-14 21:46:40 +0200
commitd3e2ccb0118b9c878efad9b45c19c4869f986133 (patch)
tree5f7c8aef38ac5ba6786e6eff52e056008be6f0e1 /slackware-upgrade-system
parent5d6f0ade42657c55502cb150e5f957f1207ea1df (diff)
downloadslackupgrade-d3e2ccb0118b9c878efad9b45c19c4869f986133.tar.gz
slackupgrade-d3e2ccb0118b9c878efad9b45c19c4869f986133.tar.bz2
Implement downloads from remote repositories
Diffstat (limited to 'slackware-upgrade-system')
-rw-r--r--slackware-upgrade-system292
1 files changed, 180 insertions, 112 deletions
diff --git a/slackware-upgrade-system b/slackware-upgrade-system
index 3509a9c..bc55bca 100644
--- a/slackware-upgrade-system
+++ b/slackware-upgrade-system
@@ -35,12 +35,30 @@ install_all=
install_series=
# Name of the keep-list file.
keep_file=
+# Verify GPG signatures
+verify=
# Internal variables
+remote=
tempdir=${TMP:-/tmp}/slackupg.$$
installed_list=$tempdir/installed.list
avail_index=$tempdir/avail.index
avail_list=$tempdir/avail.list
+series_names="a
+ap
+d
+e
+f
+k
+l
+n
+t
+tcl
+x
+xap
+xfce
+y
+"
function tempdir_create() {
u=$(umask)
@@ -94,16 +112,6 @@ function getyn() {
fi
}
-function upgrade_package() {
- if [ -n "$dry_run" ]; then
- echo "upgradepkg $@"
- elif [ "$verbosity" = 'v' ]; then
- upgradepkg "$@" | tee -a $logfile | sed -n -e '/^| Upgrading/s/^| //p'
- else
- upgradepkg "$@" >> $logfile
- fi
-}
-
function package_file_name() {
pkg=$(awk -vname=$1 '$1==name { print $2 }' $avail_index)
if [ -z "$pkg" ]; then
@@ -114,12 +122,76 @@ function package_file_name() {
fi
}
-function all_package_files() {
- cut -d ' ' -f 2 $avail_index | grep -v '.*/kde[^/]*/'
+function all_package_names() {
+ grep -v '.*/kde[^/]*/' $avail_index | cut -d ' ' -f 1
+}
+
+function series_package_names() {
+ grep '.*/'"$1/" $avail_index | cut -d ' ' -f 1
}
-function series_package_files() {
- cut -d ' ' -f 2 $avail_index | grep '.*/'"$1/"
+function catfile() {
+ echo $rootdir/${1#./}
+}
+
+function download_curl {
+ curl -sS -o$1 $2
+}
+
+function download_wget {
+ if ! wget --no-check-certificate -nv -o wget.log -O$1 $2; then
+ grep -i "failed\|error" wget.log
+ /bin/false
+ fi
+}
+
+function download() {
+ local name=$(basename $1)
+ local url=$(catfile $1)
+ if $dnfunc $name $url; then
+ if [ -n "$verify" ]; then
+ if $dnfunc $name.asc $url.asc \
+ && ${GPG:-gpg2} --verify $name.asc $name 2>/dev/null; then
+ :
+ else
+ echo >&2 "$0: gpg verification failed for $name"
+ return
+ fi
+ fi
+ fi
+ echo $name
+}
+
+function getfile() {
+ if [ -n "$remote" ]; then
+ download $1
+ else
+ catfile $1
+ fi
+}
+
+function dropfile() {
+ if [ -n "$remote" ]; then
+ rm $1
+ fi
+}
+
+function upgrade_package() {
+ local name=$1
+ shift
+ if [ -n "$dry_run" ]; then
+ echo "upgradepkg $@ $name"
+ else
+ file=$(getfile $name)
+ if [ -n "$file" ]; then
+ if [ "$verbosity" = 'v' ]; then
+ upgradepkg "$@" $file | tee -a $logfile | sed -n -e '/^| Upgrading/s/^| //p'
+ else
+ upgradepkg "$@" $file >> $logfile
+ fi
+ dropfile $file
+ fi
+ fi
}
while getopts "ahknq:s:vy" OPTION
@@ -173,100 +245,110 @@ case "$(uname -m)" in
exit
esac
-# Check if rootdir exists and contains the necessary files and directories
-if [ ! -d $rootdir ]; then
- echo >&2 "$0: $rootdir does not exist"
- exit 1
-fi
+# Check if rootdir is local or remote
+case $rootdir 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
+ remote=1
+ ;;
+ *) echo >&2 "$0: root directory must be absolute file name or URL"
+ exit 1
+esac
-newversion=$(ls $rootdir/ANNOUNCE.* |\
- sed -e 's|.*/||' -e 's/ANNOUNCE\.//' -e 's/_/./g')
-if [ -z "$newversion" ]; then
- echo >&2 "$0: cannot determine new version"
- exit 1
+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
+ fi
fi
-logstem=/var/log/slackware-upgrade-system-$VERSION-$newversion
-logfile=$logstem.log
-
-# Check if pkgdir exists and contains the necessary files and directories
-pkgdir=$rootdir/slackware$ARCH
+tempdir_create
+cd $tempdir
-if [ ! -d $pkgdir ]; then
- echo >&2 "$0: $pkgdir does not exist"
+# Check if rootdir contains all we need
+checksums=$(getfile CHECKSUMS.md5)
+if [ -z "$checksums" ]; then
+ echo >&2 "$0: CHECKSUMS.md5 not found in $rootdir"
exit 1
fi
-tempdir_create
-
-tmplist=$tempdir/$$
-cat > $tmplist <<EOF
-CHECKSUMS.md5
-CHECKSUMS.md5.asc
-FILE_LIST
-MANIFEST.bz2
-EOF
+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
+fi
+file=$(getfile $announce)
+if [ -z "$file" ]; then
+ echo >&2 "$0: file $announce not found in $rootdir"
+ exit 1
+fi
-missing=$(find $pkgdir -depth -mindepth 1 -maxdepth 1 \
- -type f -printf '%f\n' | \
- sort | \
- comm -1 -3 - $tmplist)
-rm $tmplist
-if [ -n "$missing" ]; then
- echo >&2 "$0: The following required files are missing in $pkgdir:"
- echo >&2 "$missing"
- tempdir_remove
+newversion=$(echo "$announce" | sed -e 's/ANNOUNCE\.//' -e 's/_/./g')
+if [ -z "$newversion" ]; then
+ echo >&2 "$0: cannot determine new version"
exit 1
fi
-cat > $tmplist <<EOF
-a
-ap
-d
-e
-f
-k
-l
-n
-t
-tcl
-x
-xap
-xfce
-y
-EOF
+# Create list and index of available files
+tail +13 $checksums | \
+ sed -r \
+ -n \
+ -e 's/^[0-9a-fA-F]+[[:space:]]+(\.\/slackware(64)?\/.*\/(.*)-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+(_.*)?\.t.z)$/\3 \1/p' | \
+ tee $avail_index | awk '{print $1}' | sort > $avail_list
-missing=$(find $pkgdir -depth -mindepth 1 -maxdepth 1 \
- -type d -printf '%f\n' | \
- sort | \
- comm -1 -3 - $tmplist)
-rm $tmplist
-if [ -n "$missing" ]; then
- echo >&2 "$0: The following required directories are missing in $pkgdir:"
- echo >&2 "$missing"
- tempdir_remove
- exit 1
-fi
+# Initialize log file name
+logstem=/var/log/slackware-upgrade-system-$VERSION-$newversion
+logfile=$logstem.log
-# Prepare a list of packages that should be removed after install
-candidates=
-remove_list=$logstem.removed
+# Check if pkgdir exists and contains the necessary files and directories
+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
+ fi
+ file=$(getfile $n)
+ if [ -z "$file" ]; then
+ echo >&2 "$0: exiting"
+ exit
+ fi
+ dropfile $file
+done
+# Build a list of installed packages
ls /var/log/packages |\
sed -r -e 's/-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+(_.*)?//' |\
sort > $installed_list
-find $pkgdir \
- -depth \
- -mindepth 2 -maxdepth 2 \
- -type f \
- -name '*.t?z' | \
- grep -v '/kde*/' | \
- sed -r \
- -e 's/^(.*\/)?(.*)-[^-]+-(i386|x86(_64)?|arm|noarch|fw)-[[:digit:]]+((_.*)?\.t.z)?/\2 &/' | \
- sort | tee $avail_index | awk '{print $1}' > $avail_list
+# Build a list of packages to install
+(if [ -n "$install_all" ]; then
+ all_package_names
+else
+ comm -1 -2 $installed_list $avail_list
+fi
+for s in $install_series
+do
+ series_package_names $s
+done) | sort -u > candidates
-comm -2 -3 $installed_list $avail_list > $remove_list.$$
+# Build a list of packages that should be removed after install
+remove_list=$logstem.removed
+
+comm -2 -3 $installed_list candidates > $remove_list.$$
if [ -s "$keep_file" ]; then
grep -v '^#' $keep_file | \
tr -s '\n' | sort | comm -2 -3 $remove_list.$$ - > $remove_list
@@ -275,10 +357,6 @@ else
mv $remove_list.$$ $remove_list
fi
-if [ -z "$install_all" ]; then
- candidates=$(comm -1 -2 $installed_list $avail_list)
-fi
-
# Disable interrupts during critical section
trap '' HUP INT QUIT ABRT
@@ -298,8 +376,6 @@ if ! getyn n "Ready for upgrade from $VERSION to $newversion. Continue"; then
exit 0
fi
-cd $pkgdir
-
# Upgrade the glibc shared libraries.
echo "$0: Upgrading shared libraries"
upgrade_package $(package_file_name glibc-solibs)
@@ -312,28 +388,20 @@ do
done
# Upgrade the rest of packages
-if [ -n "$candidates" ]; then
- for name in $candidates
- do
- package_file_name $name
- done
- for s in $install_series
- do
- series_package_files $s
- done
-else
- all_package_files
-fi | \
- sort -u | \
- while read pkg
- do
+egrep -v '^(glibc-solibs|pkgtools|tar|xz|findutils)$' candidates |\
+while read name
+do
+ package_file_name $name
+done | sort -u | \
+while read pkg
+do
s=$(basename ${pkg%/*})
if [ "$prev" != "$s" ]; then
echo "$0: installing selected files from series $s"
prev=$s
fi
- upgrade_package --install-new $pkg
- done
+ upgrade_package $pkg --install-new
+done
if [ -s $remove_list ]; then
echo "$0: removing packages"

Return to:

Send suggestions and report system problems to the System administrator.