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