ubuntuusers.de

Titel:
Unbenannt
Autor:
stuffel0815
Datum:
13. Juni 2020 12:44
Aktionen:
Code:
  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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/sh 
detect_printer_group() {
	if test -c /dev/usb/lp0 ; then
		PRINTER_GROUP=`ls -l /dev/usb/lp0 2> /dev/null | awk '{print $4}'`
#d		echo "/dev/usb/lp0" " found" ", group is " $PRINTER_GROUP
	elif test -c /dev/usblp0 ; then
		PRINTER_GROUP=`ls -l /dev/usblp0 2> /dev/null | awk '{print $4}'`
#d		echo "/dev/usblp0" " found" ", group is " $PRINTER_GROUP
	elif test -d /var/spool/cups ; then
		PRINTER_GROUP=`ls -ld /var/spool/cups 2> /dev/null | awk '{print $4}'`
#d		echo "/var/spool/cups" " found" ", group is " $PRINTER_GROUP
	else
		PRINTER_GROUP="lp"
	fi
}

required_packages() {
# $1 - distro
	local PACKAGES
	log_message "required_packages" "$@"

	PACKAGES=
	case $1 in
		$DISTRO_SUSE)
			PACKAGES=$PACKAGES\ cups
			PACKAGES=$PACKAGES\ cups-libs
			PACKAGES=$PACKAGES\ sane-backends
			;;
		$DISTRO_DEBIAN)
			PACKAGES=$PACKAGES\ cups
			PACKAGES=$PACKAGES\ libsane
			;;
		$DISTRO_UBUNTU)
			PACKAGES=$PACKAGES\ cups
			PACKAGES=$PACKAGES\ libsane
			;;
		$DISTRO_ALTLINUX)
			PACKAGES=$PACKAGES\ cups
			;;
		$DISTRO_FEDORA)
			PACKAGES=$PACKAGES\ cups
			PACKAGES=$PACKAGES\ cups-libs
			PACKAGES=$PACKAGES\ sane-backends-libs
			;;
		$DISTRO_MANDRAKE)
			PLATFORM_PACKAGE_PREFIX=lib$PLSFX
			PACKAGES=$PACKAGES\ ${PLATFORM_PACKAGE_PREFIX}cups2
			PACKAGES=$PACKAGES\ ${PLATFORM_PACKAGE_PREFIX}sane1
			PACKAGES=$PACKAGES\ cups
			PACKAGES=$PACKAGES\ cups-common
			;;
		$DISTRO_REDHAT)
			PACKAGES=$PACKAGES\ cups
			PACKAGES=$PACKAGES\ cups-libs
			PACKAGES=$PACKAGES\ sane-backends-libs
			;;
		*)
			echo $(gettext "Unsupported distribution") >&2
			;;
	esac

	echo $PACKAGES
}


detect_system_packages() {
	CUPS_DETECTED=1
	GS_DETECTED=1
	SANE_DETECTED=1
	. "$SCRIPT_DIR/check_packages.sh"
	MISSING=`check_required_packages required_packages`
	if [ $? -eq 0 ]; then
		return 0;
	fi
	log_message "MISSING PACKAGES: <$MISSING>"
	#TODO check libs
	if ! test -f /etc/cups/printers.conf && ! test -e /usr/sbin/cupsd ; then
		CUPS_DETECTED=0
	fi
	
	if test -z "`gs --version 2> /dev/null`" ; then
		GS_DETECTED=0
	fi

	if [ "$MISSING" != "${MISSING%*sane*}" ] ; then
		SANE_DETECTED=0
	fi
}

define_guiexec_file_depends_on_qt() {
	local GUIEXEC_NAME=guiinstall
	local GUIEXEC_SUBDIR=install
	local USE_CUSTOM_QT DIR_LIB_QT
	
	if [ "$RUN_MODE" = "$RUN_MODE_UNINSTALL" ]; then
		GUIEXEC_NAME=guiuninstall
		GUIEXEC_SUBDIR=at_opt/uninstall		
	fi

	if [ "$RUN_FROM" = "$RUN_FROM_INSTALL" ]; then
		## only uninstall script could be launched from installation directory
		GUIEXEC="$INST_DIR/uninstall/$GUIEXEC_NAME"
		return
	fi
	
	## "$RUN_FROM" = "$RUN_FROM_DIST"
	# launched from dist, suitable gui application (qt3/qt4) is selected
	GUIEXEC_QT3="$DIST_DIR/$HARDWARE_PLATFORM/$SUBDIR_QT3/$GUIEXEC_SUBDIR/$GUIEXEC_NAME"
	GUIEXEC_QT4="$DIST_DIR/$HARDWARE_PLATFORM/$SUBDIR_QT4/$GUIEXEC_SUBDIR/$GUIEXEC_NAME"
	DIR_LIB_QT3="$DIST_DIR/$HARDWARE_PLATFORM/$SUBDIR_QT3/at_root/$INSTALL_DIR_COMMON_LIB"
	DIR_LIB_QT4="$DIST_DIR/$HARDWARE_PLATFORM/$SUBDIR_QT4/at_root/$INSTALL_DIR_COMMON_LIB"

	if "$GUIEXEC_QT4" --help >/dev/null 2>&1; then
		QT_MODE=$QT_MODE_QT4

	elif "$GUIEXEC_QT3" --help >/dev/null 2>&1; then
		QT_MODE=$QT_MODE_QT3

	elif LD_LIBRARY_PATH="$DIR_LIB_QT4:$LD_LIBRARY_PATH" "$GUIEXEC_QT4" --help >/dev/null 2>&1; then
		QT_MODE=$QT_MODE_QT4
		USE_CUSTOM_QT=1

	elif LD_LIBRARY_PATH="$DIR_LIB_QT3:$LD_LIBRARY_PATH" "$GUIEXEC_QT3" --help >/dev/null 2>&1; then
		QT_MODE=$QT_MODE_QT3
		USE_CUSTOM_QT=1

	else
		log_message "Failed to auto-detect Qt: Qt4 will be used"
		QT_MODE=$QT_MODE_QT4
		USE_CUSTOM_QT=1
	fi

	log_message "<$QT_MODE> detected"
	log_message "USE_CUSTOM_QT=<$USE_CUSTOM_QT>"

	if [ "$QT_MODE" = "$QT_MODE_QT4" ]; then
		GUIEXEC=$GUIEXEC_QT4
		DIR_LIB_QT=$DIR_LIB_QT4
		SUBDIR_QT=$SUBDIR_QT4

	elif [ "$QT_MODE" = "$QT_MODE_QT3" ]; then
		GUIEXEC=$GUIEXEC_QT3
		DIR_LIB_QT=$DIR_LIB_QT3
		SUBDIR_QT=$SUBDIR_QT3
	fi

	if [ "$USE_CUSTOM_QT" ]; then
		print_message_qt_not_found 2>&1 | log_message
		export LD_LIBRARY_PATH="$DIR_LIB_QT:$LD_LIBRARY_PATH"
	fi
}

print_message_qt_not_found() {
	echo "****  "$(gettext "It seems Qt library is not installed, or X display is not accessible.")
	echo "****  "$(gettext "Custom Qt library will be configured for use with this package.")
}

show_versions() {
	test -r "${DIST_DIR}/noarch/at_opt/share/VERSION-Common_LINUX"   && echo "Common_LINUX   `cat "${DIST_DIR}/noarch/at_opt/share/VERSION-Common_LINUX"`"
	test -r "${DIST_DIR}/noarch/at_opt/share/VERSION-Printer_LINUX"  && echo "Printer_LINUX  `cat "${DIST_DIR}/noarch/at_opt/share/VERSION-Printer_LINUX"`"
	test -r "${DIST_DIR}/noarch/at_opt/share/VERSION-Scanner_LINUX"  && echo "Scanner_LINUX  `cat "${DIST_DIR}/noarch/at_opt/share/VERSION-Scanner_LINUX"`"
	test -r "${DIST_DIR}/noarch/at_opt/share/VERSION-Common_SCRIPT"  && echo "Common_SCRIPT  `cat "${DIST_DIR}/noarch/at_opt/share/VERSION-Common_SCRIPT"`"
	test -r "${DIST_DIR}/noarch/at_opt/share/VERSION-Scanner_SCRIPT" && echo "Scanner_SCRIPT `cat "${DIST_DIR}/noarch/at_opt/share/VERSION-Scanner_SCRIPT"`"
	test -r "${DIST_DIR}/noarch/at_opt/share/VERSION-Printer_SCRIPT" && echo "Printer_SCRIPT `cat "${DIST_DIR}/noarch/at_opt/share/VERSION-Printer_SCRIPT"`"

	test -r "${DIST_DIR}/smartpanel/bin${PLSFX}/.version"            && echo "SmartPanel     `cat "${DIST_DIR}/smartpanel/bin${PLSFX}/.version"`"
	test -r "${DIST_DIR}/psu/bin${PLSFX}/.version"                   && echo "PSU            `cat "${DIST_DIR}/psu/bin${PLSFX}/.version"`"
	test -r "${DIST_DIR}/phonebook/bin${PLSFX}/.version"             && echo "PhoneBook      `cat "${DIST_DIR}/phonebook/bin${PLSFX}/.version"`"
	test -r "${DIST_DIR}/emailbook/bin${PLSFX}/.version"             && echo "EmailBook      `cat "${DIST_DIR}/emailbook/bin${PLSFX}/.version"`"
	test -r "${DIST_DIR}/smartpanel/bin${PLSFX}/.script-version"     && echo "SmartPn_SCRIPT `cat "${DIST_DIR}/smartpanel/bin${PLSFX}/.script-version"`"
	test -r "${DIST_DIR}/psu/bin${PLSFX}/.script-version"            && echo "PSU_SCRIPT     `cat "${DIST_DIR}/psu/bin${PLSFX}/.script-version"`"
}

usage() {
# $1 - application name
cat << EOF
Usage: $1 [OPTIONS] [OPTIONS FOR ROOT PART]
Options:
	-t	Use text mode
	-u	Perform uninstallation
	-c	Check installation
	-v 	Show componets version
	-h	Display this help and exit
EOF
}


#include repeated common finctions such  as log_message and localization
SCRIPT_DIR=$(dirname "$0")
. "$SCRIPT_DIR/common.sh" 

common_init

### posible move to common_init
umask 022

TEXTMODE=

RUN_MODE_INSTALL=install
RUN_MODE_UNINSTALL=uninstall
RUN_MODE_CHECK=check
RUN_MODE_SHOW_VERSIONS=show_versions
RUN_MODE=$RUN_MODE_INSTALL

GUIEXEC=

while [ -n "$1" ]; do
	case $1 in
	-t) TEXTMODE=1 ;;
	-u) RUN_MODE=$RUN_MODE_UNINSTALL ;;
	-c) RUN_MODE=$RUN_MODE_CHECK ;;	
	-v) RUN_MODE=$RUN_MODE_SHOW_VERSION ;;
	-h) usage "$SCRIPT_NAME"; exit 0 ;;
	*) break ;;
	esac
	shift
done

if [ "$RUN_MODE" = "$RUN_MODE_CHECK" ]; then
	sh "$SCRIPT_DIR/check_installation.sh" ; exit 0
elif [ "$RUN_MODE" = "$RUN_MODE_SHOW_VERSION" ]; then
	show_versions ; exit 0
fi

SUBDIR_QT3=qt3
SUBDIR_QT4=qt4
SUBDIR_QT=$SUBDIR_QT4

CREATE_USR_LIB_LINK=0

DO_INSTALL_ARGS=

## additional dances only for installation 
if [ "$RUN_MODE" = "$RUN_MODE_INSTALL" ]; then

	log_message "Checking libraries..."
	
	detect_system_packages
	detect_printer_group
	DO_INSTALL_ARGS=$DO_INSTALL_ARGS\ \"--cups=$CUPS_DETECTED\"
	DO_INSTALL_ARGS=$DO_INSTALL_ARGS\ \"--gs=$GS_DETECTED\"
	DO_INSTALL_ARGS=$DO_INSTALL_ARGS\ \"--sane=$SANE_DETECTED\"
	DO_INSTALL_ARGS=$DO_INSTALL_ARGS\ \"--printer-group=$PRINTER_GROUP\"
fi

if ! [ "$TEXTMODE" ]; then

	define_guiexec_file_depends_on_qt 

	## check display
	if ! "$GUIEXEC" --check-display >/dev/null 2>&1; then
		echo $(gettext "GUI mode installer execution failed, proceeding in text mode")
		TEXTMODE=1
	fi
fi

if [ "$TEXTMODE" ] ; then
	if [ "$MISSING" ] ; then 
		echo "****  "$(gettext "Can not continue installation")
		echo "****  "$(gettext "Missing packages: $MISSING")
		exit
	fi
	
	PARPORT=1
	if [ "$RUN_MODE" = "$RUN_MODE_INSTALL" ]; then
		APPLICATION="$SCRIPT_DIR/backend.sh -t --qt-mode=$QT_MODE PRINTER_GROUP=$PRINTER_GROUP $@"
	else
		APPLICATION="$SCRIPT_DIR/backend.sh -t -u $@"
	fi

	$APPLICATION
	exit 
fi	

## if UI_MODE = GUI

GUIEXEC_ARGS=$DO_INSTALL_ARGS
if [ "$RUN_MODE" = "$RUN_MODE_UNINSTALL" ] ; then
	if [ "$RUN_FROM" = "$RUN_FROM_DIST" ]; then
		if [ "$QT_MODE" = "$QT_MODE_QT4" ] ; then
			GUIEXEC_ARGS=$GUIEXEC_ARGS\ \"--res=$DIST_DIR/noarch/$SUBDIR_QT4/at_opt/share/ui/guiuninstallui.rcc\"
		else
			GUIEXEC_ARGS=$GUIEXEC_ARGS\ \"--ui=$DIST_DIR/noarch/$SUBDIR_QT3/at_opt/share/ui/uninstalldialogbase.ui\"
		fi
	fi
fi


# When launched from distribution area add distribution binary dir to the PATH. shhv may be run from guiinstall or guiuninstall.
if [ "$RUN_FROM" = "$RUN_FROM_DIST" ]; then
	export PATH="$DIST_DIR/$HARDWARE_PLATFORM/$SUBDIR_QT/at_opt/bin:$PATH"
fi	

BACKEND="$SCRIPT_ABS_PATH/backend.sh"
BACKEND_ARGS=
if [ "$RUN_MODE" = "$RUN_MODE_UNINSTALL" ]; then
	BACKEND_ARGS="-u"
fi

unset DBUS_SESSION_BUS_ADDRESS

log_message "launching GUIEXEC: <$GUIEXEC|$GUIEXEC_ARGS|$BACKEND|$BACKEND_ARGS>"
eval \"$GUIEXEC\" $GUIEXEC_ARGS -- \"$BACKEND\" $BACKEND_ARGS >/tmp/guiinstall_$(id -un)_log 2>&1