summaryrefslogtreecommitdiff
path: root/buildlive
blob: 4d5d52c6919f2d9b6c6d124a1e03def7ca7f13eb (plain)
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
#!/bin/bash

set -e

DISTROLIST=()
ISOLIST=()
ROOTPATH=
DEVNAME=
KERNELDIR=
DATADIR=
INSTALL_GRUB=1

. functions.sh

msg() {
	echo -e "$1" >&2
}

fatalerror() {
	msg "\x1b[1;31m$1\x1b[0m"
	exit 1
}

usage() {
	msg "$0 --root=<rootpath> --dev=<devname> [--no-grub] [distro 1] [distro 2] ..."
	msg "use $0 -L to list available distros"
}

while [[ -n "$1" ]]
do
	case "$1" in
		-L)
			exec ./listisos.sh
			;;
		--root=*)
			ROOTPATH=${1/--root=}
			UUID="$(findmnt -o UUID --raw --noheadings $ROOTPATH \
				|| fatalerror "UUID of $ROOTPATH not found, not a mountpoint?")"
			KERNELDIR="$ROOTPATH/liveusb-kernel"
			DATADIR="$ROOTPATH/liveusb-data"
			GRUBCFG="$ROOTPATH/grub/grub.cfg"
			install -d "$KERNELDIR" "$DATADIR"
			msg "Files will be copy to $ROOTPATH"
			;;
		--dev=*)
			DEVNAME=${1/--dev=}
			msg "Boot sector will be written to $DEVNAME"
			;;
		--no-grub)
			INSTALL_GRUB=0
			;;
		*=*|-*)
			usage
			exit 1
			;;
		*)
			if [ -d "distro/$1" ]
			then
				DISTROLIST=(${DISTROLIST[@]} "$1")
			else
				fatalerror "directory distro/$1 not found"
			fi
			;;
	esac
	shift
done

if [[ "${#DISTROLIST[@]}" == 0 || -z "$ROOTPATH" ]]; then
	usage
	exit 1
fi

for i in ${DISTROLIST[@]}
do
	process_isoinfo "$i"
	ISOLIST=("${ISOLIST[@]}" "$ISOFILE")

	if [ -f "isofiles/$ISOFILE" ] && checksum_verify; then
		true
	else
		download_iso
	fi
done

install -d "$ROOTPATH/grub"
echo '# The live USB grub.cfg file' > "$GRUBCFG"

if [ -z "$TXTMODE" ]; then
	cat >> "$GRUBCFG" << 'EOF'
insmod all_video
insmod font
if loadfont /grub/fonts/unicode.pf2
then
	insmod gfxterm
	set gfxmode=auto
	set gfxpayload=keep
	terminal_output gfxterm
fi

EOF
fi

for i in `seq 1 ${#DISTROLIST[@]}`
do
	ISOFILE="${ISOLIST[$i-1]}"
	DISTRO="${DISTROLIST[$i-1]}"
	process_distro "$DISTRO"

	install_live
	gen_grubcfg "$DISTRO" >> "$GRUBCFG"
done

if [ "$INSTALL_GRUB" == 1 ]; then
	as-root grub-install --boot-directory="$ROOTPATH" --target=i386-pc "$DEVNAME"
	as-root grub-install --boot-directory="$ROOTPATH" --efi-directory="$ROOTPATH" --bootloader-id=grub --target=x86_64-efi --removable --no-nvram "$DEVNAME"
fi