summaryrefslogtreecommitdiff
path: root/nfs/scripts/funcs.sh
blob: a1757a1b15410ae9e08f50a2b04cd511458c5b48 (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
# no args, let the user read useful informations on console (or skip with Enter)
pause10s() {
	sfx_question # sfx_* comes from /etc/rc.d/funcs helpers
	read -t10 -p 'Press Enter or wait 10 sec...'
	# Make some blank lines on console
	echo -e '\n\n\n\n\n'
}

# no args, print colored message, returns 0 if hostname seems valid, returns 1 if hostname is a default one
hostname_test() {
	BADNAME='echo_color white red ">>> hostname should not contain special characters or should not be FQDN : $hostname"'
	# This test is for security concern, hostname will be used as shell arg
	case $hostname in
		"(none)"|eficast|"")	echo_color white red ">>> hostname is not customized : $hostname" ; return 1 ;;
		*\&*)			$BADNAME; return 2 ;;
		*\(*)			$BADNAME; return 2 ;;
		*\{*)			$BADNAME; return 2 ;;
		*\;*)			$BADNAME; return 2 ;;
		*\<*)			$BADNAME; return 2 ;;
		*\`*)			$BADNAME; return 2 ;;
		*\ *)			$BADNAME; return 2 ;;
		*)			echo_color green black ">>> hostname is $hostname" ; return 0 ;;
	esac
}

# no args, print colored message, returns 0 if NFS is read-only, returns 1 if NFS is read-write (needed for image capture)
nfswrite_test() {
	if ! touch /mnt/nfs/.writetest
	then	echo_color green black ">>> NFS is read-only"
		return 0
	else	echo_color white blue ">>> NFS is read-write"
		return 1
	fi
}

# no args, print colored message, returns 0 if sda is present and is sata, returns >0 if it is not
firstdisk_test() {
	diskinfo=$(lsblk --list --output TRAN,MODEL --noheadings --nodeps /dev/sda)
	case $diskinfo in
		sata*)	echo_color green black ">>> First disk is SATA and is available ($diskinfo)"
		return 0
		;;
		usb*)	echo_color white red ">>> First disk is USB ($diskinfo)"
		return 1
		;;
		*)	echo_color white red ">>> First disk is unknown ($diskinfo)"
		return 2;
		;;
	esac
}

# $1 : scriptname, print colored message, returns 0 script is available, returns 1 if not
scriptavailability_test() {
	script=$scriptdir/$1
	if [ -r $script ]
	then	echo_color green black ">>> Script $script is available"
		return 0
	else	echo_color white blue ">>> Script $script is missing or unreadable"
		return 1
	fi
}

# $1 : scriptname, print colored message, returns 0 script is available, returns 1 if not
diravailability_test() {
	dir=$1
	if [ -d $dir ]
	then	echo_color green black ">>> Image $dir is available"
		return 0
	else	echo_color white blue ">>> Image $dir is missing or unreadable"
		return 1
	fi
}