summarylogtreecommitdiffstats
path: root/xampp.install
blob: f4e117c6b8503458efff335ff44b72672261f1ed (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
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
# Like `backup` in `PKGBUILD`, but supports folders – no leading and trailing slash here!
_BACKUP=('opt/lampp/etc' 'opt/lampp/htdocs' 'opt/lampp/var')

post_install() {

	echo
	echo 'XAMPP is now installed below the /opt/lampp directory.'
	echo
	echo 'To start, stop or restart XAMPP simply call the command'
	echo
	echo '    xampp {start, stop, restart}'
	echo
	echo 'Alternatively you can use the `xampp` systemd service.'
	echo
	echo 'To check that everything really works just enter the following URL in your web'
	echo 'browser:'
	echo
	echo '    http://localhost'
	echo
	echo 'Have fun!'
	echo

}

pre_upgrade() {

	local _STDERR
	local _COIN

	echo -n 'Stopping lampp services...'
	_STDERR="$(/opt/lampp/lampp stop >/dev/null 2>&1)" && echo ' OK' || (echo ' FAILED'; test "x${_STDERR}" != 'x' && echo "${_STDERR}")

	for _COIN in "${_BACKUP[@]}"; do
		! test -d "/${_COIN}" || (rm -rf "/${_COIN}.keep" && mv "/${_COIN}" "/${_COIN}.keep")
	done

}

post_upgrade() {

	local _COIN
	local _HAVE_PACNEW=no

	for _COIN in "${_BACKUP[@]}"; do
		if test -d "/${_COIN}.keep"; then
			_HAVE_PACNEW=yes
			rm -rf "/${_COIN}.pacnew"
			mv "/${_COIN}" "/${_COIN}.pacnew"
			mv "/${_COIN}.keep" "/${_COIN}"
			echo "/${_COIN} has been installed as /${_COIN}.pacnew."
		fi
	done

	if test "x${_HAVE_PACNEW}" = 'xyes'; then
		echo
		echo 'One or more files have been saved as .pacnew files to preserve a current'
		echo 'version. To discard these files launch:'
		echo
		echo '    sudo rm -r `sudo find -L '\''/opt/lampp/'\'' -name '\''*.pacnew'\''`'
		echo
	fi

}

pre_remove() {

	local _STDERR
	local _COIN
	local _DATESTAMP="$(date '+%Y-%m-%d-%H.%M.%S')"

	echo -n 'Stopping lampp services...'
	_STDERR="$(/opt/lampp/lampp stop >/dev/null 2>&1)" && echo ' OK' || (echo ' FAILED'; test "x${_STDERR}" != 'x' && echo "${_STDERR}")

	for _COIN in "${_BACKUP[@]}"; do
		rm -rf "/${_COIN}.pacnew"
	done

	install -dm755 '/opt/htdocs-backups'
	rm -rf "/opt/htdocs-backups/${_DATESTAMP}"
	mv '/opt/lampp/htdocs' "/opt/htdocs-backups/${_DATESTAMP}" || echo 'ERROR: Could not create a backup of /opt/lampp/htdocs.' 1>&2

	rm -rf '/opt/lampp/var' '/opt/lampp/temp' '/opt/lampp/etc' '/opt/lampp/phpmyadmin/tmp'

}

post_remove() {

	echo
	echo 'REMEMBER: Your `htdocs` folder was backed up to `/opt/htdocs-backups`.'
	echo
	echo 'If you don'\''t need them, launch'
	echo
	echo '    sudo rm -rf /opt/htdocs-backups'
	echo
	echo 'to erase all backups.'
	echo

}