#!/bin/bash # # Copyright (C) 2018 I Sagar # # 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 2 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, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U$ # #Adding a seconds variable to display time taken by the build #Inbuilt variable available with bash, initialized to zero SECONDS=0 DATE=`date +%Y%m%d` Info () { echo "I: ${*}" >&2 } Error () { echo "E: ${*}" >&2 } SETUP(){ clear figlet SETUP cd $DIR for PKG in apt-cacher-ng debootstrap live-build figlet do dpkg -s $PKG &> /dev/null if [ $? -eq 1 ];then apt-get install -y $PKG fi done #Copying live build scripts if [ $RELEASE == "hamara-sugam" ] then cp -rv data/hamara-sugam/lb_scripts/* /usr/lib/live/build/ echo " [Done] Copying scripts for Hamara Sugam " else cp -rv data/hamara/lb_scripts/* /usr/lib/live/build/ echo " [Done] Copying scripts for hamara" fi Info "Replacing bootloader config files" rm -rf /usr/share/live/build/bootloaders cp -r data/$RELEASE/bootloaders /usr/share/live/build if [ $RELEASE == "hamara-sugam" ]; then ln -sf /usr/share/live/build/data/debian-cd/squeeze /usr/share/live/build/data/debian-cd/namaste ln -sf /usr/share/debootstrap/scripts/sid /usr/share/debootstrap/scripts/namaste else ln -sf /usr/share/live/build/data/debian-cd/squeeze /usr/share/live/build/data/debian-cd/svastik ln -sf /usr/share/debootstrap/scripts/sid /usr/share/debootstrap/scripts/svastik fi } CLEAN(){ figlet CLEAN if [ -d "$DIR/build_area/$RELEASE-$ARCH" ]; then Info "Change to target directory" cd $DIR/build_area/$RELEASE-$ARCH echo "#################################################" Info " Cleaning build files of $ARCH architecture " echo "#################################################" lb clean else Info "[Skipped] Build area not present for $ARCH architecture " fi } BUILD(){ figlet BUILD Info "Creating build directory" mkdir -p $DIR/build_area/$RELEASE-$ARCH Info "Changing to build directory" cd $DIR/build_area/$RELEASE-$ARCH Info "Copying config files" . $DIR/$RELEASE.conf cp -rv $DIR/config.d/$RELEASE/config/* $DIR/build_area/$RELEASE-$ARCH/config/ if [ $ARCH == i386 ] ;then Info "Copy installer files for i386 arch and set kernel flavour" cp -r $DIR/data/includes/* $DIR/build_area/$RELEASE-$ARCH/config/includes.installer/ lb config --linux-flavours 686-pae fi Info "Adding Hamara GPG Key" wget -qO - http://139.180.154.177:8000/aptly_repo_signing.key | sudo apt-key add - figlet STARTING BUILD lb build if [ $? -eq 0 ];then Info " ISO Build successfully for $ARCH architecture " Info "Renaming the ISO" mv *.hybrid.iso "$RELEASE"-live-"$VER"-"$ARCH".iso Info "Calculating sha1sum" for i in 1 256 512 do echo "Generating SHA"$i"SUM" for j in *.iso *.contents *.packages do sha"$i"sum $j >> SHA"$i"SUMS done done Info "Create output directory" mkdir -p $DIR/output/$RELEASE-$ARCH-$DATE for i in *.iso *.contents *.packages *SUMS do mv -v $i $DIR/output/$RELEASE-$ARCH-$DATE done duration=$SECONDS Info " Build completed in $(($duration / 60)) minutes and $(($duration % 60)) seconds " echo " ---- Now, test your ISO ---- " echo " Tip : Make bootable USB stick with Etcher " echo " [Link] https://etcher.io/ " else Error " [Failed] Try again. " fi } HELP(){ echo "############################################" echo "# HELP #" echo "############################################" echo " Uses live-build ver. ~ 5.0 " echo " " echo "* Options :" echo " help -- displays current screen " echo " iso -- builds ISO " echo " clean -- cleans building area " echo " purge -- removes cache directory after cleaning building area " echo " " echo "* Usage example :" echo " Build ISO -- ./mkbuild iso ARCH MIRROR RELEASE VERSION" echo " Clean build area -- ./mkbuild clean ARCH RELEASE " echo " Purge build area -- ./mkbuild purge ARCH RELEASE " echo " " echo "* Parameters :" echo " ARCH -- amd64 | i386 | all" echo " MIRROR -- devel.hamaralinux.org | in.devel.hamaralinux.org " echo " RELEASE -- hamara | hamara-sugam " echo " VERSION -- alpha | beta | final " echo " " echo "* For more info. " echo " man ./HELP " } DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR if [ "$EUID" -ne 0 ] then Info " ---> Please run as root <--- " echo "man ./HELP for more info" exit fi case $1 in help) HELP ;; iso) if [[ "$#" -eq 5 ]] && [[ "$2" = @(amd64|i386|all) ]] && [[ "$3" = @(in.devel.hamaralinux.org|devel.hamaralinux.org|139.180.154.177:8000) ]] && [[ "$4" = @(minimal|hamara|hamara-sugam) ]] && [[ "$5" = @(pre-alpha|alpha|beta|final) ]] then export ARCH=$2 export MIRROR=$3 export RELEASE=$4 export VER=2.0-$5 else Error "XXX-< Invalid parameters >-XXX" HELP exit 1 fi #check ARCH variable if [[ "$ARCH" = "all" ]] then #Do setup common for both arch SETUP for ARCH in amd64 i386 do CLEAN BUILD done else SETUP CLEAN BUILD fi ;; clean) if [[ "$#" -eq 3 ]] && [[ "$2" = @(amd64|i386|all) ]] && [[ "$3" = @(minimal|hamara|hamara-sugam) ]] then ARCH=$2 RELEASE=$3 if [[ "$ARCH" = "all" ]] then for ARCH in amd64 i386 do CLEAN done else CLEAN fi else Error " !!! Invalid option !!!" echo "Valid Usage - ./mkbuild clean ARCH RELEASE " HELP fi ;; purge) if [[ "$#" -eq 3 ]] && [[ "$2" = @(amd64|i386|all) ]] && [[ "$3" = @(minimal|hamara|hamara-sugam) ]] then ARCH=$2 RELEASE=$3 if [[ "$ARCH" = "all" ]] then for ARCH in amd64 i386 do CLEAN rm -rf $DIR/build_area/$RELEASE-$ARCH && Info "--- Removing build area ---" done else CLEAN rm -rf $DIR/build_area/$RELEASE-$ARCH && Info "--- Removing build area ---" fi else Error "XX-< Invalid option >-XX" HELP fi ;; *) HELP ;; esac