You need to sign in or sign up before continuing.
mkbuild 6.55 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"
isaagar's avatar
isaagar committed
101
		cp -r $DIR/data/includes/* $DIR/build_area/$RELEASE-$ARCH/config/includes.installer/
102
		lb config --linux-flavours 686-pae
103 104
	fi

105 106 107
	Info "Adding Hamara GPG Key"
	wget -qO - http://139.180.154.177:8000/aptly_repo_signing.key | sudo apt-key add -

108 109 110
	figlet STARTING BUILD
	lb build
	
isaagar's avatar
isaagar committed
111
	if [ $? -eq 0 ];then
112
		Info " ISO Build successfully for $ARCH architecture "
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
		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
isaagar's avatar
isaagar committed
139
}
isaagar's avatar
isaagar committed
140

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

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

Your Name's avatar
Your Name committed
177
case $1 in
isaagar's avatar
isaagar committed
178
help)
isaagar's avatar
isaagar committed
179 180
	HELP
	;;
isaagar's avatar
isaagar committed
181
iso)
182
	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) ]]
183
	then
isaagar's avatar
isaagar committed
184 185 186 187
		export ARCH=$2
		export MIRROR=$3
		export RELEASE=$4
		export VER=2.0-$5
188
	else
189
		Error "XXX-< Invalid parameters >-XXX"
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
		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
208
 	;;
isaagar's avatar
isaagar committed
209

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

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

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

257
esac