#!/bin/bash # # $Id: create_liveslak_iso.sh,v 1.20 2022/07/24 14:21:09 eha Exp eha $ # # Create Slackware Live ISO from a local mirror. # # Examples of use: # + A crontab entry which checks for updates every night at 06:00, and # creates a new Slackware Live ISO (if updates were found): # 00 6 * * * /usr/local/bin/create_liveslak_iso.sh # + Do not let this script run in parallel with the mirror-slackware-current # script. In cron, schedule this script immediately after the mirror script # so that you know that the local mirror is up to date. # # =========================================================================== # # - Check the local mirror if the ChangeLog.txt is newer than our available # ISO image. # - If older, then no further actions are needed (abort script) # - If ChangeLog.txt has changed since our last ISO, do the following: # * create ISO for the Slackware Live Edition. # # Author: Eric Hameleers # # =========================================================================== # Read configuration file if it exists; # - usually called 'create_liveslak_iso.conf' CONFFILE=${CONFFILE:-"$(dirname $0)/$(basename $0 .sh).conf"} [ -f ${CONFFILE} ] && . ${CONFFILE} DATE=$(date +"%d_%b_%Y") # Try not to be verbose by default: DEBUG=0 # Where is the local mirror? The Slackware directory tree # will be stored as ${SLACKROOTDIR}/${SLACKRELEASE} # This value can be overruled via the '-l' commandline parameter; SLACKROOTDIR=${SLACKROOTDIR:-"/mirrors/slackware"} # Below which root directory will we create directories for Live ISOs? ISOROOTDIR=${ISOROOTDIR:-/mirrors/slackware-live} # Architecture can be 'x86_64' meaning 64bit or 'x86' for 32bit. # The value of ARCH determines the name of the slackware directories. # This value can be overruled via the '-a' commandline parameter; ARCH=${ARCH:-"x86_64"} # The slackware release we're mirroring (defaults to 'current'). # You can use the script's '-r' switch to alter this to another release, # for instance mirror Slackware 13.37 by passing '-r 13.37' to the script. RELEASE=${RELEASE:-"current"} # Normally, when no update is found in the ChangeLog.txt, the script exits # without creating ISO images. If you want ISO images nonetheless, set # the variable FORCE to "yes" (or pass the '-f' switch to the script). FORCE=${FORCE:-"no"} # Where we will write temporary files (like the downloaded ChangeLog.txt): TMP=${TMP:-/tmp} # We prevent this script from running more than one instance: # If you have a reason to want to run multiple instances at the same time, just # make a symlink to this script and run the script using the symlinked name. # This will create a unique PIDFILE name. PIDFILE=/var/tmp/$(basename $0 .sh).pid # Location of the original script: ORIGSCR="http://www.slackware.com/~alien/tools/create_liveslak_iso.sh" # URI of the liveslak repository: GITURI=${GITURI:-"git://slackware.nl/liveslak.git"} # The name of the public log file: PUBLOG="liveslak.log" # Can we use xorriso to generate the ISO? USEX=$(which xorriso 1>/dev/null 2>/dev/null && echo "-X" || echo "") # Should we only check for an update but not generate the ISO (default: no) ONLYDIFF=0 # Make sure the PID file is removed when we kill the process trap 'rm -f $PIDFILE; exit 1' TERM INT while getopts "a:cefhi:l:npqr:v" Option do case $Option in h ) cat <<-"EOH" ----------------------------------------------------------------- $Id: create_liveslak_iso.sh,v 1.20 2022/07/24 14:21:09 eha Exp eha $ ----------------------------------------------------------------- EOH echo "Usage:" echo " $0 [OPTION] ..." echo "or:" echo " SLACKROOTDIR=/your/repository/dir $0 [OPTION] ..." echo "" echo "The SLACKROOTDIR is the directory that contains the directories" echo " slackware- and slackware--iso" echo "Current value of SLACKROOTDIR : $SLACKROOTDIR" echo "" echo "You can change the script defaults in a file '$(basename $0 .sh).conf'" echo "" echo "The script's parameters are:" echo " -h This help." echo " -a Architecture to mirror (defaults to 'x86'," echo " can be 'x86_64' too)." echo " -c Check for newer version of this script." echo " -e Use 'boot-load-size=32' instead of the value 4." echo " (32 is a more standard value, but a value of 4" echo " will let the ISO boot with old 'broken' BIOSes)." echo " -f Force the creation of new ISO image, even if" echo " no update of the ChangeLog.txt was found." echo " This is how you resume after an aborted attempt." echo " -i The directory where you store the ISO file." echo " -l The root directory where you keep your local" echo " Slackware mirror; this directory contains" echo " slackware- or slackware64-" echo " -n Only show the changes in the ChangeLog.txt" echo " but don't sync anything and don't generate ISOs." echo " -p Remove old ISO's before building the new ones" echo " (in case you're suffering from low free space)." echo " -r The release ('current' by default); use '-r 12.2'" echo " if you want to mirror and image slackware 12.2" echo " -q Non-verbose output (for cron jobs)." echo " -v Verbose progress indications." exit ;; a ) ARCH=${OPTARG} ;; c ) CHECKVER="yes" ;; e ) BOOTLOADSIZE=32 ;; f ) FORCE="yes" ;; i ) ISODIR=${OPTARG} ;; l ) SLACKROOTDIR=${OPTARG} ;; n ) ONLYDIFF=1 ;; p ) PREREMOVE=1 ;; q ) # No output at all if we are already in sync DEBUG=0 ;; r ) RELEASE=${OPTARG} ;; v ) echo "Enabling verbose output...." DEBUG=1 ;; * ) echo "You passed an illegal switch to the program!" echo "Run '$0 -h' for more help." exit ;; # DEFAULT esac done # End of option parsing. shift $(($OPTIND - 1)) # $1 now references the first non option item supplied on the command line # if one exists. # --------------------------------------------------------------------------- if [ "$ARCH" = "x86_64" ]; then SLACKRELEASE="slackware64-${RELEASE}" PKGMAIN="slackware64" else SLACKRELEASE="slackware-${RELEASE}" PKGMAIN="slackware" fi # Define the location where the Live ISOs will be placed: ISODIR=${ISOROOTDIR}/${SLACKRELEASE}-live if [ ! -d ${SLACKROOTDIR}/${SLACKRELEASE} ]; then echo "$(date) [$$]: Cannot find '${SLACKRELEASE}' directory:" echo " (${SLACKROOTDIR}/${SLACKRELEASE})!" echo " Aborting now..." exit 1 fi if [ ! -d ${ISODIR} ]; then if ! mkdir -p ${ISODIR} ; then echo "$(date) [$$]: Failure in creating '${ISODIR}' output directory!" echo " Aborting now..." exit 1 fi fi # Check for an updated version of this script: if [ "$CHECKVER" == "yes" ]; then if [ $DEBUG -eq 1 ]; then echo "#" echo "# Checking version of '${ORIGSCR}' ..." echo "#" fi CVRS=$(cat ${0} | grep ' ' | head -1 | \ sed -e 's/^.*Id: create_liveslak_iso.sh,v \([0-9.]*\) .*$/\1/') NVRS=$(wget -T 10 -q -O - ${ORIGSCR} | grep ' ' | \ head -1 | \ sed -e 's/^.*Id: create_liveslak_iso.sh,v \([0-9.]*\) .*$/\1/') if [ -z "$CVRS" -o -z "$NVRS" ]; then echo "# Cannot compare version against the script's original;" echo "# Your script version reports '$CVRS', the original reports '$NVRS'" if [ -z "$NVRS" ]; then echo "# Possible cause is a failure to retrieve the remote script:" echo "# '${ORIGSCR}'." fi elif [ "$CVRS" != "$NVRS" ]; then echo "# Your version of this script is '$CVRS', while version '$NVRS' is reported" echo "# by remote '${ORIGSCR}'" elif [ "$CVRS" == "$NVRS" -a $DEBUG -eq 1 ]; then echo "# You have the most recent version of this script" fi fi # --------------------------------------------------------------------------- if [ -e $PIDFILE ]; then echo "Another instance ($(cat $PIDFILE)) still running?" echo "If you are sure that no other instance is running, delete the lockfile" echo "'${PIDFILE}' and re-start this script." echo "Aborting now..." exit 1 else echo $$ > $PIDFILE umask 022 # First get the ChangeLog.txt (no further action needed, # when there are no changes in this file) if [ $DEBUG == 1 ]; then echo "$(date) [$$]: Comparing ChangeLog.txt..." fi # Find the latest Slackware $RELEASE update: RELMARKER="$(echo ${RELEASE^^} |tr -d '.-')" LATEST_ADD=$(head -n 40 ${SLACKROOTDIR}/${SLACKRELEASE}/ChangeLog.txt|grep -Ei "^(mon|tue|wed|thu|fri|sat|sun)"|head -n 1) echo ${LATEST_ADD} > ${TMP}/LATEST_ADDITION_TO_${RELMARKER}_$$ # If ${ISODIR}/LATEST_ADDITION_TO_${RELMARKER} doesn't exist, it might mean # that this is a first-time run. To prevent the script from aborting, # we create an empty file... if [ ! -e ${ISODIR}/LATEST_ADDITION_TO_${RELMARKER} ]; then touch ${ISODIR}/LATEST_ADDITION_TO_${RELMARKER} fi diff -b ${ISODIR}/LATEST_ADDITION_TO_${RELMARKER} ${TMP}/LATEST_ADDITION_TO_${RELMARKER}_$$ STATUS="$?" if [ "$STATUS" == "2" ]; then echo "$(date) [$$]: Trouble when running diff, aborting..." rm -f ${TMP}/LATEST_ADDITION_TO_${RELMARKER}_$$ rm -f $PIDFILE exit 1 elif [ "$STATUS" == 0 ]; then [ $DEBUG == 1 ] && echo -n "$(date) [$$]: No difference found" if [ $FORCE == "yes" ]; then # we will continue as requested [ $DEBUG == 1 ] && echo ", continuing anyway..." else # quit the script now. [ $DEBUG == 1 ] && echo ", exiting now...." rm -f ${TMP}/LATEST_ADDITION_TO_${RELMARKER}_$$ rm -f $PIDFILE exit 0 fi else echo -n "$(date) [$$]: ChangeLog.txt has been updated" if [ $ONLYDIFF -eq 1 ]; then # quit the script now. echo ", that's all you wanted to know...." rm -f ${TMP}/LATEST_ADDITION_TO_${RELMARKER}_$$ rm -f $PIDFILE exit 0 else # we will continue. echo ", starting the creation of Slackware Live Edition ISO." fi fi # Delete the previous ISO before creating the new ISO: rm -f ${ISODIR}/${PKGMAIN}-live-${RELEASE}.iso* 2>/dev/null # Write the README for prospective users of the ISO: cat < ${ISODIR}/README Things to remember when you boot the ISO: ========================================= Slackware Live does not log you on automatically! This is a demonstration environment, with the purpose of getting you acquainted with Slackware, remember? Therefore you will first see all these intimidating kernel messages scrolling across the screen while booting the OS. Then you need to login manually. The Slackware Live Edition comes with two user accounts: user "root" (with password "root") and user "live" (with password "live"). My advice is to login as user live and use "su" or "sudo" to get root access. Note: the "sudo" command will ask for the "live" user's password! Consult the documentation at: http://docs.slackware.com/slackware:liveslak#boot_parameters_explained for assistance with the various boot parameters you can use to tailor the Live OS to your needs. The syslinux boot has help screens behind the F2, F3, F4 and F5 function keys and the grub boot screen has a "help on boot parameters" menu entry. EOF rm -f ${ISODIR}/HEADER.txt ln -s README ${ISODIR}/HEADER.txt # Generate the new ISO: cd ${TMP} echo "Slackware ${RELEASE} ChangeLog.txt updated: ${LATEST_ADD}" > ${ISODIR}/${PUBLOG} echo "+--------------------------+" >> ${ISODIR}/${PUBLOG} sed -n '1,/+--------------------------+/p' "${SLACKROOTDIR}/${SLACKRELEASE}/ChangeLog.txt" >> ${ISODIR}/${PUBLOG} echo "Creating new ISO for Slackware Live Edition" >> ${ISODIR}/${PUBLOG} echo "Cloning liveslak scripts from ${GITURI}" >>${ISODIR}/${PUBLOG} git clone ${GITURI} liveslak_alientemp_$$ echo "Using liveslak $(grep ^VERSION /tmp/liveslak_alientemp_$$/make_slackware_live.sh)" >>${ISODIR}/${PUBLOG} echo "Executing 'make_slackware_live.sh -f $USEX -d SLACKWARE -a $ARCH -z $RELEASE'" >>${ISODIR}/${PUBLOG} echo "[$(date -u +%Y%m%d_%H%M) UTC] Starting..." >>${ISODIR}/${PUBLOG} echo >> ${ISODIR}/${PUBLOG} cd liveslak_alientemp_$$ OUTPUT=${ISODIR} \ LIVE_STAGING=${TMP}/slackwarelive_staging_$$ \ LIVE_ROOTDIR=/mnt/slackwarelive_mount_$$ \ SL_REPO=${SLACKROOTDIR} \ BUILDER="$(hostname) autobuilder" \ ./make_slackware_live.sh -f $USEX -d SLACKWARE -a $ARCH -z $RELEASE \ 2>&1 | tee -a ${ISODIR}/${PUBLOG} MKISOERR=$? if [ $MKISOERR -ne 0 ]; then tail -10 ${ISODIR}/${PUBLOG} | \ sed -e 's/^/! /' fi echo "[$(date -u +%Y%m%d_%H%M) UTC] Finshed." >>${ISODIR}/${PUBLOG} echo "$(date) [$$]: Live ISO created (exit code ${MKISOERR}) ..." # Log the latest slackware-current update for the next check: LATEST_ADD=$(head -n 40 ${SLACKROOTDIR}/${SLACKRELEASE}/ChangeLog.txt|grep -Ei "^(mon|tue|wed|thu|fri|sat|sun)"|head -n 1) echo ${LATEST_ADD} > ${ISODIR}/LATEST_ADDITION_TO_${RELMARKER} echo "$(date) [$$]: Resulting ISO files:" ls -l ${ISODIR}/${PKGMAIN}-live-${RELEASE}.iso echo "$(date) [$$]: Done!" # Cleanup: rm -rf ${TMP}/liveslak_alientemp_$$ rm -rf ${TMP}/slackwarelive_staging_$$ rmdir /mnt/slackwarelive_mount_$$ 2>/dev/null rm -f ${TMP}/LATEST_ADDITION_TO_${RELMARKER}_$$ rm -f $PIDFILE fi