summary refs log tree commit diff
path: root/noarch/pre_install.sh
blob: fd04a16d8c169a2b5b76e4e686bc01f7268a2083 (plain) (blame)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/sh

compare_insensitive() {
	echo "$1" | grep -qi "^${2}$"
}

detect_legacy_uld() {
	if ! [ -d "/opt" ] ; then
		return 1
	fi

	for i in $( ls "/opt" ) ; do
		if compare_insensitive $i $VENDOR ; then
			if [ -s "/opt/$i/mfp/uninstall/guiuninstall" ]; then
				LEGACY_ULD_NAME="$i"
				return 0
			fi
		fi
	done
	return 1
}

# lecence file finding
find_eula_file() {
	EULA_DIR="${DIST_DIR}/noarch/license"
	log_variable EULA_DIR

	EULA_LOCALE="${LC_ALL:-${LC_MESSAGES:-${LANG}}}"
	EULA_LOCALE=`echo "${EULA_LOCALE}" | tr A-Z a-z`
	log_variable EULA_LOCALE

	while [ -n "${EULA_LOCALE}" ] ; do
		EULA_FILE="${EULA_DIR}/eula-${EULA_LOCALE}.txt"
		#log_variable EULA_FILE
		if [ -r "${EULA_FILE}" ] ; then break ; fi
		EULA_LOCALE=`echo "${EULA_LOCALE}" | sed 's/.$//'` # drop last symbol
	done
	log_variable EULA_LOCALE
	if [ -z "${EULA_LOCALE}" ] ; then
		EULA_FILE="${EULA_DIR}/eula.txt"
		if [ ! -r "${EULA_FILE}" ] ; then
			EULA_FILE=""
		fi
	fi

	log_variable EULA_FILE
	echo "${EULA_FILE}"
}

show_license() {
	EULA_FILE=`find_eula_file`
	EULA_PAGER="${PAGER:-`which more`}"
	log_variable EULA_PAGER

	if [ -n "${EULA_FILE}" -a -n "${EULA_PAGER}" ] ; then
		ICONV_BINARY=`which iconv`
		# show EULA:
		show_cut_line
		if [ -z "${SKIP_EULA_PAGER}" ] ; then
			if [ -n "$ICONV_BINARY" ] ; then
				cat "${EULA_FILE}" | "${ICONV_BINARY}" -c -f "UTF-8" | ${EULA_PAGER}
			else
				"${EULA_PAGER}" "${EULA_FILE}"
			fi
		fi

		show_cut_line

		# ask for agreement:
		output_blank_line
		show_nls_message_no_nl "**** Do you agree ? [y/n] : "
		if [ -z "${AGREE_EULA}" ] ; then
			read AGREE_EULA
		fi
		if [ "y" != "${AGREE_EULA}" ] && [ "Y" != "${AGREE_EULA}" ] ; then
			show_nls_message "**** Terminated by user"
			exit 1
		fi
	fi
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SCRIPTS_DIR="$(dirname "$0")"

# load 'scripting' run-time support utility functions
. "${SCRIPTS_DIR}/scripting_utils"

# load 'package' run-time support utility functions
. "${SCRIPTS_DIR}/package_utils"
environment_init "$(basename "$0" ".sh")"


UNINSTALLMODE=
while [ -n "$1" ]; do
	case "$1" in
	-u) UNINSTALLMODE=1 ;;
	vendor=*) specify_vendor "${1#vendor=}" ;;
	esac
	shift
done

if ! have_root_permissions ; then
	show_nls_message "**** Root privileges are required"
	exit 1
fi

if [ "$UNINSTALLMODE" ]; then
	show_nls_message "**** Running uninstall ..."
else
	show_nls_message "**** Running install ..."
fi
show_nls_message_no_nl "**** Press 'Enter' to continue or 'q' and then 'Enter' to quit. : "
if [ -z "${QUIT_INSTALL}" ] ; then
	read QUIT_INSTALL
fi
if [ "q" = "${QUIT_INSTALL}" ] || [ "Q" = "${QUIT_INSTALL}" ] ; then
	show_nls_message "**** Terminated by user"
	exit 1
fi

LEGACY_ULD_NAME=
if detect_legacy_uld ; then
	show_nls_message "**** Old version of Unified Linux Driver is detected."
	show_nls_message "**** In order to continue the installation, please remove old version."
	show_nls_message_no_nl "**** If you want to delete old version press 'y'. To finish the installation press 'Enter'. : "
	if [ -z "${UNINSTALL_LECAGY}" ] ; then
		read UNINSTALL_LECAGY
	fi
	if [ "y" = "${UNINSTALL_LECAGY}" ] || [ "Y" = "${UNINSTALL_LECAGY}" ] ; then
		"/opt"/${LEGACY_ULD_NAME}/mfp/uninstall/uninstall.sh -t
	else
		show_nls_message "**** Terminated by user"
		exit 1
	fi
fi

if ! [ "$UNINSTALLMODE" ]; then
	show_license
fi