A Tumbleweed ISO file management bash script

I’m used to downloading the DVD ISO once a month for system reinstallation or other maintenance purposes. So I packaged a lot of repetitive operations into a bash script.

I usually download the current ISO, so the script has an extra step to process the sha256 file. The mirror sites listed by default are all in China, you can edit the list according to your needs.

#!/bin/sh
# This script is used to manage openSUSE Tumbleweed ISO files.
#
# Main functions:
# 1. Download DVD/Live ISO files, sha256 files and asc certificate files
# 2. Verify new and old ISO files (calculate hashes, verify GPG signatures)
# 3. Update and replace old ISO files
#
# Note:
# 1. Please read the script in full before use. Use at your own risk.
# 2. Users need to modify the variables that need to be modified.
# 3. Users need to configure the gpg tool themselves.

printf 'Please modify the script before using it for the first time to make it work properly.\n'

export ISO_DIR=$HOME/Downloads/ISO
# Default save location
export ISO_DIR_TMEP=$HOME/Downloads/iso-m-temp
# Default cache location

# Select a mirror site. You can only select one at a time.
export DL_URL=https://mirrors.zju.edu.cn/opensuse
#export DL_URL=http://mirror.bjtu.edu.cn/opensuse
#export DL_URL=https://mirror.nyist.edu.cn/opensuse
#export DL_URL=https://ftp.sjtu.edu.cn/opensuse
#export DL_URL=https://mirrors.163.com/openSUSE
#export DL_URL=https://mirrors.bfsu.edu.cn/opensuse
#export DL_URL=https://mirrors.tuna.tsinghua.edu.cn/opensuse
#export DL_URL=https://mirrors.ustc.edu.cn/opensuse
#export DL_URL=
#export DL_URL=
# By default, mirrors in China are included, which have been added to mirrors.opensuse.org

DVD_NEW=$ISO_DIR_TMEP/openSUSE-Tumbleweed-DVD-x86_64-Current.iso
LIVE_NEW=$ISO_DIR_TMEP/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso
# Check location for new files
DVD_OLD=$ISO_DIR/openSUSE-Tumbleweed-DVD-x86_64-Current.iso
LIVE_OLD=$ISO_DIR/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso
# Check location for old files

while true; do

    printf -- '-%0.s' {1..100} && echo
    printf 'You can use the ISO files maintenance script for:\n\n'
    printf '1 - Download openSUSE DVD ISO files\n'
    printf '2 - Download openSUSE KDE Live ISO files\n'
    printf 'V - Verify New ISO files.\n'
    printf 'C - Check old ISO files.\n'
    printf 'U - Update ISO files\n'
    printf 'R - Clear temp file.\n'
    printf 'Q - End task.\n\n'
    printf '==> '
    read answer

    # Download ISO file
    if [ $answer = 1 ]; then
        if [ -d $ISO_DIR_TMEP ]; then
            printf 'INFO: Find the temp dir.\n'
            cd $ISO_DIR_TMEP
        else
            mkdir -p $ISO_DIR_TMEP
            printf 'INFO: The temp dir created.\n'
            cd $ISO_DIR_TMEP
        fi
        wget -c $DL_URL/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso
        wget -c $DL_URL/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso.sha256
        wget -c $DL_URL/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso.sha256.asc
    elif [ $answer = 2 ]; then
        if [ -d $ISO_DIR_TMEP ]; then
            printf 'INFO: Find the temp dir.\n'
            cd $ISO_DIR_TMEP
        else
            mkdir -p $ISO_DIR_TMEP
            printf 'INFO: The temp dir created.\n'
            cd $ISO_DIR_TMEP
        fi
        wget -c $DL_URL/tumbleweed/iso/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso
        wget -c $DL_URL/tumbleweed/iso/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso.sha256
        wget -c $DL_URL/tumbleweed/iso/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso.sha256.asc

    elif [ "$answer" = "V" ] || [ "$answer" = "v" ]; then
    # Verify the newly downloaded ISO file
        if [ -d $ISO_DIR_TMEP ]; then
            cd $ISO_DIR_TMEP
            if [ -f $DVD_NEW ]; then
                gpg --verify openSUSE-Tumbleweed-DVD-x86_64-Current.iso.sha256.asc
                cat openSUSE-Tumbleweed-DVD-x86_64-Current.iso.sha256 | sed 's/openSUSE-Tumbleweed-DVD-x86_64-Snapshot\(........\)-Media.iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso/' > temp.sha256
                sha256sum -c temp.sha256
                rm temp.sha256
            else
                printf 'ERROR: No found new DVD ISO files!\n'
            fi
            printf -- '-%0.s' {1..100} && echo
            if [ -f $LIVE_NEW ]; then
                gpg --verify openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso.sha256.asc
                cat openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso.sha256 | sed 's/openSUSE-Tumbleweed-KDE-Live-x86_64-Snapshot\(........\)-Media.iso/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso/' > temp.sha256
                sha256sum -c temp.sha256
                rm temp.sha256
            else
                printf 'ERROR: No found new Live ISO files!\n'
            fi
        else
            printf 'ERROR: No found the temp dir!\n'
        fi


    elif [ "$answer" = "C" ] || [ "$answer" = "c" ]; then
    # Verify the old ISO file
        if [ -d $ISO_DIR ]; then
            cd $ISO_DIR
            if [ -f $DVD_OLD ]; then
                gpg --verify openSUSE-Tumbleweed-DVD-x86_64-Current.iso.sha256.asc
                cat openSUSE-Tumbleweed-DVD-x86_64-Current.iso.sha256 | sed 's/openSUSE-Tumbleweed-DVD-x86_64-Snapshot\(........\)-Media.iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso/' > temp.sha256
                sha256sum -c temp.sha256
                rm temp.sha256
            else
                printf 'ERROR: No found old DVD ISO files!\n'
            fi
            printf -- '-%0.s' {1..100} && echo
            if [ -f $LIVE_OLD ]; then
                gpg --verify openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso.sha256.asc
                cat openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso.sha256 | sed 's/openSUSE-Tumbleweed-KDE-Live-x86_64-Snapshot\(........\)-Media.iso/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso/' > temp.sha256
                sha256sum -c temp.sha256
                rm temp.sha256
            else
                printf 'ERROR: No found old Live ISO files!\n'
            fi
        else
            printf 'ERROR: No found the ISO dir!\n'
        fi

    elif [ "$answer" = "U" ] || [ "$answer" = "u" ]; then
    # Update ISO file
        if [ -d $ISO_DIR_TMEP ]; then
            if [ -f $DVD_NEW ]; then
                printf 'Found the new DVD ISO files: OK!\n'
                if [ -f $DVD_OLD ]; then
                    rm $ISO_DIR/openSUSE-Tumbleweed-DVD*.*
                    printf 'Delete the old DVD ISO files: OK!\n'
                else
                    printf 'ERROR: No found the old DVD ISO files!\n'
                fi
                mv $ISO_DIR_TMEP/openSUSE-Tumbleweed-DVD*.* $ISO_DIR
                printf 'Update the DVD ISO files: OK!\n'
            else
                printf 'ERROR: No found the new DVD ISO files!\n'
            fi
            if [ -f $LIVE_NEW ]; then
                printf 'Found the new Live ISO files: OK!\n'
                if [ -f $LIVE_OLD ]; then
                    rm $ISO_DIR_TMEP/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.*
                    printf 'Delete the old Live ISO files: OK!\n'
                else
                    printf 'ERROR: No found the old Live ISO files!\n'
                fi
                mv $ISO_DIR_TMEP/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.* $ISO_DIR
                printf 'Update the Live ISO files: OK!\n'
            else
                printf 'ERROR: No found the new Live ISO files!\n'
            fi
        else
            printf 'ERROR: No found the temp dir!\n'
        fi

    elif [ "$answer" = "R" ] || [ "$answer" = "r" ]; then
    # Manually delete the cache folder
        if [ -d $ISO_DIR_TMEP ]; then
            rm -rf $ISO_DIR_TMEP
            printf 'Delete the temp dir: OK!\n'
        else
            printf 'ERROR: NO found the temp dir!'
        fi

    elif [ "$answer" = "Q" ] || [ "$answer" = "q" ]; then
        if [ -d "$ISO_DIR_TMEP" ]; then
            if [ "$(ls -A $ISO_DIR_TMEP)" ]; then
                printf "INFO: the temp dir isn't empty.\n"
            else
                rm -rf $ISO_DIR_TMEP
                printf "INFO: Deleted empty temp dir.\n"
            fi
        else
            printf 'INFO: No found the temp dir.\n'
        fi
        exit

    else
        printf 'ERROR: Invalid input!\n'
        continue

    fi
done

WOW! heres mine, it automatically picks links out of the download pages.

#!/bin/bash

while getopts "hf:" flag; do
 case $flag in
   h) # Handle the -h flag
   # Display script help information
   ;;
   d) # debug mode
   SIMULATE=TRUE
   ;;
   \?)
   ;;
 esac
done


function downloadFileAs() {
  if [ SIMULATE == "TRUE" ] then
    wget $1 -NO $2
  else
    echo $1 with name $2
  fi

  
}


mkdir openSUSE
mkdir openSUSE/Leap
mkdir openSUSE/Tumbleweed



leapfirsthalf='https://download.opensuse.org/distribution/openSUSE-current/iso'
wget "$leapfirsthalf" -O 'leapscan.html'
LEAPLOAD=`grep -oP '\.\/openSUSE-Leap-[0-z][0-z]\.[0-z]-DVD-x86_64-Current\.iso">' leapscan.html`
LEAPLOAD="${LEAPLOAD:1}"
LEAPLOAD="${LEAPLOAD::-2}"
rm 'leapscan.html'
downloadFileAs "$leapfirsthalf$LEAPLOAD" 'openSUSE/Leap/X86_64-leap-current.iso'

downloadFileAs 'https://download.opensuse.org/tumbleweed/iso/openSUSE-Tumbleweed-DVD-x86_64-Current.iso' 'openSUSE/Tumbleweed/X86_64-openSUSE_tumbleweed.iso'
downloadFileAs 'https://download.opensuse.org/tumbleweed/iso/openSUSE-Tumbleweed-Rescue-CD-x86_64-Current.iso' 'openSUSE/Tumbleweed/X86_64-openSUSE_tumbleweed-RESCUE.iso'
downloadFileAs 'https://download.opensuse.org/tumbleweed/iso/openSUSE-Tumbleweed-KDE-Live-x86_64-Current.iso' 'openSUSE/Tumbleweed/X86_64-openSUSE_tumbleweed-live(KDE).iso'


mkdir kolibri
downloadFileAs 'https://builds.kolibrios.org/rus/kolibri.iso' 'kolibri/kolibriOS-ru.iso'
downloadFileAs 'https://builds.kolibrios.org/eng/kolibri.iso' 'kolibri/kolibriOS-en.iso'


downloadFileAs 'http://www.tinycorelinux.net/14.x/x86/release/CorePlus-current.iso' 'X86-tinyCORE_linux.iso'


wget 'https://www.kali.org/get-kali/#kali-live' -O 'kaliscan.html'
KALILOAD=`grep -oP 'https:\/\/cdimage\.kali\.org\/kali-[0-z][0-z][0-z][0-z]\.[0-z]\/kali-linux-[0-z][0-z][0-z][0-z]\.[0-z]-live-amd64\.iso\>' kaliscan.html`
KALILOAD="${KALILOAD::-1}"
rm 'kaliscan.html'
downloadFileAs "$KALILOAD" 'X86_64-kali-live.iso'
1 Like