getFirefox 44.1 KB
Newer Older
Kyodev's avatar
Kyodev committed
1
#!/bin/bash
kyodev's avatar
kyodev committed
2

kyodev's avatar
kyodev committed
3 4
version=4.26.0
date="03/07/2018"
Kyodev's avatar
Kyodev committed
5
script="getFirefox"
kyodev's avatar
kyodev committed
6
#contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getFirefox/issues"
Kyodev's avatar
Kyodev committed
7

Kyodev's avatar
Kyodev committed
8
##### license LPRAB/WTFPL
kyodev's avatar
kyodev committed
9
#  auteur: sdeb
Kyodev's avatar
Kyodev committed
10
#    contributeurs: kyodev
Kyodev's avatar
Kyodev committed
11 12
#####

Kyodev's avatar
Kyodev committed
13 14 15
	# détection architecture système, assigne $fu_archi: linux|linux64
	# return 1 on unknown architecture
	# remarque, debian: dpkg --print-architecture affiche i386
kyodev's avatar
kyodev committed
16
f__architecture(){		# 09/O6/2018  SPÉCIFIQUE
Kyodev's avatar
Kyodev committed
17

Kyodev's avatar
Kyodev committed
18
	case "$(uname -m)" in
kyodev's avatar
kyodev committed
19 20
		amd64 | x86_64 ) 	fu_archi="linux64";;
		i?86 | x86 )		fu_archi="linux";;
Kyodev's avatar
Kyodev committed
21 22 23
		* )
			case "$(getconf LONG_BIT)" in
				64 )
Kyodev's avatar
Kyodev committed
24
					fu_archi="linux64";;
Kyodev's avatar
Kyodev committed
25
				32 )
Kyodev's avatar
Kyodev committed
26
					fu_archi="linux";;
Kyodev's avatar
Kyodev committed
27 28 29 30 31 32
				*)
					return 1
			esac ;;
	esac
}

Kyodev's avatar
Kyodev committed
33
	# test validité archive, $1 archive, assigne $archive_detect (gzip|xz|deb|zip), return 1 si inconnue
kyodev's avatar
kyodev committed
34 35
f__archive_test(){		# 13/06/2018
	local filetest test
Kyodev's avatar
Kyodev committed
36

kyodev's avatar
kyodev committed
37
	filetest=$( file -b "$1" )
kyodev's avatar
kyodev committed
38 39 40 41 42 43 44 45 46 47
	test=${filetest/*gzip compressed data*/1234567890}
	[ "$test" == "1234567890" ] && archive_detect="gzip"
	test=${filetest/*bzip2 compressed data*/1234567890}
	[ "$test" == "1234567890" ] && archive_detect="bzip2"
	test=${filetest/*binary compressed data*/1234567890}
	[ "$test" == "1234567890" ] && archive_detect="deb"
	test=${filetest/*Zip compressed data*/1234567890}
	[ "$test" == "1234567890" ] && archive_detect="Zip"
	test=${filetest/*XZ compressed data*/1234567890}
	[ "$test" == "1234567890" ] && archive_detect="XZ"
kyodev's avatar
kyodev committed
48
	if [[ -z "$archive_detect" || "$archive_detect" == "empty" ]]; then return 1; fi
Kyodev's avatar
Kyodev committed
49 50
}

kyodev's avatar
kyodev committed
51
# shellcheck disable=SC2034
kyodev's avatar
kyodev committed
52
f__color(){		# 29/05/2018
Kyodev's avatar
Kyodev committed
53

kyodev's avatar
kyodev committed
54
	if type -p tput &>/dev/null && tput setaf 1 &>/dev/null; then
kyodev's avatar
kyodev committed
55
		MAGENTA=$( tput setaf 5 )
kyodev's avatar
kyodev committed
56
		  BLACK=$( tput setaf 0 )
kyodev's avatar
kyodev committed
57
		   CYAN=$( tput setaf 6 )
kyodev's avatar
kyodev committed
58
		 YELLOW=$( tput setaf 3 )		# question
kyodev's avatar
kyodev committed
59
		  GREEN=$( tput setaf 2 )		# ok
kyodev's avatar
kyodev committed
60
		   BLUE=$( tput setaf 4 )		# info
kyodev's avatar
kyodev committed
61
			RED=$( tput setaf 1 )		# alerte
kyodev's avatar
kyodev committed
62 63 64 65 66
			STD=$( tput sgr0 )			# retour "normal"
		BOLD=$( tput bold )
		ITAL=$( tput sitm )
		SOUL=$( tput smul )
	else 
kyodev's avatar
kyodev committed
67 68 69 70 71
		YELLOW=$'\033[0;33m'		# ?
		 GREEN=$'\033[0;32m'		# ok
		  BLUE=$'\033[0;34m'		# info
		   RED=$'\033[0;31m'		# alerte
		   STD=$'\033[0m'			# standard
kyodev's avatar
kyodev committed
72
	fi
Kyodev's avatar
Kyodev committed
73 74
}

Kyodev's avatar
Kyodev committed
75
	# affichage $1 en rouge, $1++ optionnels en bleu, sortie script sur erreur, log $1 si $operation=upgrade
kyodev's avatar
kyodev committed
76
f__error(){		# 07/O6/2018
Kyodev's avatar
Kyodev committed
77 78
	local depart=1 i

kyodev's avatar
kyodev committed
79
	echo -e "\\n$RED  $script $version, erreur critique: $1 $STD" >&2
Kyodev's avatar
Kyodev committed
80
	for (( i=2 ; i<=$# ; i++ )); do
kyodev's avatar
kyodev committed
81
		echo -e "  $BLUE${!i}$STD" >&2
Kyodev's avatar
Kyodev committed
82 83
	done
	echo
Kyodev's avatar
Kyodev committed
84
	[ "$operation" == "upgrade" ] && f__log "$script $version: $1"
Kyodev's avatar
Kyodev committed
85 86 87
	exit 1
}

Kyodev's avatar
Kyodev committed
88
	# affichage en bleu, si $1=raw pas de ligne vide à la fin, si $1=log alors uniquement $2 logué, combiné: $1="log:raw"
kyodev's avatar
kyodev committed
89 90
f__info(){		# 07/06/2018
	local depart=1 log i
Kyodev's avatar
Kyodev committed
91

kyodev's avatar
kyodev committed
92 93 94 95
	if [[ "$1" =~ "raw"  ||  "$1" =~ "log" ]]; then
		depart=2
	fi
	if [[ "$1" =~ "log" ]]; then
kyodev's avatar
kyodev committed
96 97 98 99 100
		log="$2"
		log=${log//$'\t'}
		log=${log//$'\n'}
		f__trim log
		f__log "$log"
kyodev's avatar
kyodev committed
101
	fi
kyodev's avatar
kyodev committed
102
	for (( i=depart ; i<=$# ; i++ )); do
Kyodev's avatar
Kyodev committed
103 104
		echo -e "  $BLUE${!i}$STD"
	done
Kyodev's avatar
Kyodev committed
105
	[[ "$1" =~ raw ]] || echo 
Kyodev's avatar
Kyodev committed
106 107
}

Kyodev's avatar
Kyodev committed
108
	# log spécifique, fichier log limité à 10000 octets, $1 message à loguer
kyodev's avatar
kyodev committed
109
f__log(){		# 05/03/2018
Kyodev's avatar
Kyodev committed
110 111

	if [ -w "$script_logs" ];  then 
kyodev's avatar
kyodev committed
112
		if [ "$( stat -c %s  "$script_logs" )" -ge "10000" ]; then
Kyodev's avatar
Kyodev committed
113
			echo "$(date +%Y%m%d\ %H%M%S) $1"  &>/dev/null > "$script_logs"
Kyodev's avatar
Kyodev committed
114
		else 
Kyodev's avatar
Kyodev committed
115
			echo "$(date +%Y%m%d\ %H%M%S) $1"  &>/dev/null >> "$script_logs"
Kyodev's avatar
Kyodev committed
116
		fi
Kyodev's avatar
Kyodev committed
117 118 119
	fi
}

kyodev's avatar
kyodev committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
	# $1 file, [$2=n|l] (si vide, last line)
f__read_file(){		# 13/06/2018
	local i=1 no

	case $2 in 
		l | last ) no=0 ;;
		*        ) no=$(( $2 )) ;;
	esac
	while read -r; do
		(( i >= no )) && break
		(( i++ ))
	done < "$1"
	echo "$REPLY"
}

kyodev's avatar
kyodev committed
135 136
	# recherche commandes/paquets, $1 liste: cmd1|cmd2[>paquet] (séparées par espaces) ex: "gawk|mawk>gawk wget"
	# si manque, return 1 & affiche commandes manquantes (si debian, ajout proposition paquet à installer)
kyodev's avatar
kyodev committed
137 138 139 140
	# requiert f__sort_uniq
f__requis(){		# 30/06/2018
	local ENV_DEBIAN c_echo ireq cmds package commands command 
	local commandsMissing packagesMissing t_commandsMissing t_packagesMissing
kyodev's avatar
kyodev committed
141

kyodev's avatar
kyodev committed
142 143 144 145 146 147 148 149
	if type -p dpkg &>/dev/null ; then
		ENV_DEBIAN="oui"							# debian
	fi
	if type -t f__info &>/dev/null; then
		c_echo="f__info"
	else
		c_echo="echo -e"					# f__info existe? sinon echo
	fi
kyodev's avatar
kyodev committed
150 151
	for ireq in $1; do
		IFS='>' read -r cmds package <<< "$ireq"			# ex: "awk|gawk>gawk wget file tar killall>psmisc"
kyodev's avatar
kyodev committed
152 153 154
		IFS='|' read -ra commands <<< "${cmds}"
		[ -z "$package" ] && package=${commands[0]}	# pas de packages dans les options, donc = commands[0]
		unset t_commandsMissing t_packagesMissing
kyodev's avatar
kyodev committed
155
		for command in "${commands[@]%$'\n'}"; do
kyodev's avatar
kyodev committed
156
			if type -p "$command" &>/dev/null ; then
kyodev's avatar
kyodev committed
157
				unset t_commandsMissing t_packagesMissing
kyodev's avatar
kyodev committed
158 159
				break
			else	# inexistant
kyodev's avatar
kyodev committed
160 161
				t_commandsMissing+="$command "
				t_packagesMissing="$package "
kyodev's avatar
kyodev committed
162 163
			fi
		done
kyodev's avatar
kyodev committed
164 165
		[ "$t_commandsMissing" ] && commandsMissing+="$t_commandsMissing "
		[ "$t_packagesMissing" ] && packagesMissing+="$t_packagesMissing "
Kyodev's avatar
Kyodev committed
166
	done
kyodev's avatar
kyodev committed
167

kyodev's avatar
kyodev committed
168 169 170 171
		# dédoublonnage & tri
	commandsMissing=$( f__sort_uniq "$commandsMissing" )
	packagesMissing=$( f__sort_uniq "$packagesMissing" )

kyodev's avatar
kyodev committed
172 173
		# affichage final
	if [ "$commandsMissing" ] && [ "$ENV_DEBIAN" ]; then
kyodev's avatar
kyodev committed
174 175
		$c_echo "${RED}erreur critique, manquant: $STD$BOLD$commandsMissing$STD" \
						"vous devriez exécuter:$GREEN apt install $packagesMissing$STD"
kyodev's avatar
kyodev committed
176
	elif [ "$commandsMissing" ]; then
kyodev's avatar
kyodev committed
177
		$c_echo "${RED}erreur critique, manquant: $STD$BOLD$commandsMissing$STD"
kyodev's avatar
kyodev committed
178 179 180
	fi

	[ "$commandsMissing" ] && return 1 || return 0
Kyodev's avatar
Kyodev committed
181 182
}

kyodev's avatar
kyodev committed
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
	# options: liste à trier [-lf], affiche flat liste (\n enlevés en sortie) ou si -ln  liste avec \n à chaque ligne
	# des caractères non permis =$/`... sont transformés en ø
f__sort_uniq(){		# 02/07/2018
	local lf list array result item

	while (( $# )) ; do
		case "$1" in
			-lf ) lf='yes' ;;
			 * ) list=${1} ;;
		esac
		shift
	done

	while read -r ; do		# lecture ligne
		[ -z "$REPLY" ] && continue
		REPLY=${REPLY# } 		# trim gauche simple
		REPLY=${REPLY% }		# trim droite simple
		REPLY=${REPLY// /\~}	# espace remplacé avec ~
			# interdits/remplacés: ()/`;      ø utilisé comme indicateur, ~ remplacé pas espace
		REPLY=${REPLY//[^a-zA-Z0-9~.,\{\}!\[\]#*%µ£°⇉:_+-]/ø}	# caractère <> de autorisé remplacés par ø 
		if [ "$lf" ]; then
			array+=( "${REPLY}" )
		else
			IFS='~' read -ra array <<< "$REPLY"
		fi
	done <<< "${list}"

	result=$(
		for item in "${array[@]}"; do
			eval "alias ${item}=ls"
		done
		alias
	)
	result=${result//alias }
	result=${result//=\'ls\'}
	result=${result//\~/ }
	[ "$lf" ] && echo "${result}" || echo "${result//$'\n'/ }"
}

kyodev's avatar
kyodev committed
222 223
	# $@=cmd à lancer en root avec su ou sudo. si sudo possible: prioritairesu su
f__sudo(){		# 11/06/2018
Kyodev's avatar
Kyodev committed
224

Kyodev's avatar
Kyodev committed
225
	if sudo -v &>/dev/null && [ $EUID -ne 0 ] ; then
kyodev's avatar
kyodev committed
226
		sudo su --preserve-environment -c "$@"
kyodev's avatar
kyodev committed
227
	else
kyodev's avatar
kyodev committed
228 229
		echo -n "[su]   "
		su --preserve-environment -c "$@"
kyodev's avatar
kyodev committed
230
	fi
Kyodev's avatar
Kyodev committed
231 232
}

kyodev's avatar
kyodev committed
233 234 235 236 237 238 239 240 241
	# $1=NOM de la variable à trimer (variable et non $variable), [$2=left|right|all], all si vide
f__trim(){		# 07/03/2018
	local trim=${!1}

	[[ "$2" == right || "$2" == all || -z "$2" ]] && trim="${trim%${trim##*[^[:space:]]}}"		# fin right
	[[ "$2" == left  || "$2" == all  || -z "$2" ]] && trim="${trim#${trim%%[^[:space:]]*}}"		# début left
	eval "$1=\"$trim\""
}

Kyodev's avatar
Kyodev committed
242
	# user ayant initié la session graphique, assigne $fu_user
Kyodev's avatar
Kyodev committed
243
	# return 1 sur échec identification user, return 2 sur absence home/
Kyodev's avatar
Kyodev committed
244
	# gestion variable environnement user avec: USER_INSTALL=<user> script
kyodev's avatar
kyodev committed
245 246
f__user(){		# 08/03/2018
	local user userid root_login
Kyodev's avatar
Kyodev committed
247

Kyodev's avatar
Kyodev committed
248
	root_login="$(grep ':0:' /etc/passwd | cut -d':' -f1)" || root_login="root"
Kyodev's avatar
Kyodev committed
249 250
	if [ "$USER_INSTALL" ]; then 	# user via variable environnement, moyen d'injecter root si pb 
		fu_user="$USER_INSTALL"; 
Kyodev's avatar
Kyodev committed
251
		return 0
Kyodev's avatar
Kyodev committed
252 253
	elif [[ "$TERM" =~ linux ]]; then	#debian 9 recovery ou nomodeset TERM=linux
		if [ "$USER" ]; then
Kyodev's avatar
Kyodev committed
254
			user="$USER"
Kyodev's avatar
Kyodev committed
255
		elif [ "$EUID" -eq 0 ]; then
Kyodev's avatar
Kyodev committed
256
			fu_user="$root_login"
Kyodev's avatar
Kyodev committed
257 258
			return 0
		fi
Kyodev's avatar
Kyodev committed
259
	fi
Kyodev's avatar
Kyodev committed
260
	if [ "$SUDO_UID" ]; then 
Kyodev's avatar
Kyodev committed
261
		userid="$SUDO_UID"; 
Kyodev's avatar
Kyodev committed
262
	elif grep -qEo '[0-9]+' <<< "$XDG_RUNTIME_DIR" ; then 
kyodev's avatar
kyodev committed
263
		userid=$( grep -Eo '[0-9]+' <<< "$XDG_RUNTIME_DIR" | cut -d'/' -f4 )
kyodev's avatar
kyodev committed
264
	else
kyodev's avatar
kyodev committed
265
		userid=$( grep -Eo '[0-9]+' <<< "$XAUTHORITY" | cut -d'/' -f4 )
Kyodev's avatar
Kyodev committed
266
	fi
kyodev's avatar
kyodev committed
267
	[ "$userid" ] && user=$( grep "$userid" /etc/passwd | cut -d ":" -f 1 )
Kyodev's avatar
Kyodev committed
268 269
	if [ "$user" ] && [ "$user" != "$root_login" ]; then
		fu_user="$user"
Kyodev's avatar
Kyodev committed
270 271 272
		return 0
	else
		if [ "$SUDO_USER" ] && [ "$SUDO_USER" != "$root_login" ]; then 
Kyodev's avatar
Kyodev committed
273
			user="$SUDO_USER"; 
kyodev's avatar
kyodev committed
274 275
		elif who | grep -qv 'root'; then 
			user=$( who | grep -v 'root' | head -n1 | cut -d ' ' -f1 );	# who | grep -v 'root' | awk 'FNR==1{print $1}'
kyodev's avatar
kyodev committed
276 277
		else
			user=$( grep -m1 'hourly.*get[A-Z].*\.anacrontab.*\.config/anacron/spool' /etc/crontab | cut -d' ' -f2 );
Kyodev's avatar
Kyodev committed
278
		fi
Kyodev's avatar
Kyodev committed
279
	fi
Kyodev's avatar
Kyodev committed
280 281 282
	fu_user="$user"
	[ "$fu_user" ] || return 1
	[ -d "/home/$fu_user" ] || return 2
Kyodev's avatar
Kyodev committed
283
	return 0
Kyodev's avatar
Kyodev committed
284 285
}

Kyodev's avatar
Kyodev committed
286 287
	# test wget, $1=url à tester, $2=''|print|loc|test
	# par défaut, sortie du script (même si url testée ok) avec affichage erreur ou ok
Kyodev's avatar
Kyodev committed
288 289 290
	# si $2=print affiche url testée & entêtes http & location, return 0
	# si $2=loc affiche seulement location, return 0
	# si $2=test return 0 si ok, return 1 si KO
kyodev's avatar
kyodev committed
291
f__wget_test(){		# 07/06/2018
Kyodev's avatar
Kyodev committed
292
	local file_test_wget="/tmp/testWget-$script" retourWget retourHttp location
Kyodev's avatar
Kyodev committed
293

Kyodev's avatar
Kyodev committed
294
	wget -Sq --timeout=5 --tries=2 --user-agent="$user_agent" --spider --save-headers "$1" &>"$file_test_wget"
Kyodev's avatar
Kyodev committed
295
	retourWget="$?"
Kyodev's avatar
Kyodev committed
296 297 298 299 300 301 302 303
	[ "$retourWget" == 1 ] && retourWget="1: code erreur générique"
	[ "$retourWget" == 2 ] && retourWget="2: parse erreur (ligne de commande?)"
	[ "$retourWget" == 3 ] && retourWget="3: erreur Entrée/sortie fichier"
	[ "$retourWget" == 4 ] && retourWget="4: défaut réseau"
	[ "$retourWget" == 5 ] && retourWget="5: défaut vérification SSL"
	[ "$retourWget" == 6 ] && retourWget="6: défaut authentification"
	[ "$retourWget" == 7 ] && retourWget="7: erreur de protocole"
	[ "$retourWget" == 8 ] && retourWget="8: réponse serveur en erreur"
kyodev's avatar
kyodev committed
304 305 306 307
	retourHttp=$( grep -i 'HTTP/' "$file_test_wget" | tr -d '\n' )
	f__trim retourHttp
	location=$( grep -i 'location' $file_test_wget )
	f__trim location
Kyodev's avatar
Kyodev committed
308
	if [ "$2" == "test" ]; then
Kyodev's avatar
Kyodev committed
309
		rm -f "$file_test_wget"
Kyodev's avatar
Kyodev committed
310
			# spécial maintenance frama.link, pas de redirection sur page status framalink
kyodev's avatar
kyodev committed
311
		grep -q '303' <<< "$retourHttp" && return 1			# 303 See Other
Kyodev's avatar
Kyodev committed
312 313
		[ "$retourWget" == "0" ] && return 0 || return 1
	fi
Kyodev's avatar
Kyodev committed
314
	if [ "$2" == "print" ]; then
Kyodev's avatar
Kyodev committed
315
		if [ "$retourWget" != "0" ]; then
kyodev's avatar
kyodev committed
316
			echo "  erreur wget: erreur $RED$retourWget" 
kyodev's avatar
kyodev committed
317
			echo -e "$BLUE  $1$STD\\t$RED  $retourHttp$STD"
Kyodev's avatar
Kyodev committed
318
		else
kyodev's avatar
kyodev committed
319
			echo -e "$BLUE  $1$STD\\t$GREEN  $retourHttp$STD" 
Kyodev's avatar
Kyodev committed
320 321
		fi
	fi
Kyodev's avatar
Kyodev committed
322
	if [ "$2" == "print" ] || [ "$2" == "loc" ]; then
kyodev's avatar
kyodev committed
323
		[ "$location" ] && echo -n "$YELLOW  $location" || echo -n "$YELLOW  no location"
Kyodev's avatar
Kyodev committed
324
		echo "$STD"
Kyodev's avatar
Kyodev committed
325
		rm -f "$file_test_wget"
Kyodev's avatar
Kyodev committed
326
		return 0
Kyodev's avatar
Kyodev committed
327
	fi
Kyodev's avatar
Kyodev committed
328
	if [ "$retourWget" != "0" ]; then
Kyodev's avatar
Kyodev committed
329
		rm -f "$file_test_wget"
Kyodev's avatar
Kyodev committed
330
		f__error "wget, erreur $retourWget" "$1" "$YELLOW$retourHttp" "$location"
kyodev's avatar
kyodev committed
331
		echo -e "$RED   erreur wget, $retourWget \\n  $1 \\n  $YELLOW$retourHttp \\n  $location$STD" # pour les diags
Kyodev's avatar
Kyodev committed
332
		return 1
Kyodev's avatar
Kyodev committed
333
	fi
kyodev's avatar
kyodev committed
334
	if grep -q '200' <<< "$retourHttp"; then 
kyodev's avatar
kyodev committed
335
		echo -e "$GREEN\\ntout est ok, réessayer$STD\\n"
Kyodev's avatar
Kyodev committed
336
	fi
Kyodev's avatar
Kyodev committed
337
	rm -f "$file_test_wget"
Kyodev's avatar
Kyodev committed
338
	exit 0
Kyodev's avatar
Kyodev committed
339 340
}

kyodev's avatar
kyodev committed
341 342
# shellcheck disable=SC1117
f_affichage(){		# 07/06/2018
Kyodev's avatar
Kyodev committed
343

kyodev's avatar
kyodev committed
344 345
	(( x_logo == 1 )) && return
	x_logo=1
kyodev's avatar
kyodev committed
346 347 348 349 350 351 352 353 354 355 356
	clear 2>/dev/null || tput clear 2>/dev/null
	echo -n "$BLUE"
	cat <<- end
	              _   _____ _           __ 
	    __ _  ___| |_|  ___(_)_ __ ___ / _| _____  __ 
	   / _' |/ _ \ __| |_  | | '__/ _ \ |_ / _ \ \/ / 
	  | (_| |  __/ |_|  _| | | | |  __/  _| (_) >  <  
	   \__, |\___|\__|_|   |_|_|  \___|_|  \___/_/\_\ 
	   |___/  ${YELLOW}version $version - $date$STD

	end
Kyodev's avatar
Kyodev committed
357 358
}

Kyodev's avatar
Kyodev committed
359
	# affichage help
kyodev's avatar
kyodev committed
360
f_help(){		# 11/06/2018
Kyodev's avatar
Kyodev committed
361

kyodev's avatar
kyodev committed
362
	tput cuu1						# une ligne plus haut
kyodev's avatar
kyodev committed
363
	cat <<- end
kyodev's avatar
kyodev committed
364 365 366

		      canaux possibles:$GREEN latest, beta, nightly, dev, esr$STD ( <all> = tous les canaux sauf dev )
		  
kyodev's avatar
kyodev committed
367
		  exemple, installation version Release (latest): $BLUE$script i-latest$STD
kyodev's avatar
kyodev committed
368 369 370 371 372 373 374 375
		  ----------------------------------------------------------------------
		  $BLUE$script i-$STD${GREEN}canal       :$STD ${RED}i${STD}nstallation de $appli <canal> $RED(root)$STD
		  $BLUE$script d-$STD${GREEN}canal       :$STD copier un éventuel profil ${RED}.d${STD}efault existant sur <canal>
		  $BLUE$script m-$STD${GREEN}canal archi :$STD installation sur le <canal> d'une <archi>ve téléchargée ${RED}m${STD}anuellement $RED(root)$STD
		  $BLUE$script r-$STD${GREEN}canal       :$STD désinstallation (${RED}r${STD}emove) du <canal> $RED(root)$STD
		  $BLUE$script ri$STD${GREEN}            :$STD ${RED}r${STD}éparation$RED i${STD}cône(s) et lanceur(s) dans le menu $RED(root)$STD
		  $BLUE$script t-$STD${GREEN}canal       :$STD téléchargement du <canal> dans le répertoire courant (sans installation)
		  $BLUE$script u-$STD${GREEN}canal       :$STD profil pour l'${RED}u${STD}tilisateur en cours et comme défaut système $RED(root)$STD
kyodev's avatar
kyodev committed
376
		
kyodev's avatar
kyodev committed
377 378 379
		  $BLUE$script p-$STD${GREEN}canal       :$STD ${RED}p${STD}ersonnalisation sur le <canal> de user.js & userChrome.css
		  $BLUE$script pr-$STD${GREEN}canal      :$STD suppression des ${RED}p${STD}ersonnalisations (${RED}r${STD}emove) sur le <canal>
		  $BLUE$script pu            :$STD mise à jour des ${RED}p${STD}ersonnalisations (${RED}u${STD}pdate) installées
kyodev's avatar
kyodev committed
380
		
kyodev's avatar
kyodev committed
381 382 383 384
		  $BLUE$script version       :$STD versions installées et en ligne
		  
		  $GREEN  --dev   :$STD une version de dev du script (si existante) est recherchée
		  $GREEN  --sauve :$STD le téléchargement est sauvegardé dans le répertoire courant ${BOLD}en$STD plus de l'installation
kyodev's avatar
kyodev committed
385 386 387 388 389 390 391 392 393 394 395
		  ----------------------------------------------------------------------
		  $BLUE./$script$STD (ou $BLUE./$script -i$STD) : installation du script dans le système $RED(root)$STD
		  $BLUE$script -h$STD, --help    : affichage aide
		  $BLUE$script -r$STD, --remove  : désinstallation du script $RED(root)$STD
		  $BLUE$script -u$STD, --upgrade : mise à jour du script
		  $BLUE$script -v$STD, --version : version du script
		
		  ${STD}plus d'infos: $GREEN$url_notice${STD}
		  ${STD}Tor Browser, voir getXfox:${YELLOW} https://framaclic.org/h/doc-getxfox${STD}
		
	end
Kyodev's avatar
Kyodev committed
396 397
}

Kyodev's avatar
Kyodev committed
398
	# traitement utilisateur(profiles.ini), $1=canal,  [$2='menu'] si appel indépendant pour reconfiguration
kyodev's avatar
kyodev committed
399
ffx_config_profil(){		# 07/06/2018
kyodev's avatar
kyodev committed
400
	local nbProfiles canal="$1"
Kyodev's avatar
Kyodev committed
401

Kyodev's avatar
Kyodev committed
402
	if [ ! -d "$dirInstallFfx$canal" ] && [ "$2" == "menu" ]; then	# pas de répertoire programme
Kyodev's avatar
Kyodev committed
403
		f__info "$appli $canal n'est pas installé"
Kyodev's avatar
Kyodev committed
404
		exit 1
Kyodev's avatar
Kyodev committed
405
	fi
Kyodev's avatar
Kyodev committed
406 407 408 409 410 411 412

	if [ ! -d "$dirProfilFfx/$canal" ] ; then						# pas de répertoire profil
		mkdir -p "$dirProfilFfx/$canal"									# répertoire du répertoire profil
		chown -R "$fu_user:" "$dirProfilFfx/$canal/"					# propriété du répertoire profil à l'user
		chmod g-rx,o-rx "$dirProfilFfx/$canal/"							# droits répertoire
	fi
	if [ ! -e "$dirProfilFfx/profiles.ini" ]; then 					# pas de profile.ini
kyodev's avatar
kyodev committed
413
		echo -e "[General]\\nStartWithLastProfile=1" > "$dirProfilFfx/profiles.ini"
Kyodev's avatar
Kyodev committed
414 415 416 417
		chown "$fu_user:" "$dirProfilFfx/profiles.ini"					# propriété du fichier profile.ini à l'user
		chmod u+rw,go+r "$dirProfilFfx/profiles.ini"					# permissions du fichier profile.ini à l'user
	fi
		# inscription canal dans profil.ini, à la fin, si inexistant
Kyodev's avatar
Kyodev committed
418
	if ! grep -q "Name=$canal" "$dirProfilFfx/profiles.ini" ; then
Kyodev's avatar
Kyodev committed
419
			# comptage profils existants
Kyodev's avatar
Kyodev committed
420 421
		nbProfiles=$( grep -cEs '\[Profile[0-9]+\]' "$dirProfilFfx/profiles.ini" )
			# création profil dans profile.ini
kyodev's avatar
kyodev committed
422 423 424 425 426 427 428
		{
			echo 
			echo "[Profile$nbProfiles]"
			echo "Name=$canal"
			echo "IsRelative=1"
			echo "Path=$canal"
		} >> "$dirProfilFfx/profiles.ini"
Kyodev's avatar
Kyodev committed
429 430
	fi

Kyodev's avatar
Kyodev committed
431
	f__info "log:raw" "profil $appli $canal configuré"
Kyodev's avatar
Kyodev committed
432 433
}

Kyodev's avatar
Kyodev committed
434
	# traitement système: lien /usr/bin & alternatives, $1 canal
kyodev's avatar
kyodev committed
435 436
ffx_config_system(){		# 09/03/2018
	local canal="$1" xbrowser ligne marqueur stockage profileIni="$dirProfilFfx/profiles.ini"
Kyodev's avatar
Kyodev committed
437

Kyodev's avatar
Kyodev committed
438 439
	if [ ! -d "$dirInstallFfx$canal" ]; then
		f__info "$appli $canal n'est pas installé"
Kyodev's avatar
Kyodev committed
440 441 442
		return 1
	fi

Kyodev's avatar
Kyodev committed
443 444
		#lanceurs
	ln -sf "/usr/bin/firefox-$canal" "/usr/bin/firefox"		# lien "lanceur" sur lanceur réel
Kyodev's avatar
Kyodev committed
445
		# update-alternatives
kyodev's avatar
kyodev committed
446
	if type -p update-alternatives &>/dev/null ; then			# update-alternatives existe?
kyodev's avatar
kyodev committed
447 448 449 450 451 452 453
		if type -p x-www-browser &>/dev/null; then			# commande x-www-browser existe ?
			xbrowser=$( type -p x-www-browser 2>/dev/null )		# déjà existant
		else
			xbrowser="/usr/bin/x-www-browser"					# primo install
		fi
		update-alternatives --quiet --install  "$xbrowser" 'x-www-browser' "/usr/bin/firefox-$canal"  100	# nouvelle alternative
		update-alternatives --quiet --set 'x-www-browser' "/usr/bin/firefox-$canal"							# si la priorité n'était pas suffisante
kyodev's avatar
kyodev committed
454
		if type -p gnome-www-browser &>/dev/null; then			# commande gnome-www-browser existe ?
kyodev's avatar
kyodev committed
455
			update-alternatives --quiet --install "$( type -p gnome-www-browser 2>/dev/null )" 'gnome-www-browser' "/usr/bin/firefox-$canal"  100		# nouvelle alternative
kyodev's avatar
kyodev committed
456
			update-alternatives --quiet --set 'gnome-www-browser' "/usr/bin/firefox-$canal"					# si la priorité n'était pas suffisante
kyodev's avatar
kyodev committed
457
		fi
Kyodev's avatar
Kyodev committed
458
	fi
Kyodev's avatar
Kyodev committed
459

Kyodev's avatar
Kyodev committed
460
		# set default=1 dans profiles.ini
Kyodev's avatar
Kyodev committed
461
	while read -r ligne ; do
kyodev's avatar
kyodev committed
462 463 464 465 466 467
		[[ $ligne == "Name=$canal" ]] && marqueur="ok"	# détection canal recherché? marqueur actif
		[[ $ligne == "Default=1" ]] && continue			# si Default existant, on saute, la ligne ne fera donc pas partie de $stockage (=effacement)

		if [ "$marqueur" == "ok" ] && [ -z "$ligne" ]; then		# marqueur actif, première ligne vide rencontrée 
			ligne+="Default=1"$'\n'						# ajout du Default=1
			unset marqueur								# effacement marqueur
Kyodev's avatar
Kyodev committed
468
		fi
kyodev's avatar
kyodev committed
469
		stockage+="$ligne"$'\n'							# stockage lignes brutes ou traitées
Kyodev's avatar
Kyodev committed
470
	done < "$profileIni"
kyodev's avatar
kyodev committed
471 472 473 474
	if [ "$marqueur" == "ok" ]; then	# marqueur encore actif (dernier profil), read ne permet de choper dernière ligne vide
		stockage+="Default=1"							# ajout Default=1
		unset marqueur									# effacement marqueur
	fi
Kyodev's avatar
Kyodev committed
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500
	stockage=${stockage%[[:cntrl:]]}					# suppression dernier saut de ligne superflu

	if type -p uniq &>/dev/null ; then					# si commande uniq dispo
		uniq <<< "$stockage"  > "$profileIni"			# on élimine doublons adjacents (lignes vides éventuelles)
	else
		echo "$stockage" > "$profileIni"
	fi

	f__info "log:raw" "$appli $canal est le défaut système"
}

	# copie du répertoire .default dans canal, $1=canal
ffx_copie_default(){		# 22/12/2017
	local canal="$1" profileDefault

	if [ ! -d "$dirProfilFfx/$canal" ]; then
		f__info "$appli $canal n'a pas de profil et ne peut donc pas recevoir .default"
		return 1
	fi
	profileDefault=$( sed -En 's/Path=(.*\.default).*$/\1/p' "$dirProfilFfx/profiles.ini" )	# recherche profil .default
	if [ -z "$profileDefault" ] || [ ! -d "$dirProfilFfx/$profileDefault" ]; then
		f__info "pas de profil .default existant, opération abandonnée"
		return 1
	fi

	f__info "copie du profil default <$profileDefault> sur $canal"
kyodev's avatar
kyodev committed
501
#	cp -R --preserve "$dirProfilFfx/$profileDefault/"*  "$dirProfilFfx/$canal/"
Kyodev's avatar
Kyodev committed
502 503 504
	cp -R "$dirProfilFfx/$profileDefault/"*  "$dirProfilFfx/$canal/"
	chown -R "$fu_user:" "$dirProfilFfx/$canal/"		# propriété du répertoire profil à l'user
	chmod g-rx,o-rx "$dirProfilFfx/$canal/" 			# droits répertoire
Kyodev's avatar
Kyodev committed
505 506
}

Kyodev's avatar
Kyodev committed
507 508 509
	# détermination canal bas installé, assigne $ffx_canal_bas
ffx_get_canalBas(){		# 18/12/2017
	local ii
Kyodev's avatar
Kyodev committed
510

Kyodev's avatar
Kyodev committed
511
	for ii in $produit_all_inverse; do
Kyodev's avatar
Kyodev committed
512
		[ -d "$dirInstallFfx$ii" ] && ffx_canal_bas="$ii"
Kyodev's avatar
Kyodev committed
513
	done
Kyodev's avatar
Kyodev committed
514
	[ "$ffx_canal_bas" ] && return 0 || return 1
Kyodev's avatar
Kyodev committed
515 516
}

kyodev's avatar
kyodev committed
517 518 519 520
	# version en ligne et installée, [$1=quiet], affichage & assigne :
	# $ver_fx_latest $ver_fx_esr $ver_fx_esr_old $ver_fx_beta $ver_fx_nightly
ffx_get_version(){		# 12/06/2018
	local recup_url ii versOnline versionEsr ver_fx_esr_avertissement verFfxInstall='' verFfxOnline='' pointeur 
Kyodev's avatar
Kyodev committed
521

kyodev's avatar
kyodev committed
522 523
	x_ffx_get_version=1
	[ "$1" != quiet ] && echo -n "  ."
Kyodev's avatar
Kyodev committed
524 525
		# version latest & esr
	recup_url="https://www.mozilla.org/en-US/firefox/notes/"
kyodev's avatar
kyodev committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
	recup_url="https://www.mozilla.org/en-US/firefox/notes/"	# alternatif 
	if versOnline=$( wget -q --tries=2 --timeout=15 --user-agent="$user_agent" -o /dev/null -O - "$recup_url" ); then
		ver_fx_latest=${versOnline#*data-latest-firefox=\"}
		ver_fx_latest=${ver_fx_latest%%\"*}
		versionEsr=${versOnline#*data-esr-versions=\"}
		mapfile -t -d ' ' versionEsr <<< "${versionEsr%%\"*}"
		versionEsr=( "${versionEsr[@]%$'\n'}" )
		if (( ${#versionEsr[@]} > 1 )); then
			ver_fx_esr=${versionEsr[1]}
			ver_fx_esr_old=${versionEsr[0]}
			ver_fx_esr_avertissement="nouvelle version esr"
		else
			ver_fx_esr=${versionEsr[0]}
		fi
	else
kyodev's avatar
kyodev committed
541 542
		f__wget_test "$recup_url"
	fi
kyodev's avatar
kyodev committed
543
	[ "$1" != quiet ] && echo -n "."
Kyodev's avatar
Kyodev committed
544 545
		# version beta
	recup_url="https://download.mozilla.org/?product=firefox-beta-latest&os=linux64&lang=fr"
kyodev's avatar
kyodev committed
546 547 548 549
	if versOnline=$(  wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers -O - "$recup_url" 2>&1); then
		ver_fx_beta=${versOnline#*releases\/}
		ver_fx_beta=${ver_fx_beta%%\/*}
	else
kyodev's avatar
kyodev committed
550 551
		f__wget_test "$recup_url"
	fi
kyodev's avatar
kyodev committed
552
	[ "$1" != quiet ] && echo -n "."
Kyodev's avatar
Kyodev committed
553 554
		# version nightly
	recup_url="https://download.mozilla.org/?product=firefox-nightly-latest-l10n-ssl&os=linux64&lang=fr"
kyodev's avatar
kyodev committed
555 556 557 558
	if versOnline=$(  wget -Sq --tries=1 --timeout=10 --user-agent="$user_agent" --spider --save-headers -O - "$recup_url" 2>&1); then
		ver_fx_nightly=${versOnline#*\/firefox-}
		ver_fx_nightly=${ver_fx_nightly%%\.fr*}
	else
kyodev's avatar
kyodev committed
559 560
		f__wget_test "$recup_url"
	fi
kyodev's avatar
kyodev committed
561 562 563 564 565 566
	[ "$1" == "quiet" ] && return 0
	ver_fx_latest=${ver_fx_latest:="${RED}n/a$STD"}
	ver_fx_esr=${ver_fx_esr:="${RED}n/a$STD"}
	ver_fx_beta=${ver_fx_beta:="${RED}n/a$STD"}
	ver_fx_nightly=${ver_fx_nightly:="${RED}n/a$STD"}
	for ii in $produit_all esr_old; do
Kyodev's avatar
Kyodev committed
567 568
			# versions en ligne
		[ "$ii" == "dev" ] && continue
kyodev's avatar
kyodev committed
569 570
		pointeur="ver_fx_$ii"
		verFfxOnline+=$( printf "%7s: %-7s  " "$ii" "${!pointeur}" )
kyodev's avatar
kyodev committed
571
		[[ "${!pointeur}" != "${RED}n/a" ]] && (( compteur++ ))
Kyodev's avatar
Kyodev committed
572
			# versions installées
Kyodev's avatar
Kyodev committed
573
		if [ -x "$dirInstallFfx$ii/firefox" ]; then
kyodev's avatar
kyodev committed
574
			verFfxInstall+=$( printf "%7s: %-7s  " "$ii" "$( "$dirInstallFfx$ii"/firefox -v | grep -Eo '[0-9].*' )" )
Kyodev's avatar
Kyodev committed
575 576
			(( compteur2++ ))
		else
kyodev's avatar
kyodev committed
577
			verFfxInstall+=$( printf " %.s" $(seq 18) )
Kyodev's avatar
Kyodev committed
578 579
		fi
	done
Kyodev's avatar
Kyodev committed
580

kyodev's avatar
kyodev committed
581 582 583 584 585
	f__trim verFfxInstall
	f__trim verFfxOnline
	verFfxInstall=${verFfxInstall:="Non installé"}
	verFfxOnline=${verFfxOnline:="${RED}n/a$STD"}
	echo -e "\\n"
Kyodev's avatar
Kyodev committed
586 587
	f__info "raw" "$appli en place: $GREEN$verFfxInstall"
	f__info "$appli en ligne: $YELLOW$verFfxOnline"
Kyodev's avatar
Kyodev committed
588 589
}

Kyodev's avatar
Kyodev committed
590
	# ascii art godzilla
kyodev's avatar
kyodev committed
591
# shellcheck disable=SC1117
kyodev's avatar
kyodev committed
592
ffx_godzilla(){		# 11/06/2018
Kyodev's avatar
Kyodev committed
593

Kyodev's avatar
Kyodev committed
594
	echo -n "$RED"
kyodev's avatar
kyodev committed
595
	cat <<- end
kyodev's avatar
kyodev committed
596 597 598 599 600 601 602 603 604 605 606 607 608
	               _.-~-.  
	             7''  Q..\  
	          _7         (_ 
	        _7  _/    _q.  / 
	      _7 . ___  /VVvv-'_                                            . 
	     7/ / /~- \_\\      '-._     .-'                      /       // 
	    ./ ( /-~-/||'=.__  '::. '-~'' {             ___   /  //     ./{ 
	   V   V-~-~| ||   __''_   ':::.   ''~-~.___.-'' _/  // / {_   /  {  / 
		VV/-~-~-|/ \ .'__'. '.    '::                     _ _ _        ''. 
		/ /~~~~||VVV/ /  \ )  \        _ __ ___   ___ ___(_) | | __ _   .::' 
	   / (~-~-~\\.-' /    \'   \::::. | '_ ' _ \ / _ \_  / | | |/ _' | :::' 
	  /..\    /..\__/      '     '::: | | | | | | (_) / /| | | | (_| | ::' 
	  vVVv    vVVv                 ': |_| |_| |_|\___/___|_|_|_|\__,_| '' 
kyodev's avatar
kyodev committed
609
	end
Kyodev's avatar
Kyodev committed
610
	echo "$STD"
Kyodev's avatar
Kyodev committed
611 612
}

Kyodev's avatar
Kyodev committed
613
	# installation, $1 canal [$2='manuel', $3 archive]
kyodev's avatar
kyodev committed
614
ffx_install(){		# 12/06/2018
kyodev's avatar
kyodev committed
615
	local fxVersion fileTemp canal="$1" versArchive appli="firefox"  dirTemp="/tmp/$script-install_ffx"
Kyodev's avatar
Kyodev committed
616

Kyodev's avatar
Kyodev committed
617
	if [ "$2" == "manuel" ]; then
kyodev's avatar
kyodev committed
618 619 620 621
		versArchive=${3%\.linux*}		# ../../../kyopages/scripts/dl/firefox-58.0b16_nightly.linux64.tar.bz2
		versArchive=${versArchive%_*}
		versArchive=${versArchive##*-}
		f__info raw "installation manuelle dans $canal de $appli version $versArchive ($3)"
Kyodev's avatar
Kyodev committed
622
		fileTemp="$3"
root's avatar
root committed
623
	else
kyodev's avatar
kyodev committed
624 625 626 627
		if ! mkdir -p "$dirTemp" 2>/dev/null; then		# contournement bug? bash, utile si téléchargement et mauvais effacement précédent
			dirTemp+="-$RANDOM"
			! mkdir -p "$dirTemp" 2>/dev/null && f__error "droits insuffisants, recommencer avec les droits root"
		fi
kyodev's avatar
kyodev committed
628 629 630 631 632 633 634 635 636 637 638 639 640
		[ -z "$dl_only" ] && f__info "installation $appli-$canal"
		(( x_ffx_get_version == 1 )) || ffx_get_version quiet
		case "$1" in
			latest  ) fxVersion="$ver_fx_latest"  ;;
			beta    ) fxVersion="$ver_fx_beta"    ;;
			nightly ) fxVersion="$ver_fx_nightly" ;;
			esr     ) fxVersion="$ver_fx_esr"
				[ "$ver_fx_esr_avertissement" ] && f__info raw "nouvelle version ESR, avec de possibles points de non-retour" \
				"appuyer sur une touche pour continuer"
				read -n1 -rs ;;
			esr_old ) fxVersion="$ver_fx_esr_old" ;;
		esac
		fileTemp="$dirTemp/${appli,,}-${fxVersion}_$canal.$fu_archi.tar.bz2"
kyodev's avatar
kyodev committed
641

root's avatar
root committed
642
		f__info "  - téléchargement..."
kyodev's avatar
kyodev committed
643
			# calcul url
kyodev's avatar
kyodev committed
644 645 646 647 648 649 650 651 652 653
		case "$canal" in
			latest     ) recup_url="https://download.mozilla.org/?product=firefox-$canal&os=$fu_archi&lang=fr" ;;
			esr | beta ) recup_url="https://download.mozilla.org/?product=firefox-$canal-latest&os=$fu_archi&lang=fr" ;;
			dev        ) recup_url="https://download.mozilla.org/?product=firefox-$canal""edition-latest-ssl&os=$fu_archi&lang=fr" ;;
			nightly    ) recup_url="https://download.mozilla.org/?product=firefox-$canal-latest-l10n-ssl&os=$fu_archi&lang=fr" ;;
		esac
			# téléchargement
		if ! wget -q -c --show-progress --tries=2 --timeout=15 --user-agent="$user_agent" \
			-o /dev/null -O "$fileTemp" "$recup_url" ; then
					f__wget_test "$recup_url"
kyodev's avatar
kyodev committed
654
		fi
root's avatar
root committed
655
	fi
Kyodev's avatar
Kyodev committed
656 657
	f__archive_test "$fileTemp" || f__error "Le fichier $fileTemp n'est pas une archive tar.gz valide"
	echo
kyodev's avatar
kyodev committed
658

kyodev's avatar
kyodev committed
659 660 661 662 663
	if [[ "$dl_to_svg" || "$dl_only" ]]; then
		chown "$fu_user:" "$fileTemp"
		cp --preserve "$fileTemp" ./
	fi
	if [ "$dl_only" ]; then
kyodev's avatar
kyodev committed
664
		rm -f "$fileTemp"
kyodev's avatar
kyodev committed
665 666 667 668 669
		echo
		return 0
	fi

	# décompression archive téléchargée dans dossier de travail
root's avatar
root committed
670
	f__info " - décompression..."
Kyodev's avatar
Kyodev committed
671
	tar -xaf "$fileTemp" -C "$dirTemp/"
Kyodev's avatar
Kyodev committed
672

Kyodev's avatar
Kyodev committed
673 674
		# mise en place finale
	f__info " - installation..."
kyodev's avatar
kyodev committed
675 676
	rm -fr "/opt/firefox-$canal"		# effacement ancien répertoire éventuel
	rm -fr "$dirInstallFfx$canal"		# effacement éventuel répertoire existant
Kyodev's avatar
Kyodev committed
677 678 679 680
	mkdir -p "$dirInstallFfx$canal"
	mv -f "$dirTemp/firefox/"* "$dirInstallFfx$canal/"
	chown -R "$fu_user:" "$dirInstallFfx$canal/"
	chmod -R g+wrs,a+r "$dirInstallFfx$canal/"
kyodev's avatar
kyodev committed
681
		# effacement répertoire temporaire
kyodev's avatar
kyodev committed
682
	rm -fr "$dirTemp"
Kyodev's avatar
Kyodev committed
683 684 685 686

		# traitement finaux système
	ln -sf "$dirInstallFfx$canal/browser/chrome/icons/default/default48.png" "/usr/share/pixmaps/firefox-$canal.png"
	ffx_lanceur_desktop "$canal"
Kyodev's avatar
Kyodev committed
687 688
		# suppression liens lanceurs éventuels
	unlink "/usr/bin/firefox-$canal" &>/dev/null
Kyodev's avatar
Kyodev committed
689
	unlink "/usr/bin/firefox" &>/dev/null
Kyodev's avatar
Kyodev committed
690
		# lanceur dans /usr/bin
kyodev's avatar
kyodev committed
691
	echo "#!/bin/sh" > "/usr/bin/firefox-$canal"
kyodev's avatar
kyodev committed
692 693
	{
		echo 
kyodev's avatar
kyodev committed
694
		# shellcheck disable=SC1117
kyodev's avatar
kyodev committed
695 696 697
		echo "echo \"\$@\" | grep -qE '\-P|\-\-ProfileManager' && exec $dirInstallFfx$canal/firefox -P || \\"
		echo "    exec $dirInstallFfx$canal/firefox -P $canal \"\$@\""
	} >> "/usr/bin/firefox-$canal"
Kyodev's avatar
Kyodev committed
698
	chmod a+x "/usr/bin/firefox-$canal"
Kyodev's avatar
Kyodev committed
699 700 701

	ffx_config_profil "$canal"			# traitement de profile.ini
	ffx_config_system "$canal"			# lien /usr/bin, alternatives, default dans le profile
Kyodev's avatar
Kyodev committed
702

kyodev's avatar
kyodev committed
703 704 705
	[ "$1" != "manuel" ] && versArchive=$fxVersion
	echo
	f__info "log" "$appli-$canal $versArchive installé"
Kyodev's avatar
Kyodev committed
706
	ffx_godzilla
Kyodev's avatar
Kyodev committed
707 708
}

Kyodev's avatar
Kyodev committed
709 710 711 712
	# installation d'une archive manuelle, $1=canal, $2=archive
ffx_install_manuel(){		# 18/12/2017

	[ -e "$2" ] || f__error "fichier archive $2 introuvable"
Kyodev's avatar
Kyodev committed
713
	ffx_install "$1" "manuel" "$2"
Kyodev's avatar
Kyodev committed
714
	[ -e "$fileDev" ] || rm "$2" &>/dev/null	## on n'efface pas si fileDev (dev)
root's avatar
root committed
715 716
}

Kyodev's avatar
Kyodev committed
717
	# création lanceur.desktop, $1=canal
kyodev's avatar
kyodev committed
718
ffx_lanceur_desktop(){		# 09/03/2018
kyodev's avatar
kyodev committed
719
	local canal="$1" fileDesktop="/usr/share/applications/firefox-$1.desktop"
Kyodev's avatar
Kyodev committed
720

kyodev's avatar
kyodev committed
721
	[ -d "$dirInstallFfx$canal" ] || return 0		# pas d'installation? sortie
Kyodev's avatar
Kyodev committed
722

kyodev's avatar
kyodev committed
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
	echo "[Desktop Entry]" > "$fileDesktop"
	{
		echo "Name=$appli $canal"
		echo "Name[fr]=$appli $canal"
		echo "X-GNOME-FullName=$appli-$canal Web Browser"
		echo "X-GNOME-FullName[fr]=$appli-$canal Navigateur Web"
		echo "StartupWMClass=$appli-$canal"
		echo "Exec=/usr/bin/firefox-$canal %u"
			# default128.png: disparu dans beta, esr, latest, mozicon128 ok sauf nightly! mais default128 ok nightly
		if [ -e "$dirInstallFfx$canal/browser/icons/mozicon128.png" ]; then
			echo "Icon=$dirInstallFfx$canal/browser/icons/mozicon128.png"
		elif [ -e "$dirInstallFfx$canal/browser/chrome/icons/default/default128.png" ]; then
			echo "Icon=$dirInstallFfx$canal/browser/chrome/icons/default/default128.png"
		else
			echo "Icon=$dirInstallFfx$canal/browser/chrome/icons/default/default48.png"
		fi
		echo "Comment=Browse the World Wide Web"
		echo "Comment[fr]=Naviguer sur Internet"
		echo "GenericName=Web Browser" 
		echo "GenericName[fr]=Navigateur Web"
		echo "Terminal=false"
		echo "X-MultipleArgs=false"
		echo "Type=Application"
		echo "Categories=Network;WebBrowser;"
		echo "MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;x-scheme-handler/http;x-scheme-handler/https;"
		echo "StartupNotify=true"
	} >> "$fileDesktop"
Kyodev's avatar
Kyodev committed
750 751
}

Kyodev's avatar
Kyodev committed
752
	# version personnalisation en ligne, [$1=quiet], assigne $perso_ffx_afaire
kyodev's avatar
kyodev committed
753
ffx_pers_get_version(){		# 13/06/2018
kyodev's avatar
kyodev committed
754
	local ii verPersEnPlace persEnPlace verPersOnline 
Kyodev's avatar
Kyodev committed
755
	x_ffx_pers_get_version=1
kyodev's avatar
kyodev committed
756

kyodev's avatar
kyodev committed
757 758 759 760 761 762 763 764 765
	if verPersOnline=$( wget -q --tries=2 --timeout=15 -o /dev/null -O - "$urlPersFfx/$userFfx" ) ; then
		read -r <<< "$verPersOnline"		# lecture 1ere ligne
		verPersOnline=${REPLY,,}
		verPersOnline=${verPersOnline#*v}
		verPersOnline=${verPersOnline%\**}
	else
		f__wget_test "$urlPersFfx/$userFfx"		# si erreur, test url
	fi

Kyodev's avatar
Kyodev committed
766 767
	for ii in $produit_all; do
		if [ -e "$dirProfilFfx/$ii/personnalisation" ]; then
kyodev's avatar
kyodev committed
768
			verPersEnPlace=$( f__read_file "$dirProfilFfx/$ii/personnalisation" 2 )
kyodev's avatar
kyodev committed
769 770 771 772 773
			persEnPlace+="$ii: $verPersEnPlace  "
			if [ -z "$verPersOnline" ]; then
				verPersOnline="${RED}non accessible$STD"		# si quiet
				continue
			fi
kyodev's avatar
kyodev committed
774
			if [ "$verPersEnPlace" != "$verPersOnline" ]; then
kyodev's avatar
kyodev committed
775 776
				perso_ffx_afaire+="$ii "
			fi
Kyodev's avatar
Kyodev committed
777
		fi
Kyodev's avatar
Kyodev committed
778
	done
kyodev's avatar
kyodev committed
779
	f__trim perso_ffx_afaire
Kyodev's avatar
Kyodev committed
780
	[ "$1" == "quiet" ] && return 0
Kyodev's avatar
Kyodev committed
781

kyodev's avatar
kyodev committed
782 783
	f__trim persEnPlace
	f__trim verPersOnline
kyodev's avatar
kyodev committed
784 785
	persEnPlace=${persEnPlace:="Non installé"}
	verPersOnline=${verPersOnline:="${RED}n/a$STD"}
Kyodev's avatar
Kyodev committed
786 787
	f__info "raw" "perso. $appli en place: $GREEN$persEnPlace"
	f__info "perso. $appli en ligne: $YELLOW$verPersOnline"
Kyodev's avatar
Kyodev committed
788 789
}

Kyodev's avatar
Kyodev committed
790
	# recup user.js et chrome/userChrome.css, $1=canal à personnaliser ou mettre à jour
kyodev's avatar
kyodev committed
791
ffx_pers_install(){		# 13/03/2018
kyodev's avatar
kyodev committed
792
	local verPersDL canal="$1" dirTemp="/tmp/$script-persInstall_ffx" 
Kyodev's avatar
Kyodev committed
793

Kyodev's avatar
Kyodev committed
794 795 796
	if [ ! -d "$dirProfilFfx/$canal" ]; then
		f__info "profil $appli $canal inexistant"
		return 1
Kyodev's avatar
Kyodev committed
797 798 799
	fi
		# chargement fichiers personnalisation
	mkdir -p "$dirTemp"
kyodev's avatar
kyodev committed
800 801 802 803 804 805
	if ! wget -q --tries=2 --timeout=15 -o /dev/null -O "$dirTemp/user.js" "$urlPersFfx/$userFfx" ; then
		if__wget_test "$urlPersFfx/$userFfx"
	fi
	if ! wget -q --tries=1 --timeout=15 -o /dev/null -O "$dirTemp/userChrome.css" "$urlPersFfx/$chromeFfx" ; then
		f__wget_test "$urlPersFfx/$chromeFfx"
	fi
Kyodev's avatar
Kyodev committed
806
		# installation
Kyodev's avatar
Kyodev committed
807 808 809 810 811
	mkdir -p "$dirProfilFfx/$canal/chrome"		# répertoire pour userChrome.css
	chown "$fu_user:" "$dirProfilFfx/$canal/chrome"
	cp "$dirTemp/user.js" "$dirProfilFfx/$canal/"
	chown "$fu_user:" "$dirProfilFfx/$canal/user.js"
	if [ -e "$dirTemp/userChrome.css" ]; then
Kyodev's avatar
Kyodev committed
812
		cp "$dirTemp/userChrome.css" "$dirProfilFfx/$canal/chrome"
Kyodev's avatar
Kyodev committed
813
		chown "$fu_user:" "$dirProfilFfx/$canal/chrome/userChrome.css"
Kyodev's avatar
Kyodev committed
814
	fi
Kyodev's avatar
Kyodev committed
815 816 817
	echo "$urlPersFfx" 		 > "$dirProfilFfx/$canal/personnalisation"
	echo "$verPersDL" 		>> "$dirProfilFfx/$canal/personnalisation"
	chown "$fu_user:" "$dirProfilFfx/$canal/personnalisation"
kyodev's avatar
kyodev committed
818
	rm -fr "$dirTemp"
Kyodev's avatar
Kyodev committed
819 820

	f__info "log" "personnalisation $verPersDL mise en place pour $appli $canal"
Kyodev's avatar
Kyodev committed
821 822 823
}

	# supprime une personnalisation pour un canal, $1=canal à traiter
kyodev's avatar
kyodev committed
824 825
ffx_pers_remove(){		# 14/01/2018
	local canal="$1"
Kyodev's avatar
Kyodev committed
826

Kyodev's avatar
Kyodev committed
827 828 829 830
	if [ ! -e "$dirProfilFfx/$canal/personnalisation" ]; then
		f__info "personnalisation inexistante pour $appli"
		return 0
	fi
Kyodev's avatar
Kyodev committed
831 832 833
	rm -f "$dirProfilFfx/$canal/personnalisation"
	rm -f "$dirProfilFfx/$canal/user.js"
	rm -f "$dirProfilFfx/$canal/chrome/userChrome.css"
Kyodev's avatar
Kyodev committed
834 835

	f__info "log" "personnalisation pour $canal désinstallée"	# /chrome répertoire laissé en place si autres fichiers
Kyodev's avatar
Kyodev committed
836 837
}

Kyodev's avatar
Kyodev committed
838 839 840 841 842 843 844
	# maj user.js et chrome/userChrome.css, requiert $perso_ffx_afaire
ffx_pers_upgrade(){		# 21/12/2017
	local ii

	(( x_ffx_pers_get_version == 1 )) || ffx_pers_get_version "quiet"
	if [ "$perso_ffx_afaire" ]; then
		for ii in $perso_ffx_afaire; do
Kyodev's avatar
Kyodev committed
845 846
			ffx_pers_install "$ii"
		done
Kyodev's avatar
Kyodev committed
847
	fi
Kyodev's avatar
Kyodev committed
848 849
}

Kyodev's avatar
Kyodev committed
850
	# désinstallation, $1=canal
kyodev's avatar
kyodev committed
851 852
ffx_remove(){		# 09/03/2018
	local canal="$1"
Kyodev's avatar
Kyodev committed
853

Kyodev's avatar
Kyodev committed
854 855 856 857 858 859 860
	if [ ! -d "$dirInstallFfx$canal" ]; then
		f__info "$appli $canal n'est pas installé"
		return 1
	fi

	killall "$dirInstallFfx$canal/firefox" &>/dev/null
		# suppression du répertoire
kyodev's avatar
kyodev committed
861
	rm -fr "$dirInstallFfx$canal"
Kyodev's avatar
Kyodev committed
862
		# suppression lanceurs
Kyodev's avatar
Kyodev committed
863 864
	rm -f "/usr/share/applications/firefox-$canal.desktop"
	rm -f "/usr/bin/firefox-$canal"
Kyodev's avatar
Kyodev committed
865
		# suppression des liens
Kyodev's avatar
Kyodev committed
866
	unlink "/usr/share/pixmaps/firefox-$canal.png" &>/dev/null
Kyodev's avatar
Kyodev committed
867
	unlink "/usr/bin/firefox" &>/dev/null
Kyodev's avatar
Kyodev committed
868
		#finalisation system
kyodev's avatar
kyodev committed
869 870
	update-alternatives --quiet --remove 'x-www-browser' "/usr/bin/firefox-$canal"
	update-alternatives --quiet --remove 'gnome-www-browser' "/usr/bin/firefox-$canal"
Kyodev's avatar
Kyodev committed
871 872 873

		# canal bas comme nouveau défaut
	ffx_get_canalBas && ffx_config_system "$ffx_canal_bas"
Kyodev's avatar
Kyodev committed
874 875 876 877 878 879 880

	f__info "log" "$appli-$canal désinstallé, mais le profil est toujours en place" \
		"	le supprimer manuellement si nécessaire, avec un autre caanl, pour cela:" \
		"fermer toutes les instances ouvertes de $appli et lancer en console, en user:" \
		"$GREEN firefox -P" \
		"il est aussi possible de supprimer manuellement le profil:" \
		"$YELLOW$dirProfilFfx/$canal"
Kyodev's avatar
Kyodev committed
881
	ffx_godzilla
Kyodev's avatar
Kyodev committed
882 883
}

kyodev's avatar
kyodev committed
884
	# anacron hebdomadaire, via cron horaire, $1=upgrade|install|remove
kyodev's avatar
kyodev committed
885
fscript_cronAnacron(){		# 11/06/2018
Kyodev's avatar
Kyodev committed
886
	local dirAnacron dirSpool fileAnacron
Kyodev's avatar
Kyodev committed
887

kyodev's avatar
kyodev committed
888
	type -t fscript_cronAnacron_special &>/dev/null && fscript_cronAnacron_special		# test, si fonction spécifique, appel
Kyodev's avatar
Kyodev committed
889
	dirAnacron="/home/$fu_user/.config/anacron"
Kyodev's avatar
Kyodev committed
890 891
	dirSpool="$dirAnacron/spool"
	fileAnacron="$dirAnacron/$script.anacrontab"
Kyodev's avatar
Kyodev committed
892
	[ "$EUID" -eq 0 ] && sed -i "/$script.anacrontab/d" /etc/crontab
Kyodev's avatar
Kyodev committed
893 894 895 896
	case "$1" in 
		install | upgrade )
			mkdir -p  "$dirAnacron"
				# table anacron
Kyodev's avatar
Kyodev committed
897
			echo "7 10 $script nice $script_install --upgrade 1>/dev/null" > "$fileAnacron"	# juste erreurs en syslog
Kyodev's avatar
Kyodev committed
898
				## anacron journalier pour dev logname 
Kyodev's avatar
Kyodev committed
899
			if [ -e "$fileDev" ]; then
kyodev's avatar
kyodev committed
900
				echo "1 00 ${script}Dev nice $script_install --upgrade 1>/dev/null" >> "$fileAnacron"
Kyodev's avatar
Kyodev committed
901 902 903
			fi
				# création spool anacron utilisateur
			mkdir -p "$dirSpool"
Kyodev's avatar
Kyodev committed
904
			chown -R "$fu_user:" "$dirAnacron" "$dirSpool"
Kyodev's avatar
Kyodev committed
905
			if [ "$EUID" -eq 0 ]; then
Kyodev's avatar
Kyodev committed
906
					# crontab pour activation horaire anacron
Kyodev's avatar
Kyodev committed
907
				echo "@hourly $fu_user /usr/sbin/anacron -t $fileAnacron -S $dirSpool" >> /etc/crontab
Kyodev's avatar
Kyodev committed
908
			fi
Kyodev's avatar
Kyodev committed
909
			grep -q "$script" "/etc/crontab" || echo f__error "inscription crontab"
Kyodev's avatar
Kyodev committed
910 911
		;;
		remove )
kyodev's avatar
kyodev committed
912
			rm -f "${dirSpool:?}/$script"*
kyodev's avatar
kyodev committed
913 914
			rm -f "$fileAnacron"
			rmdir "$${dirSpool:?}" "${dirAnacron:?}" 2>/dev/null
Kyodev's avatar
Kyodev committed
915 916 917 918
		;;
	esac
}

kyodev's avatar
kyodev committed
919
	# assigne $ver_script_install, $ver_script_online, $script_a_jour=ok|KO
kyodev's avatar
kyodev committed
920
fscript_get_version(){		# 09/06/2018
kyodev's avatar
kyodev committed
921

kyodev's avatar
kyodev committed
922
	x_script_get_version=1
Kyodev's avatar
Kyodev committed
923
		# version online
kyodev's avatar
kyodev committed
924 925 926 927
	if ver_script_online=$( wget -q --timeout=15 -o /dev/null -O - "$url_script" ); then
		ver_script_online=${ver_script_online#*version=}
		read -r ver_script_online <<< "$ver_script_online"
	else
kyodev's avatar
kyodev committed
928 929
		f__wget_test "$url_script"
	fi
Kyodev's avatar
Kyodev committed
930 931
		# version installée
	if [ -e "$script_install" ]; then
kyodev's avatar
kyodev committed
932 933 934 935 936
		while read -r ; do
			if [[ "$REPLY" =~ ^version= ]]; then
				ver_script_install=${REPLY#*=}
			fi
		done < "$script_install"
Kyodev's avatar
Kyodev committed
937
	fi
kyodev's avatar
kyodev committed
938
		# maj ?
Kyodev's avatar
Kyodev committed
939
	if [[ "$ver_script_online" && "$script_install" ]]; then 
kyodev's avatar
kyodev committed
940 941 942 943 944
		if [ "$ver_script_install" != "$ver_script_online" ]; then
			script_a_jour="KO"
		else
			script_a_jour="ok"
		fi
Kyodev's avatar
Kyodev committed
945
	fi
kyodev's avatar
kyodev committed
946 947 948
		# affichage
	ver_script_online=${ver_script_online:="${RED}n/a$STD"}
	ver_script_install=${ver_script_install:="Non installé"}
Kyodev's avatar
Kyodev committed
949 950
	f__info "raw" "script en place: $GREEN$ver_script_install"
	f__info "script en ligne: $YELLOW$ver_script_online"
Kyodev's avatar
Kyodev committed
951 952
}

kyodev's avatar
kyodev committed
953
fscript_install(){		# 09/06/2018
Kyodev's avatar
Kyodev committed
954

kyodev's avatar
kyodev committed
955
	if grep -Eq "$script_install|/usr/bin/$script" <<< "$0"; then
kyodev's avatar
kyodev committed
956
		f__info "${RED}l'installation dans le système doit se faire depuis le script non installé $GREEN(./$script -i )"
Kyodev's avatar
Kyodev committed
957
		return 1
Kyodev's avatar
Kyodev committed
958
	fi
kyodev's avatar
kyodev committed
959
	type -t fscript_install_special &>/dev/null && fscript_install_special		# test, si fonction spécifique, appel
Kyodev's avatar
Kyodev committed
960
	f__requis "wget anacron cron" || exit 1 
Kyodev's avatar
Kyodev committed
961 962
		# install /opt
	mkdir -p /opt/bin/
kyodev's avatar
kyodev committed
963 964 965
	cp "$0" "$script_install"
	ln -s "$script_install" "/usr/bin/$script" 2>/dev/null
	chmod 755 "$script_install"
Kyodev's avatar
Kyodev committed
966 967 968
		# cron/anacron install
	fscript_cronAnacron "install"
		# création fichier log
Kyodev's avatar
Kyodev committed
969
	touch "$script_logs"
kyodev's avatar
kyodev committed
970
	chmod 644 "$script_logs"
Kyodev's avatar
Kyodev committed
971
	chown "$fu_user:" "$script_logs" "$script_install"
Kyodev's avatar
Kyodev committed
972 973
	[ -e "$fileDev" ] || rm -f "$0"			## on efface pas si fileDev (dev)

Kyodev's avatar
Kyodev committed
974
	f__info "log" "$script $version installé dans le système." "maintenant, appel du script par: $GREEN$script$BLUE (sans ./)"
Kyodev's avatar
Kyodev committed
975 976
}

kyodev's avatar
kyodev committed
977
fscript_remove(){		# 09/06/2018
Kyodev's avatar
Kyodev committed
978

kyodev's avatar
kyodev committed
979
	if ! grep -Eq "$script_install|/usr/bin/$script" <<< "$0"; then
kyodev's avatar
kyodev committed
980
		f__info "${RED}cette fonction doit être appelée depuis le script installé dans le système $GREEN($script -r)"
Kyodev's avatar
Kyodev committed
981 982
		return 1
	fi
Kyodev's avatar
Kyodev committed
983
	if [ ! -x "$script_install" ];then
Kyodev's avatar
Kyodev committed
984 985
		f__info "$RED$script n'est pas installé"
		return 1
Kyodev's avatar
Kyodev committed
986
	fi
Kyodev's avatar
Kyodev committed
987

kyodev's avatar
kyodev committed
988
	type -t fscript_remove_special &>/dev/null && fscript_remove_special		# test, si fonction spécifique, appel
kyodev's avatar
kyodev committed
989
		# suppression /opt, lien /usr/bin
Kyodev's avatar
Kyodev committed
990
	rm -f "$script_install"
kyodev's avatar
kyodev committed
991
	unlink "/usr/bin/$script" 2>/dev/null
Kyodev's avatar
Kyodev committed
992 993
		# cron/anacron remove
	fscript_cronAnacron "remove"
Kyodev's avatar
Kyodev committed
994

Kyodev's avatar
Kyodev committed
995 996 997
	f__info "log" "$script $version supprimé du système."
}

kyodev's avatar
kyodev committed
998 999 1000
	# $1: update standard $1=std, si update en place $1=message d'info
fscript_update(){		# 11/06/2018
	local dirTemp="/tmp/$script-maj" upgradeEnPlace
Kyodev's avatar
Kyodev committed
1001

kyodev's avatar
kyodev committed
1002 1003
	[ "$1" != 'std' ] && upgradeEnPlace="$1"
	type -t fscript_update_special &>/dev/null && fscript_update_special		# test, si fonction spécifique, appel
kyodev's avatar
kyodev committed
1004
	if [ -z "$upgradeEnPlace" ] && ! grep -Eq "$script_install|/usr/bin/$script" <<< "$0"; then
kyodev's avatar
kyodev committed
1005
		f__info "${RED}cette fonction doit être appelée depuis le script installé dans le système $GREEN($script -u)"
Kyodev's avatar
Kyodev committed
1006
		return 1
Kyodev's avatar
Kyodev committed
1007
	fi
Kyodev's avatar
Kyodev committed
1008
	(( x_script_get_version == 1 )) || fscript_get_version
Kyodev's avatar
Kyodev committed
1009
	if [ "$script_a_jour" == "ok" ]; then 
Kyodev's avatar
Kyodev committed
1010
		f__info "log" "pas de mise à jour disponible pour $script $version"
Kyodev's avatar
Kyodev committed
1011
		return 0
Kyodev's avatar
Kyodev committed
1012 1013
	else
		f__info "mise à jour en cours"
Kyodev's avatar
Kyodev committed
1014 1015
	fi
	mkdir -p "$dirTemp"
kyodev's avatar
kyodev committed
1016 1017
	if ! wget -q --tries=2 --timeout=15 -o /dev/null -O "$dirTemp/$script" "$url_script"; then
		rm -fr "$dirTemp"
Kyodev's avatar
Kyodev committed
1018 1019
		f__wget_test "$url_script"
	fi
Kyodev's avatar
Kyodev committed
1020
	if grep -q '#!/bin/bash' "$dirTemp/$script" && grep -q '^### END CONTROL' "$dirTemp/$script"; then 
kyodev's avatar
kyodev committed
1021 1022
		cp "$dirTemp/$script" "$script_install"
		chmod 755 "$script_install"
Kyodev's avatar
Kyodev committed
1023
		chown "$fu_user:" "$script_install"
Kyodev's avatar
Kyodev committed
1024
		[ -z "$upgradeEnPlace" ] && fscript_cronAnacron "upgrade"
kyodev's avatar
kyodev committed
1025
		f__info "log" "$script mis à jour en version $ver_script_online $upgradeEnPlace"
Kyodev's avatar
Kyodev committed
1026
	else
Kyodev's avatar
Kyodev committed
1027
		f_info "log" "$script: échec update" "mauvais téléchargement, réessayer plus tard"
Kyodev's avatar
Kyodev committed
1028
	fi
kyodev's avatar
kyodev committed
1029
	rm -fr "$dirTemp"
Kyodev's avatar
Kyodev committed
1030 1031
}

kyodev's avatar
kyodev committed
1032
prg_init(){		# 07/06/2018
Kyodev's avatar
Kyodev committed
1033

Kyodev's avatar
Kyodev committed
1034 1035 1036 1037
	PATH='/usr/sbin:/usr/bin:/sbin:/bin' 
	TERM=xterm  
	IFS=$' \t\n'
	export PATH TERM IFS
Kyodev's avatar
Kyodev committed
1038

kyodev's avatar
kyodev committed
1039 1040 1041 1042
		# options bash figées
	shopt -s checkwinsize complete_fullquote extglob extquote interactive_comments sourcepath
	shopt -u force_fignore execfail failglob

Kyodev's avatar
Kyodev committed
1043
		# test bash v4
kyodev's avatar
kyodev committed
1044
	[ "${BASH_VERSINFO[0]}" == 4 ] || f__error "bash v4 requis" "version installée: $BASH_VERSION"
Kyodev's avatar
Kyodev committed
1045

Kyodev's avatar
Kyodev committed
1046
		# architectures possibles
Kyodev's avatar
Kyodev committed
1047
	f__architecture || f__error "Seules les architecture 32 et/ou 64 bits sont supportée (i686 & amd64)"
Kyodev's avatar
Kyodev committed
1048 1049 1050 1051 1052

		# détermination user derrière root
	f__user
	retourFUser="$?"
	[ "$retourFUser" -eq 1 ] && f__error "user indéterminé" \
kyodev's avatar
kyodev committed
1053
		"pour contourner, lancer le script avec:\\n$GREEN  USER_INSTALL=<user> $0 \\n"
Kyodev's avatar
Kyodev committed
1054
	if [ "$retourFUser" -eq 2 ]; then
kyodev's avatar
kyodev committed
1055 1056 1057 1058 1059
		if [ "$EUID" -eq 0 ]; then
			fu_user="root"
		else
			f__error "user détecté, mais pas de home: /home/$fu_user"
		fi
Kyodev's avatar
Kyodev committed
1060 1061
		f__info "user root"
	fi
Kyodev's avatar
Kyodev committed
1062

Kyodev's avatar
Kyodev committed
1063
		# requis pour fonctionnement programme
kyodev's avatar
kyodev committed
1064
	f__requis "awk|gawk>gawk wget file tar killall>psmisc" || exit 1 
Kyodev's avatar
Kyodev committed
1065 1066 1067

		# définition couleurs
	f__color
Kyodev's avatar
Kyodev committed
1068 1069
}

kyodev's avatar
kyodev committed
1070

Kyodev's avatar
Kyodev committed
1071 1072
######## début script / initialisation

Kyodev's avatar
Kyodev committed
1073
	# tests ou initialisation au démarrage
kyodev's avatar
kyodev committed
1074
prg_init
Kyodev's avatar
Kyodev committed
1075

kyodev's avatar
kyodev committed
1076
	# logo
Kyodev's avatar
Kyodev committed
1077 1078
f_affichage

Kyodev's avatar
Kyodev committed
1079
	# paramètres script
Kyodev's avatar
Kyodev committed
1080
user_agent="Mozilla/5.0 Firefox"
Kyodev's avatar
Kyodev committed
1081
fileDev="/opt/bin/fileDev"
Kyodev's avatar
Kyodev committed
1082 1083
script_install="/opt/bin/$script"
script_logs="/var/log/sdeb_$script.log"
kyodev's avatar
kyodev committed
1084 1085
url_script="https://framagit.org/sdeb/getFirefox/raw/master/getFirefox"
url_notice="https://framaclic.org/h/doc-getfirefox"
Kyodev's avatar
Kyodev committed
1086 1087

	# paramètres firefox
kyodev's avatar
kyodev committed
1088
appli="Firefox"
Kyodev's avatar
Kyodev committed
1089
dirInstallFfx="/opt/usr/share/firefox-"
kyodev's avatar
kyodev committed
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
dirProfilFfx="/home/$fu_user/.mozilla/firefox"					# emplacement profiles.ini
urlPersFfx="https://framagit.org/sdeb/getFirefox/raw/master"	# url standard des personnalisations
userFfx="user.js"												# nom du fichier user.js sur un dépôt distant
chromeFfx="userChrome.css"										# nom du fichier userChrome.css sur un dépôt distant
produit_all="esr latest beta nightly"							# tous les canaux sauf dev (=beta)
produit_all_inverse="nightly beta latest esr"					# tous les canaux sauf dev (=beta)


	# url perso éventuellement personnalisée, une seule url possible, arrêt à la première trouvée
for ii in $produit_all dev; do		# première url personnalisée éventuellement trouvée
kyodev's avatar
kyodev committed
1100 1101 1102 1103
	if [ -e "$dirProfilFfx/$ii/personnalisation.getFirefox" ]; then
		# renommage anciens fichiers personnalisation
		mv "$dirProfilFfx/$ii/personnalisation.getFirefox"  "$dirProfilFfx/$ii/personnalisation"
	fi
kyodev's avatar
kyodev committed
1104 1105 1106
	if [ -e "$dirProfilFfx/$ii/personnalisation" ]; then
		[ -z "$urlPersoEnPlace" ] && read -r urlPersoEnPlace < "$dirProfilFfx/$ii/personnalisation"	# url 1er fichier
		perso_ffx_enPlace+="$ii "
Kyodev's avatar
Kyodev committed
1107 1108
	fi
done
kyodev's avatar
kyodev committed
1109 1110
if [[ "$urlPersoEnPlace" =~ /kyodev/kyopages/ ]]; then	# changement git distant
	perso_ffx_afaire="$perso_ffx_enPlace"
kyodev's avatar
kyodev committed
1111
elif [[ "$urlPersoEnPlace" && "$urlPersoEnPlace" != "$urlPersFfx" ]]; then		# url personnalisée
kyodev's avatar
kyodev committed
1112 1113
	urlPersFfx="$urlPersoEnPlace"
fi
Kyodev's avatar
Kyodev committed
1114

kyodev's avatar
kyodev committed
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
script_options="$*"
	# options
while (( $# )) ; do
	case "$1" in 
		--sauve ) dl_to_svg="ok" ;;
		--dev   ) url_script=${url_script//\/master\///dev/} ;;
		* ) options+=( "$1" ) ;;
	esac
	shift
done

kyodev's avatar
kyodev committed
1126
	# auto-installation script éventuel, si pas de marqueur $fileDev
kyodev's avatar
kyodev committed
1127
if [[ $( dirname "$0" ) != $( dirname "$script_install" ) && $( dirname "$0" ) != "/usr/bin" && ! -e "$fileDev" ]]; then
kyodev's avatar
kyodev committed
1128
	options=( -i )									# option installation script
Kyodev's avatar
Kyodev committed
1129
fi
kyodev's avatar
kyodev committed
1130
(( ${#options} == 0 )) && options=( -h )			# vide help (si fileDev), sinon install
kyodev's avatar
kyodev committed
1131

kyodev's avatar
kyodev committed
1132 1133 1134 1135 1136
	#actions
for i in "${!options[@]}"; do							# deuxième passe options, actions
	produit=${options[$i]#*-}
	# shellcheck disable=SC2221,SC2222
	case ${options[$i]} in
kyodev's avatar
kyodev committed
1137 1138
		-i | --install | -r | --remove | ri | i-* | m-* | r-* | u-* )
			if [ "$EUID" -ne 0 ]; then
kyodev's avatar
kyodev committed
1139 1140
				f__info raw "vous devez être$RED ROOT$BLUE pour cette opération"
				f__sudo "exec $0 $script_options"
kyodev's avatar
kyodev committed
1141
				exit
kyodev's avatar
kyodev committed
1142
			fi 	;;&
Kyodev's avatar
Kyodev committed
1143 1144
		d-latest | d-esr | d-dev | d-beta | d-nightly | d-all )
			[ "$produit" == "all" ] && produit="$produit_all"
kyodev's avatar
kyodev committed
1145 1146
			for k in $produit; do
				ffx_copie_default "$k"				# copier un profil default sur un canal
kyodev's avatar
kyodev committed
1147
			done ;;
Kyodev's avatar
Kyodev committed
1148 1149
		i-latest | i-esr | i-dev | i-beta | i-nightly | i-all )
			[ "$produit" == "all" ] && produit="$produit_all_inverse"
kyodev's avatar
kyodev committed
1150 1151
			for k in $produit; do
				ffx_install "$k"					# installation canal
kyodev's avatar
kyodev committed
1152
			done ;;
root's avatar
root committed
1153
		m-latest | m-esr | m-dev | m-beta | m-nightly )
kyodev's avatar
kyodev committed
1154
			ffx_install_manuel "$produit" "${options[((i+1))]}"		# installation manuelle d'une archive, $2=archive
kyodev's avatar
kyodev committed
1155
			exit ;;
Kyodev's avatar
Kyodev committed
1156
		p-latest | p-esr | p-dev | p-beta | p-nightly | p-all )
Kyodev's avatar
Kyodev committed
1157
			[ "$produit" == "all" ] && produit="$produit_all"
kyodev's avatar
kyodev committed
1158 1159
			for k in $produit; do
				ffx_pers_install "$k"				# personnalisation
kyodev's avatar
kyodev committed
1160
			done ;;
Kyodev's avatar
Kyodev committed
1161
		pr-latest | pr-esr | pr-dev | pr-beta | pr-nightly | pr-all )
Kyodev's avatar
Kyodev committed
1162
			[ "$produit" == "all" ] && produit="$produit_all"
kyodev's avatar
kyodev committed
1163 1164
			for k in $produit; do
				ffx_pers_remove "$k"				# personnalisation remove
kyodev's avatar
kyodev committed
1165
			done ;;
Kyodev's avatar
Kyodev committed
1166
		pu ) 
kyodev's avatar
kyodev committed
1167 1168
			ffx_pers_upgrade						# mise à jour personnalisations
			;;
Kyodev's avatar
Kyodev committed
1169 1170
		r-latest | r-esr | r-dev | r-beta | r-nightly | r-all )
			[ "$produit" == "all" ] && produit="$produit_all"
kyodev's avatar
kyodev committed
1171
			for k in $produit; do  					# remove canal
Kyodev's avatar
Kyodev committed
1172
				ffx_remove "$k"
kyodev's avatar
kyodev committed
1173
			done ;;
kyodev's avatar
kyodev committed
1174
		ri )
kyodev's avatar
kyodev committed
1175 1176
			produit="$produit_all"
			for k in $produit; do 
kyodev's avatar
kyodev committed
1177
				ffx_lanceur_desktop "$k"			# réparation icône de tous les canaux installés
kyodev's avatar
kyodev committed
1178 1179 1180 1181 1182 1183 1184
			done ;;
		t-latest | t-esr | t-dev | t-beta | t-nightly | t-all )
			[ "$produit" == "all" ] && produit="$produit_all"
			for k in $produit; do
				dl_only="ok"
				ffx_install "$k"					# téléchargement canal
			done ;;
kyodev's avatar
kyodev committed
1185
		u-latest | u-esr | u-dev | u-beta | u-nightly | u-all )
Kyodev's avatar
Kyodev committed
1186
			[ "$produit" == "all" ] && produit="$produit_all"
Kyodev's avatar
Kyodev committed
1187
			for k in $produit; do 
kyodev's avatar
kyodev committed
1188 1189
				ffx_config_profil "$k" "menu"		# configurer un canal pour user en cours
				ffx_config_system "$k"				# défaut système
Kyodev's avatar
Kyodev committed
1190
				echo
kyodev's avatar
kyodev committed
1191
			done ;;
Kyodev's avatar
Kyodev committed
1192

kyodev's avatar
kyodev committed
1193
		version | versions )						# versions en ligne & installées
Kyodev's avatar
Kyodev committed
1194
			fscript_get_version
Kyodev's avatar
Kyodev committed
1195
			ffx_get_version
kyodev's avatar
kyodev committed
1196
			ffx_pers_get_version ;;
Kyodev's avatar
Kyodev committed
1197

kyodev's avatar
kyodev committed
1198
		-i | --install )							# installation du script dans le système
Kyodev's avatar
Kyodev committed
1199
			fscript_install
Kyodev's avatar
Kyodev committed
1200
			exit ;;
kyodev's avatar
kyodev committed
1201
		-r | --remove )								# désinstallation du script
Kyodev's avatar
Kyodev committed
1202
			fscript_remove
Kyodev's avatar
Kyodev committed
1203
			exit ;;
kyodev's avatar
kyodev committed
1204
		-u | --upgrade )							# upgrade script & personnalisations
Kyodev's avatar
Kyodev committed
1205
			operation="upgrade"
kyodev's avatar
kyodev committed
1206
			fscript_update std						# std argument obligatoire pour upgrade normal
kyodev's avatar
kyodev committed
1207
			ffx_pers_upgrade
Kyodev's avatar
Kyodev committed
1208