File: confd-link.sh

package info (click to toggle)
wwwconfig-common 0.3.0
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 488 kB
  • sloc: sh: 952; makefile: 5
file content (88 lines) | stat: -rwxr-xr-x 2,326 bytes parent folder | download
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
#!/bin/sh
# File:		confd-link.sh
# Changes:
#       20160609 Ola Lundqvist <opal@debian.org>
#               Changed as apache2 directory is now called conf-available too.
#       20081109 Norman Messtorff <normes@normes.org>
#               Initial version.
#
# Needs:	$servers - the servers to link configurations in.
#		$linkname	 - specify the link name
#		$linkdestination_apache	- specify the link destination (Apache config)
#		$linkdestination_lighttpd - specify the link destination (lighttpd config)
# Description:	Linking configurations into Webservers conf.d
# Sets:		$status = {error, nothing, linked, removed}
#		$error = error message (if $status = error)

status="nothing"
error=""

#
# Checking needed settings...
#
if [ -z "$servers" ]; then
    status="error"
    error="No servers specified in confd-link.sh"
elif [ -z "$linkname" ]; then
	status="error"
	error="No linkname specified in confd-link.sh"
else
	
	#
	# The link removal part...
	#
	if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
		for A in $servers ; do
			A=${A%,}
			#
			# lighttpd has no conf.d
			#
			if [ "$A" = "lighttpd" ] || [ "$A" = "apache" ]; then
				linkpath="/etc/$A/conf-available"
			else
				linkpath="/etc/$A/conf.d"
			fi
			
			#
			# Is it existing and a symbolic link or are we going to do some unwished things?
			#
			if [ -L $linkpath/$linkname ]; then
				if rm -f $linkpath/$linkname 2>&1 ; then
					status="removed"
				else
					status="error"
					error="ERROR! Couln't remove $linkpath/$linkname "
				fi
			else
				status="error"
				error="ERROR! $linkpath/$linkname is no symbolic link or doesn't exists."
			fi
		done
	else
		for A in $servers ; do
			A=${A%,}
			#
			# lighttpd has no conf.d
			#
			if [ "$A" = "lighttpd" ] || [ "$A" = "apache" ]; then
				linkpath="/etc/$A/conf-available"
				linkdestination=$linkdestination_lighttpd
			else
				linkpath="/etc/$A/conf.d"
				linkdestination=$linkdestination_apache
			fi
			
			if [ -d $linkpath ]; then
				if ln -s $linkdestination $linkpath/$linkname >/dev/null 2>&1 ; then
					status="linked"
				else
					status="error"
					error="ERROR! 'ln -s' returned an error. Could not create link in $linkpath"
				fi
			else
				status="error"
				error="ERROR! $linkpath doesn't exists. Could not create link in $linkpath"
			fi
		done
	fi
fi