summaryrefslogtreecommitdiff
path: root/functions.sh
blob: 8d8db9cef064574646f29e090f5aaee3c25f28cf (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
checksum_verify() {
	local _hashtool _hashsum _cksum
	if [ -n "$SHA256" ]; then
		_hashtool=sha256sum
		_hashsum=$SHA256
	elif [ -n "$SHA1" ]; then
		_hashtool=sha1sum
		_hashsum=$SHA1
	elif [ -n "$MD5" ]; then
		_hashtool=md5sum
		_hashsum=$MD5
	else
		fatalerror "Cannot find the SHA256, SHA1, or MD5 checksum of $ISOFILE"
	fi
	_cksum=$("$_hashtool" "isofiles/$ISOFILE" | cut -d' ' -f1)
	if [[ $_cksum == $_hashsum ]]; then
		msg "$ISOFILE ok."
	else
		fatalerror "$ISOFILE checksum bad!"
	fi
}

process_distro() {
	unset MD5 SHA1 SHA256
	source "distro/$1/install.sh"
	ISOFILE="$(basename $ISOURL)"
	ISOMNT="/media/$ISOFILE"
	MIRRORLIST=(`cat "distro/$1/mirrorlist"`)
}

download_iso() {
	for url in ${MIRRORLIST[@]}
	do
		wget -O "isofiles/$ISOFILE" "$url/$ISOURL" && return 0
	done
	fatalerror "Fail to download $ISOFILE!"
}

mount_iso() {
	udevil mount "isofiles/$ISOFILE" "$ISOMNT"
}

umount_iso() {
	udevil umount "$ISOMNT"
}

getuuid() {
	lsblk -n -o UUID "$1"
}