aboutsummaryrefslogtreecommitdiffstats
path: root/www/tomcat55/files/pkg-install.in
blob: fe300c3c8426ec9cbf97f04aff7634d0e0cd6d7b (plain) (blame)
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
100
101
102
103
104
105
106
107
#!/bin/sh
#
# Checks if the '%%USER%%' user and '%%GROUP%%' group exist. If they don't, then
# an attempt is made to create both.
#
# $FreeBSD$
#

PATH=/usr/bin:/bin:/usr/sbin:/usr/local/bin

# Set some constants
UID=%%UID%%
GID=${UID}
USER=%%USER%%
GROUP=%%GROUP%%
APP_HOME=%%APP_HOME%%
JAVA_HOME=%%JAVA_HOME%%
LOG_DIR=%%LOG_DIR%%
STDOUT_LOG=%%STDOUT_LOG%%
STDERR_LOG=%%STDERR_LOG%%

uidgid() {
if ! pw groupshow "${GROUP}" 2>/dev/null 1>&2; then

    # If not, try to create it
    if pw groupadd "${GROUP}" -g ${GID}; then
        echo "Added group \"${GROUP}\"."
    elif pw groupadd "${GROUP}"; then
        echo "Added group \"${GROUP}\"."
    else
        echo "Adding group \"${GROUP}\" failed..."
        exit 1
    fi
else
    echo "You already have a group \"${GROUP}\", so I will use it."
fi

# See if the user already exists
if ! pw usershow "${USER}" 2>/dev/null 1>&2; then

    # If not, try to create it
    if pw useradd "${USER}" -u ${UID} -g "${GROUP}" -h - \
                -s "/usr/sbin/nologin" -d "/nonexistent" \
                -c "World Wide Web Owner";
    then
        echo "Added user \"${USER}\"."
    elif pw useradd "${USER}" -g "${GROUP}" -h - \
                -s "/usr/sbin/nologin" -d "/nonexistent" \
                -c "World Wide Web Owner";
    then
        echo "Added user \"${USER}\"."
    else
        echo "Adding user \"${USER}\" failed..."
        exit 1
    fi
else
    echo "You already have a user \"${USER}\", so I will use it."
fi
}


post() {
    echo -n ">> Creating destination directory..."
    mkdir -p ${APP_HOME}
    mkdir -p ${LOG_DIR}
    echo " [ DONE ]"

    echo ">> Copying files to destination directory..."

    echo " [ DONE ]"
 
    echo -n ">> Creating log files..."
    install -m 664 -o ${USER} -g ${GROUP} /dev/null ${STDOUT_LOG}
    install -m 664 -o ${USER} -g ${GROUP} /dev/null ${STDERR_LOG}
    echo " [ DONE ]"

    echo -n ">> Creating symlink to tools.jar..."
    ln -sf ${JAVA_HOME}/lib/tools.jar ${APP_HOME}/common/lib/tools.jar
    echo " [ DONE ]"

    echo -n ">> Fixing ownership settings..."
    chown -R ${USER}:${GROUP} ${APP_HOME}/conf ${APP_HOME}/logs \
        ${APP_HOME}/temp ${APP_HOME}/work ${APP_HOME}/webapps
    chmod -R a+r ${APP_HOME}/common ${APP_HOME}/server ${APP_HOME}/bin
    echo " [ DONE ]"

    echo -n ">> Fixing permissions..."
    find ${APP_HOME} -type d -exec chmod 755 {} \; 
    echo " [ DONE ] "
}


# PACKAGE_BUILDING is only defined on the build cluster or tinderbox!
# No interactive parts, there is no one who can answer!
if [ "x${PACKAGE_BUILDING}" != "x" ]; then
    uidgid
    post
    exit 0
fi

if [ "$2" = "POST-INSTALL" ]; then
    uidgid
    post
    exit 0
fi

exit 0