#!/usr/bin/bash # Hamara OS Builder # Copyright (C) 2020 rajudev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero 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 Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # # Check if the script is being run as root user if [ "$EUID" -ne 0 ] then echo "Please run the script as root" exit fi ## ---------------------------------- # Step #1: Define variables # ---------------------------------- EDITOR=nano PASSWD=/etc/passwd RED='\033[0;41;30m' STD='\033[0;0;39m' # ---------------------------------- # Functions # ---------------------------------- setup(){ #This function will setup the build environment apt-get -y install live-build xorriso apt-cacher-ng figlet figlet setup figlet is figlet completed sleep 2 } configure(){ #this function will start the initial configuration mirror="http://127.0.0.1:3142/deb.debian.org/debian" # do not change this dist="unstable" lb config noauto \ --architectures amd64 \ --archive-areas "main contrib" \ --mirror-bootstrap "$mirror" \ --distribution "$dist" \ --iso-application "Hamara spin i3wm Live" \ --iso-publisher "Hamara Team" \ --iso-volume "Hamara i3wm live" \ --security false \ --updates false \ --memtest memtest86 figlet configuration figlet is done } minimal-build(){ setup configure echo "Adding minimal package list" cp -v configurations/minimal.list.chroot_install config/package-lists/minimal.list.chroot_install cp -v configurations/live.list.chroot config/package-lists/live.list.chroot build } build(){ #This function starts the actual build of the operating system. figlet build figlet started lb build | tee build.log figlet build figlet finished } clean(){ lb clean rm -rf cache config } # function to display menus show_menus() { clear echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo " Hamara OS Builder - M E N U" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "1. Setup" echo "2. Configure" echo "3. Build Hamara i3wm spin" echo "4. Clean build environment" echo "5. Exit" } # read input from the keyboard and take a action # Exit when user the user select 7 form the menu option. read_options(){ local choice read -p "Enter choice [ 1 - 5] " choice case $choice in 1) setup ;; 2) configure ;; 3) minimal-build ;; 4) clean ;; 5) exit 0;; *) echo -e "${RED}Error...${STD}" && sleep 2 esac } # ---------------------------------------------- # Step #3: Trap CTRL+C, CTRL+Z and quit singles # ---------------------------------------------- trap '' SIGINT SIGQUIT SIGTSTP # ----------------------------------- # Step #4: Main logic - infinite loop # ------------------------------------ # automatic-build(){ # echo "Starting Automatic build" # setup # configure # build # } help(){ echo "############################################" echo "# HELP #" echo "############################################" echo " This Hamara builder can be be run in two modes " echo " 1. Interactive mode" echo " 2. Automated mode" echo " When building manually you should be using the interactive mode." echo " Interactive mode brings up a menu which you can use to do the magic" echo " " echo " Automated mode is used to run the script in a CI system." echo " In CI system a human interaction is not needed, hence everything needs" echo " to be pre-selected" echo " " echo "* Usage example :" echo " Interactive Build -- ./build interactive" echo " " echo " For automated build we also need to supply the variant" echo " format: ./build MODE VARIANT" echo "Usage" echo "Minimal Build -- ./build auto minimal" echo " " echo " Help Menu" echo " HELP -- ./build help " } interactive(){ while true do show_menus read_options done } case $1 in interactive) interactive ;; auto) if [[ "$#" -eq 2 ]] && [[ "$2" = "minimal" ]] then minimal-build else echo "Invalid Build option" exit 0 fi ;; help) help ;; *) help ;; esac