You need to sign in or sign up before continuing.
build 4.78 KB
Newer Older
Raju Devidas's avatar
Raju Devidas committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
#!/usr/bin/bash
#    Hamara OS Builder
#    Copyright (C) 2020 rajudev <mail@raju.dev>
#
#    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 <https://www.gnu.org/licenses/>.
#


# 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