1
|
#!/bin/sh
|
2
|
# postinst script for cdmserver
|
3
|
#
|
4
|
# see: dh_installdeb(1)
|
5
|
|
6
|
set -e
|
7
|
|
8
|
#
|
9
|
# variables
|
10
|
#
|
11
|
CDM_HOME="/opt/cdmserver/"
|
12
|
CDM_CONFIG_TEMPLATE="/opt/cdmserver/templates/.cdmLibrary"
|
13
|
CDM_LOG="/var/log/cdmserver/"
|
14
|
|
15
|
INIT_SCRIPT="cdmserver"
|
16
|
ETC_CDMSERVER="/etc/cdmserver/"
|
17
|
|
18
|
CDM_USER=cdm
|
19
|
CDM_GROUP=cdm
|
20
|
|
21
|
CDM_USER_HOME=$CDM_HOME
|
22
|
|
23
|
#
|
24
|
# functions
|
25
|
#
|
26
|
userExist(){
|
27
|
grep $1 /etc/passwd > /dev/null
|
28
|
[ $? -eq 0 ] && return $TRUE || return $FALSE
|
29
|
}
|
30
|
|
31
|
groupExist(){
|
32
|
grep $1 /etc/group > /dev/null
|
33
|
[ $? -eq 0 ] && return $TRUE || return $FALSE
|
34
|
}
|
35
|
|
36
|
|
37
|
# summary of how this script can be called:
|
38
|
# * <postinst> `configure' <most-recently-configured-version>
|
39
|
# * <old-postinst> `abort-upgrade' <new version>
|
40
|
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
|
41
|
# <new-version>
|
42
|
# * <postinst> `abort-remove'
|
43
|
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
|
44
|
# <failed-install-package> <version> `removing'
|
45
|
# <conflicting-package> <version>
|
46
|
# for details, see http://www.debian.org/doc/debian-policy/ or
|
47
|
# the debian-policy package
|
48
|
|
49
|
case "$1" in
|
50
|
configure)
|
51
|
|
52
|
#
|
53
|
# adding the group
|
54
|
# if the group already exist will be deleted
|
55
|
#
|
56
|
if ( groupExist $CDM_GROUP )
|
57
|
then
|
58
|
echo "user '$CDM_GROUP' alreday exists"
|
59
|
else
|
60
|
echo "creating group '$CDM_GROUP'"
|
61
|
groupadd $CDM_GROUP
|
62
|
fi
|
63
|
|
64
|
#
|
65
|
# adding the user
|
66
|
#
|
67
|
if ( userExist $CDM_USER )
|
68
|
then
|
69
|
echo "user '$CDM_USER' alreday exists"
|
70
|
else
|
71
|
echo "creating user '$CDM_USER'"
|
72
|
useradd -g $CDM_GROUP -d $CDM_USER_HOME $CDM_USER
|
73
|
fi
|
74
|
|
75
|
|
76
|
#
|
77
|
# adjusting permissions of init script user and group should be root
|
78
|
#
|
79
|
chmod 755 /etc/init.d/$INIT_SCRIPT
|
80
|
chown root:root /etc/init.d/$INIT_SCRIPT
|
81
|
|
82
|
chown -R $CDM_USER:$CDM_GROUP $CDM_HOME
|
83
|
|
84
|
#
|
85
|
# create log file folder and set owner:group
|
86
|
#
|
87
|
if [ ! -d $CDM_LOG ]; then
|
88
|
mkdir -p $CDM_LOG
|
89
|
chown -R $CDM_USER:$CDM_GROUP $CDM_LOG
|
90
|
fi
|
91
|
|
92
|
#
|
93
|
# copy template .cdmLibrary if not yet existing into
|
94
|
# /etc/cdmserver
|
95
|
# AND create symlink
|
96
|
#
|
97
|
if [ ! -d $ETC_CDMSERVER.cdmLibrary ]
|
98
|
then
|
99
|
mkdir -p $ETC_CDMSERVER
|
100
|
cp -r $CDM_CONFIG_TEMPLATE $ETC_CDMSERVER
|
101
|
fi
|
102
|
ln -s $ETC_CDMSERVER.cdmLibrary $CDM_USER_HOME.cdmLibrary
|
103
|
|
104
|
# let the cdm server start automatically on boot
|
105
|
update-rc.d $INIT_SCRIPT defaults 98 02
|
106
|
|
107
|
# start the server manually this time
|
108
|
/etc/init.d/$INIT_SCRIPT start
|
109
|
|
110
|
;;
|
111
|
|
112
|
abort-upgrade|abort-remove|abort-deconfigure)
|
113
|
;;
|
114
|
|
115
|
*)
|
116
|
echo "postinst called with unknown argument \`$1'" >&2
|
117
|
exit 1
|
118
|
;;
|
119
|
esac
|
120
|
|
121
|
# dh_installdeb will replace this with shell code automatically
|
122
|
# generated by other debhelper scripts.
|
123
|
|
124
|
#DEBHELPER#
|
125
|
|
126
|
exit 0
|
127
|
|
128
|
|