#!/bin/bash # This script was initially based on the information documented on the following sites: # https://help.ubuntu.com/community/LiveCDCustomization (shared under a Creative Commons Attribution-ShareAlike 3.0 License available at https://help.ubuntu.com/community/License) # https://wiki.ubuntu.com/KernelTeam/GitKernelBuild (shared under a Creative Commons Attribution-ShareAlike 3.0 License available at https://help.ubuntu.com/community/License) # and then further developed by Linuxium (linuxium@linuxium.com.au). # Version 1: This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. # Version 2.01.050417: This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 License. # Version 3.01.120417: This work is licensed under GNU GPL version 3 under one-way compatibility with CC BY-SA 4.0. # Version 3.02.130417, 4.06.220417 to 4.09.280417, 5.01.020517, 6.01.120517, 6.02.0 to 6.03.3, 7.1.0 to 7.3.5.1, 7.3.6, 8.0.0 to 8.2.6: This work is licensed under GNU GPL version 3. # Version 8.2.7: This work is licensed under GNU GPL version 3. # # Linuxium's script to respin an Ubuntu (or Ubuntu flavour), Linux Mint, neon, elementary, BackBox or Peppermint desktop ISO and optionally add/remove functionality like # kernels/repositories/packages/files/boot parameters etc., run pre- and post commands, output files and directories, include boot loader/manager support for Intel Atom/Apollo # devices and add support for 32-bit boot loaders together with template configuration files. # Copyright (C) 2019 Ian W. Morrison (linuxium@linuxium.com.au). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . VERSION="8.3.0" # Update xorriso cmd in line with Linux Mint (GPD version) and fix work_directory bug with GUI MAINLINE_URL="http://kernel.ubuntu.com/~kernel-ppa/mainline" KERNEL_TYPE="generic" SUPPORTED_OS=("Ubuntu" "Kubuntu" "Lubuntu" "Lubuntu-Next" "Ubuntu-Budgie" "Ubuntu-GNOME" "Ubuntu-MATE" "Xubuntu" "Mint" "neon" "elementary" "BackBox" "Peppermint" "Ubuntu-Studio") LONG_FLAGS=("help" "version" "update" "kernel" "repository" "erase" "package" "local-package" "download" "file" "boot" "storage" "iso" "work-directory" "command" "output" "grub" "key" "upgrade" "template") PROCESSORS=("apollo" "atom") ROLLING_POSSIBILITIES=("rolling-release" "rolling-release-hwe" "rolling-release-hwe-edge" "rolling-proposed" "rolling-proposed-hwe" "rolling-proposed-hwe-edge" "rolling-testing" "rolling-testing-hwe" "rolling-testing-hwe-edge" "rolling-unstable" "rolling-unstable-hwe" "rolling-unstable-hwe-edge") ROLLING_LIST=("rolling-list") CHECK_VERSION=("check") IS_A_LONG_FLAG=("${LONG_FLAGS[@]}" "${PROCESSORS[@]}" "${ROLLING_POSSIBILITIES[@]}" "${ROLLING_LIST[@]}" "${CHECK_VERSION[@]}") NEEDS_AN_ARGUMENT=("k" "r" "e" "p" "l" "d" "f" "b" "s" "i" "w" "c" "o" "g") # Based on /usr/share/distro-info/ubuntu.csv RELEASE_CODENAME=("trusty" "utopic" "vivid" "wily" "xenial" "yakkety" "zesty" "artful" "bionic" "cosmic") RELEASE_VERSION=("14.04" "14.10" "15.04" "15.10" "16.04" "16.10" "17.04" "17.10" "18.04" "18.10" "19.04" "19.10") trap 'FORCED_EXIT' SIGHUP SIGINT SIGTERM function UMOUNT { MOUNT_POINT=$1 if $(sudo fuser -mM ${MOUNT_POINT} > /dev/null 2>&1); then sleep 10 fi sudo sync && sudo sync && sudo umount ${MOUNT_POINT} > /dev/null 2>&1 || sudo sync && sudo sync && sudo umount -lf ${MOUNT_POINT} > /dev/null 2>&1 if $(fuser -mM ${MOUNT_POINT} > /dev/null 2>&1); then DISPLAY_PROGRESS "${0}: Cannot unmount '${MOUNT_POINT}' ... exiting." && MESSY_EXIT; fi } function FORCED_EXIT { CLOSE_DISPLAY_BOX DISPLAY_MESSAGE "${0}: Forced exit ... ISO not created." cd ${CWD} if [ -d ${WIP} ]; then cd ${WIP} sudo umount mnt > /dev/null 2>&1 || sudo umount -lf mnt > /dev/null 2>&1 sudo sync && sudo sync && sudo umount iso-chroot/dev > /dev/null 2>&1 || sudo sync && sudo sync && sudo umount -lf iso-chroot/dev > /dev/null 2>&1 cd ${CWD} sudo rm -rf ${WIP} fi [ -f ${CWD}/isorespin.tpl ] && sudo rm -f ${CWD}/isorespin.tpl sudo rm -f ${CWD}/.isorespin.sh.lock exit -1 } function DIRTY_EXIT { CLOSE_DISPLAY_BOX cd "${CWD}" [ -f ${CWD}/isorespin.tpl ] && sudo rm -f ${CWD}/isorespin.tpl sudo rm -f "${CWD}"/.isorespin.sh.lock exit 1 } function UNCLEAN_EXIT { CLOSE_DISPLAY_BOX cd "${CWD}" sudo rm -f "${CWD}"/.isorespin.sh.lock exit 1 } function MESSY_EXIT { CLOSE_DISPLAY_BOX cd ${CWD} if [ -d ${WIP} ]; then cd ${WIP} sudo umount mnt > /dev/null 2>&1 || sudo umount -lf mnt > /dev/null 2>&1 cd ${CWD} sudo rm -rf ${WIP} fi [ -f ${CWD}/isorespin.tpl ] && sudo rm -f ${CWD}/isorespin.tpl sudo rm -f ${CWD}/.isorespin.sh.lock exit 1 } function CLEAN_EXIT { CLOSE_DISPLAY_BOX cd ${CWD} if [ -d ${WIP} ]; then sudo rm -rf ${WIP} fi [ -f ${CWD}/isorespin.tpl ] && sudo rm -f ${CWD}/isorespin.tpl sudo rm -f ${CWD}/.isorespin.sh.lock exit 1 } function CLOSE_DISPLAY_BOX { if [ -n "${GUI_BOX_CONTENT}" ] && [ "$(ps -p ${GUI_BOX_CONTENT} -o comm --no-header)" == "zenity" ]; then sudo kill -9 ${GUI_BOX_CONTENT} > /dev/null 2>&1 GUI_BOX_CONTENT="" fi if [ -n "${GUI_BOX_BORDER}" ] && [ "$(ps -p ${GUI_BOX_BORDER} -o comm --no-header)" == "sleep" ]; then sudo kill -9 ${GUI_BOX_BORDER} > /dev/null 2>&1 GUI_BOX_BORDER="" fi } function DISPLAY_MESSAGE { DISPLAY_TEXT="$1" CLOSE_DISPLAY_BOX ${GUI} && zenity --info --title="isorespin.sh" --text="${DISPLAY_TEXT}" 2> /dev/null ${GUI} || echo "${DISPLAY_TEXT}" if [ -f ${ISORESPIN_LOGFILE} ]; then echo "${DISPLAY_TEXT#${0}: }" >> ${ISORESPIN_LOGFILE} 2> /dev/null fi } function DISPLAY_PROGRESS { DISPLAY_TEXT="$1" CLOSE_DISPLAY_BOX if ${GUI}; then sleep infinity | zenity --progress --title="isorespin.sh" --text="${DISPLAY_TEXT}" --auto-close --no-cancel --pulsate 2> /dev/null & GUI_BOX_BORDER=$(jobs -l | (read GUI_BOX_BORDER; echo $GUI_BOX_BORDER | awk '{print $2}')) GUI_BOX_CONTENT=$(jobs -l | sed 1d | (read GUI_BOX_CONTENT; echo $GUI_BOX_CONTENT | awk '{print $1}')) disown ${GUI_BOX_BORDER} fi ${GUI} || echo "${DISPLAY_TEXT}" } function USAGE { echo "Usage: ${0} [ -h | -v | --check | --rolling-list ]" echo " ${0} -i [ [ -u | -k ] | -r \" ... \" | -p \" ... \" | -l \" ... \" | -f \" | ... \" | [ -s MB | GB ] | ..." echo " ${0} ... -w | -d \" ... \" | -e \" ... \" | -c \" ... \" | -o \" | ... \" | -g \"\" | \" ... \" | ..." echo " ${0} ... [ -b GRUB | GRUB-32 | GRUB-64 | rEFInd | Linuxium ] | -t