mkbuild 6.47 KB
Newer Older
isaagar's avatar
isaagar committed
1
#!/bin/bash
isaagar's avatar
isaagar committed
2
#
isaagar's avatar
isaagar committed
3
#    Copyright (C) 2018 I Sagar <sagar@hamaralinux.org>
isaagar's avatar
isaagar committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#
#    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$
#
isaagar's avatar
isaagar committed
19

isaagar's avatar
isaagar committed
20

21 22 23
#Adding a seconds variable to  display  time taken by the build
#Inbuilt variable available with bash, initialized to zero
SECONDS=0
24 25
DATE=`date +%Y%m%d`

26 27 28 29 30 31 32 33 34
Info () {
    echo "I: ${*}" >&2
}

Error () {
    echo "E: ${*}" >&2
}


isaagar's avatar
isaagar committed
35
SETUP(){
36 37 38
	clear
	figlet SETUP
	
isaagar's avatar
isaagar committed
39
	cd $DIR
40
	
41
	for PKG in apt-cacher-ng debootstrap live-build figlet
42
	do
43 44 45 46
		dpkg -s $PKG &> /dev/null
		if [ $? -eq 1 ];then
			apt-get install -y $PKG
		fi
47
	done
isaagar's avatar
isaagar committed
48

isaagar's avatar
isaagar committed
49
	#Copying live build scripts
rajudev's avatar
rajudev committed
50
	if [ $RELEASE == "hamara-sugam" ]
51 52 53 54 55 56 57 58
	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

59
	Info "Replacing bootloader config files"
60 61
	rm -rf /usr/share/live/build/bootloaders
	cp -r data/$RELEASE/bootloaders /usr/share/live/build
isaagar's avatar
isaagar committed
62

rajudev's avatar
rajudev committed
63
	if [ $RELEASE == "hamara-sugam" ]; then
64
		ln -sf /usr/share/live/build/data/debian-cd/squeeze /usr/share/live/build/data/debian-cd/namaste
65
		ln -sf /usr/share/debootstrap/scripts/sid /usr/share/debootstrap/scripts/namaste
66
	else
67 68
		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
69
	fi
isaagar's avatar
isaagar committed
70
}
isaagar's avatar
isaagar committed
71

isaagar's avatar
isaagar committed
72
CLEAN(){
73
	figlet CLEAN
74
	if [ -d "$DIR/build_area/$RELEASE-$ARCH" ]; then
75
		Info "Change to target directory"
isaagar's avatar
isaagar committed
76
		cd $DIR/build_area/$RELEASE-$ARCH
77
		echo "#################################################"
78
		Info "   Cleaning build files of $ARCH architecture   "
79
		echo "#################################################"
isaagar's avatar
isaagar committed
80 81
		lb clean
	else
82
		Info "[Skipped] Build area not present for $ARCH architecture "
isaagar's avatar
isaagar committed
83
	fi
isaagar's avatar
isaagar committed
84 85 86
}

BUILD(){
87
	figlet BUILD
88
	Info "Creating build directory"
89

isaagar's avatar
isaagar committed
90
	mkdir -p $DIR/build_area/$RELEASE-$ARCH
91

92
	Info "Changing to build directory"
isaagar's avatar
isaagar committed
93
	cd $DIR/build_area/$RELEASE-$ARCH
isaagar's avatar
isaagar committed
94

95 96
	Info "Copying config files"
	. $DIR/$RELEASE.conf
97
	cp -rv $DIR/config.d/$RELEASE/config/* $DIR/build_area/$RELEASE-$ARCH/config/
98

99
	if [ $ARCH == i386 ] ;then
100
		Info "Copy installer files for i386 arch and set kernel flavour"
101
		cp -rv $DIR/config.d/$RELEASE/config/* $DIR/build_area/$RELEASE-$ARCH/config/
rajudev's avatar
rajudev committed
102
		lb config --linux-flavours 686 --architectures i386
103 104
	fi

105 106 107
	figlet STARTING BUILD
	lb build
	
isaagar's avatar
isaagar committed
108
	if [ $? -eq 0 ];then
109
		Info " ISO Build successfully for $ARCH architecture "
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
		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
129 130
		echo " Current time "
		date | figlet
131 132 133 134 135 136 137
		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
isaagar's avatar
isaagar committed
138
}
isaagar's avatar
isaagar committed
139

isaagar's avatar
isaagar committed
140
HELP(){
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
	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 "
161
	echo "     VERSION           --   alpha | beta | final  "
162 163 164
	echo " "
	echo "* For more info. "
	echo "     man ./HELP "
isaagar's avatar
isaagar committed
165
}
isaagar's avatar
isaagar committed
166

167 168 169
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
if [ "$EUID" -ne 0 ]
170
	then
171
	Info " --->  Please run as root <--- "
172
	echo "man ./HELP for more info"
173
	exit
174 175
fi

Your Name's avatar
Your Name committed
176
case $1 in
isaagar's avatar
isaagar committed
177
help)
isaagar's avatar
isaagar committed
178 179
	HELP
	;;
isaagar's avatar
isaagar committed
180
iso)
181
	if [[ "$#" -eq 5 ]] && [[ "$2" = @(amd64|i386|all) ]] && [[ "$3" = @(in.devel.hamaralinux.org|devel.hamaralinux.org) ]] && [[ "$4" = @(minimal|hamara|hamara-sugam) ]] && [[ "$5" = @(pre-alpha|alpha|beta|final) ]]
182
	then
isaagar's avatar
isaagar committed
183 184 185 186
		export ARCH=$2
		export MIRROR=$3
		export RELEASE=$4
		export VER=2.0-$5
187
	else
188
		Error "XXX-< Invalid parameters >-XXX"
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
		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
isaagar's avatar
isaagar committed
207
 	;;
isaagar's avatar
isaagar committed
208

isaagar's avatar
isaagar committed
209
clean)
210 211 212 213 214 215 216 217 218 219 220
	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
isaagar's avatar
isaagar committed
221
			CLEAN
222 223
		fi
	else
224 225
		Error " !!! Invalid option !!!"
		echo  "Valid Usage -  ./mkbuild clean ARCH RELEASE "
226 227
		HELP
	fi
isaagar's avatar
isaagar committed
228 229
	;;

230 231 232 233 234 235 236 237 238 239
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
240
				rm -rf $DIR/build_area/$RELEASE-$ARCH && Info "--- Removing build area ---"
241 242 243
			done
		else
			CLEAN
244
			rm -rf $DIR/build_area/$RELEASE-$ARCH && Info "--- Removing build area ---"
245 246
		fi
	else
247
		Error "XX-< Invalid option >-XX"
248 249
		HELP
	fi
isaagar's avatar
isaagar committed
250 251
	;;

isaagar's avatar
isaagar committed
252
*)
isaagar's avatar
isaagar committed
253 254 255
	HELP
	;;

256
esac