|
1 | 1 | #!/bin/sh |
2 | 2 | set -e |
3 | 3 |
|
4 | | -composer-debian cnb-cache |
5 | | - |
6 | | -. /usr/share/debconf/confmodule |
7 | | - |
8 | | -db_version 2.0 |
9 | | - |
10 | | -pathfind() { |
11 | | - OLDIFS="$IFS" |
12 | | - IFS=: |
13 | | - for p in $PATH; do |
14 | | - if [ -x "$p/$*" ]; then |
15 | | - IFS="$OLDIFS" |
16 | | - return 0 |
17 | | - fi |
18 | | - done |
19 | | - IFS="$OLDIFS" |
20 | | - return 1 |
21 | | -} |
22 | | - |
23 | | -lighttpd_install() { |
24 | | - if [ -d /etc/lighttpd/conf-available ] && [ ! -f /etc/lighttpd/conf-available/50-cnb-cache.conf ]; then |
25 | | - if pathfind lighty-enable-mod; then |
26 | | - ln -s /etc/cnb-cache/lighttpd.conf /etc/lighttpd/conf-available/50-cnb-cache.conf |
27 | | - if ! { lighty-enable-mod cnb-cache fastcgi fastcgi-php || [ $? -eq 2 ]; }; then |
28 | | - return 1 |
29 | | - fi |
30 | | - fi |
31 | | - fi |
32 | | -} |
33 | | - |
34 | | -[ ! -e /usr/share/apache2/apache2-maintscript-helper ] || . /usr/share/apache2/apache2-maintscript-helper |
35 | | - |
36 | | -apache_install() { |
37 | | - if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then |
38 | | - if [ -d /etc/apache2/conf-available ] && [ ! -e /etc/apache2/conf-available/cnb-cache.conf ]; then |
39 | | - ln -s /etc/cnb-cache/apache.conf /etc/apache2/conf-available/cnb-cache.conf |
40 | | - fi |
41 | | - # Remove old symlink if present |
42 | | - if [ -d /etc/apache2/conf.d ] && [ -h /etc/apache2/conf.d/cnb-cache ]; then |
43 | | - rm /etc/apache2/conf.d/cnb-cache |
44 | | - fi |
45 | | - # Enable the configuration |
46 | | - apache2_invoke enconf cnb-cache.conf |
47 | | - fi |
48 | | -} |
49 | | - |
50 | | -case "$1" in |
51 | | -configure) |
52 | | - |
53 | | - # If the package has default file it could be sourced, so that |
54 | | - # the local admin can overwrite the defaults |
55 | | - |
56 | | - # shellcheck disable=SC1091 |
57 | | - [ -f "/etc/default/cnb-cache" ] && . /etc/default/cnb-cache |
58 | | - |
59 | | - # Sane defaults: |
60 | | - |
61 | | - [ -z "$SERVER_HOME" ] && SERVER_HOME=/var/lib/cnb-cache |
62 | | - [ -z "$SERVER_USER" ] && SERVER_USER=cnb-cache |
63 | | - [ -z "$SERVER_NAME" ] && SERVER_NAME="cnb-cache" |
64 | | - [ -z "$SERVER_GROUP" ] && SERVER_GROUP=cnb-cache |
65 | | - |
66 | | - # Groups that the user will be added to, if undefined, then none. |
67 | | - ADDGROUP="cnb-cache" |
68 | | - |
69 | | - # create user to avoid running server as root |
70 | | - # 1. create group if not existing |
71 | | - if ! getent group | grep -q "^$SERVER_GROUP:"; then |
72 | | - echo -n "Adding group $SERVER_GROUP.." |
73 | | - addgroup --quiet --system "$SERVER_GROUP" 2>/dev/null || true |
74 | | - echo "..done" |
75 | | - fi |
76 | | - # 2. create homedir if not existing |
77 | | - test -d "$SERVER_HOME" || mkdir "$SERVER_HOME" |
78 | | - # 3. create user if not existing |
79 | | - if ! getent passwd | grep -q "^$SERVER_USER:"; then |
80 | | - echo -n "Adding system user $SERVER_USER.." |
81 | | - adduser --quiet \ |
82 | | - --system \ |
83 | | - --ingroup "$SERVER_GROUP" \ |
84 | | - --home /var/lib/cnb-cache \ |
85 | | - --disabled-password \ |
86 | | - "$SERVER_USER" 2>/dev/null || true |
87 | | - echo "..done" |
88 | | - fi |
89 | | - # 4. adjust passwd entry |
90 | | - usermod -c "$SERVER_NAME" \ |
91 | | - -d "$SERVER_HOME" \ |
92 | | - -g "$SERVER_GROUP" \ |
93 | | - "$SERVER_USER" |
94 | | - # 5. adjust file and directory permissions |
95 | | - if ! dpkg-statoverride --list "$SERVER_HOME" >/dev/null; then |
96 | | - chown -R "$SERVER_USER":adm "$SERVER_HOME" |
97 | | - chmod u=rwx,g=rxs,o= "$SERVER_HOME" |
98 | | - fi |
99 | | - # 6. Add the user to the ADDGROUP group |
100 | | - if test -n $ADDGROUP; then |
101 | | - if ! groups "$SERVER_USER" | cut -d: -f2 | |
102 | | - grep -qw $ADDGROUP; then |
103 | | - adduser "$SERVER_USER" $ADDGROUP |
104 | | - fi |
105 | | - fi |
106 | | - |
107 | | - echo "Reconfigurning Web Server" |
108 | | - |
109 | | - |
110 | | - db_get cnb-cache/reconfigure-webserver || true |
111 | | - webservers="$RET" |
112 | | - restart="" |
113 | | - |
114 | | - for webserver in $webservers; do |
115 | | - webserver=${webserver%,} |
116 | | - case "$webserver" in |
117 | | - lighttpd) |
118 | | - lighttpd_install |
119 | | - ;; |
120 | | - apache2) |
121 | | - apache_install |
122 | | - ;; |
123 | | - esac |
124 | | - pathfind "$webserver" || continue |
125 | | - restart="$restart $webserver" |
126 | | - done |
127 | | - |
128 | | - db_get cnb-cache/restart-webserver || true |
129 | | - res="$RET" |
130 | | - db_go || true |
131 | | - if [ "$res" = "true" ]; then |
132 | | - for webserver in $restart; do |
133 | | - webserver=${webserver%,} |
134 | | - # Redirection of 3 is needed because Debconf uses it and it might |
135 | | - # be inherited by webserver. See bug #446324. |
136 | | - if pathfind invoke-rc.d; then |
137 | | - invoke-rc.d "$webserver" reload 3>/dev/null || true |
138 | | - else |
139 | | - /etc/init.d/"$webserver" reload 3>/dev/null || true |
140 | | - fi |
141 | | - done |
142 | | - fi |
143 | | - |
144 | | - db_get cnb-cache/currencies || true |
145 | | - currencies="$RET" |
146 | | - db_go || true |
147 | | - |
148 | | - echo "Currencies to cache: $currencies" |
149 | | - |
150 | | - # Update or populate CURRENCIES key in /etc/cnb-cache/cnb-cache.env with $currencies |
151 | | - if [ -n "$currencies" ]; then |
152 | | - if grep -q "^CURRENCIES=" /etc/cnb-cache/cnb-cache.env; then |
153 | | - sed -i "s/^CURRENCIES=.*/CURRENCIES=\"$currencies\"/" /etc/cnb-cache/cnb-cache.env |
154 | | - else |
155 | | - echo "CURRENCIES=\"$currencies\"" >>/etc/cnb-cache/cnb-cache.env |
156 | | - fi |
157 | | - fi |
158 | | - |
159 | | - db_get cnb-cache/keepdays || true |
160 | | - keepdays="$RET" |
161 | | - db_go || true |
162 | | - |
163 | | - echo "Number of days to keep cache: $keepdays" |
164 | | - |
165 | | - # Update or populate KEEP_DAYS key in /etc/cnb-cache/cnb-cache.env with $keepdays |
166 | | - if [ -n "$keepdays" ]; then |
167 | | - if grep -q "^KEEP_DAYS=" /etc/cnb-cache/cnb-cache.env; then |
168 | | - sed -i "s/^KEEP_DAYS=.*/KEEP_DAYS=\"$keepdays\"/" /etc/cnb-cache/cnb-cache.env |
169 | | - else |
170 | | - echo "KEEP_DAYS=\"$keepdays\"" >>/etc/cnb-cache/cnb-cache.env |
171 | | - fi |
172 | | - fi |
173 | | - |
174 | | - echo "Migrate database" |
175 | | - phinx migrate -c /usr/lib/cnb-cache/phinx-adapter.php || true |
176 | | - |
177 | | - echo "Initializing cache" |
178 | | - |
179 | | - |
180 | | - APP_DEBUG=True cnb-cache-init || true |
181 | | - |
182 | | - ;; |
183 | | - |
184 | | -abort-upgrade | abort-remove | abort-deconfigure) ;; |
185 | | - |
186 | | -*) |
187 | | - echo "postinst called with unknown argument \`$1'" >&2 |
188 | | - exit 1 |
189 | | - ;; |
190 | | -esac |
191 | | - |
192 | 4 | #DEBHELPER# |
193 | 5 |
|
194 | 6 | exit 0 |
0 commit comments