Project

General

Profile

Download (3.22 KB) Statistics
| Branch: | Tag: | Revision:
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
TEMPLATE_DIR="/opt/cdmserver/templates"
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
    # if /etc/cdmserver is not yet existing
89
    # copy the content of template/.cdmLibrary into
90
    # /etc/cdmserver
91
    #
92
    if [ ! -d $ETC_CDMSERVER ]
93
    then
94
      mkdir -p $ETC_CDMSERVER
95
      cp -r $TEMPLATE_DIR/etc/cdmserver/* $ETC_CDMSERVER/
96
    fi
97
    
98
    if [ ! -e /etc/default/cdmserver ]
99
    then
100
      cp $TEMPLATE_DIR/etc/default/cdmserver /etc/default/cdmserver
101
    fi
102
    
103
	#
104
	# create a .cdmLibrary folder in user home, it will hold temporary files
105
	# and symlinks to the configfiles
106
	#
107
	if [ ! -e $CDM_USER_HOME/.cdmLibrary ]
108
	then
109
		mkdir $CDM_USER_HOME/.cdmLibrary
110
	fi
111
	
112
	cd $CDM_USER_HOME/.cdmLibrary
113
	
114
    ln -sf $ETC_CDMSERVER/datasources.xml datasources.xml
115
    ln -sf $ETC_CDMSERVER/cdm-server-realm.properties cdm-server-realm.properties
116
    
117
    # clean up
118
    rm -rf $TEMPLATE_DIR
119

    
120
    #
121
    # set group and owner for home directory
122
    #
123
    chown -R $CDM_USER:$CDM_GROUP $CDM_HOME
124

    
125
    # let the cdm server start automatically on boot
126
    update-rc.d $INIT_SCRIPT defaults 98 02
127

    
128
    # start the server manually this time ignoring errors
129
    /etc/init.d/$INIT_SCRIPT start || true
130

    
131
    ;;
132

    
133
    abort-upgrade|abort-remove|abort-deconfigure)
134
    ;;
135

    
136
    *)
137
        echo "postinst called with unknown argument \`$1'" >&2
138
        exit 1
139
    ;;
140
esac
141

    
142
# dh_installdeb will replace this with shell code automatically
143
# generated by other debhelper scripts.
144

    
145
#DEBHELPER#
146

    
147
exit 0
148

    
149

    
(3-3/5)