]> Raphaƫl G. Git Repositories - ihttpd/blob - SOURCES/ihttpd.module-setup
c5ba6d271bd6b0ea026c4eda4ed4846880dd646c
[ihttpd] / SOURCES / ihttpd.module-setup
1 #!/bin/bash
2
3 # called by dracut
4 check() {
5 local fs
6
7 # Fix tmpfiledir
8 #XXX: fix installation of /usr/lib/tmpfileS.d/{dracut-tmpfiles,systemd}.conf
9 #XXX: should be removed when bug 18642 (mageia) or 1343230 (fedora) will be fixed in /usr/bin/dracut +1262-1282
10 [ -z "$tmpfilesdir" -o ! -d "$tmpfilesdir" -a -d /usr/lib/tmpfiles.d ] && tmpfilesdir=/usr/lib/tmpfiles.d
11 [ -z "$tmpfilesdir" -o ! -d "$tmpfilesdir" -a -d /etc/tmpfiles.d ] && tmpfilesdir=/etc/tmpfiles.d
12 [ -z "$tmpfilesdir" -o ! -d "$tmpfilesdir" -a -d /lib/tmpfiles.d ] && tmpfilesdir=/lib/tmpfiles.d
13
14 # if cryptsetup is not installed, then we cannot support encrypted devices.
15 require_binaries cryptsetup || return 1
16
17 # if hostonly or mount_needs include if required by other module
18 # if one of fs types is crypto_LUKS include it
19 [[ $hostonly ]] || [[ $mount_needs ]] && {
20 for fs in "${host_fs_types[@]}"; do
21 [[ $fs = "crypto_LUKS" ]] && return 0
22 done
23 return 255
24 }
25
26 return 0
27 }
28
29 # called by dracut
30 depends() {
31 # depend on crypt for /etc/crypttab
32 # depend on systemd-networkd for ip=dhcp and rd.neednet=1
33 # depend on dracut-systemd for appending to $tmpfilesdir/dracut-tmpfiles.conf
34 echo crypt systemd-networkd dracut-systemd
35 return 0
36 }
37
38 # called by dracut
39 cmdline() {
40 local fs
41 for fs in "${host_fs_types[@]}"; do
42 if [[ "$fs" == "crypto_LUKS" ]]; then
43 printf "%s" " ip=dhcp rd.neednet=1"
44 break
45 fi
46 done
47 }
48
49 # called by dracut
50 install() {
51 local _ihttpdconf=$(cmdline)
52 local fs
53 [[ $_ihttpdconf ]] && printf "%s\n" "$_ihttpdconf" >> "${initdir}/etc/cmdline.d/99ihttpd.conf"
54
55 # Install cert dirs
56 inst_dir /etc/pki/tls/certs
57 inst_dir /etc/pki/tls/private
58 inst_dir /etc/systemd/network
59 inst_dir /var/www/html
60 inst_dir $systemdsystemunitdir/ihttpd.service.wants
61
62 # Install favicon
63 inst_simple -o /var/www/html/favicon.ico
64
65 # Install network
66 for nc in `ls /etc/systemd/network/`; do
67 inst_simple /etc/systemd/network/$nc
68 done
69
70 # Install index.bin
71 inst_simple /usr/lib/ihttpd/index.bin /var/www/html/index.bin
72
73 # Install reboot.bin
74 inst_simple /usr/lib/ihttpd/reboot.bin /var/www/html/reboot.bin
75
76 # Install all files
77 inst_multiple \
78 /etc/hosts \
79 /etc/mime.types \
80 /etc/localtime \
81 /etc/nsswitch.conf \
82 /etc/ihttpd.conf \
83 /etc/pki/tls/certs/ihttpd.pem \
84 /etc/pki/tls/private/ihttpd.pem \
85 $tmpfilesdir/ihttpd.conf \
86 $systemdsystemunitdir/ihttpd.path \
87 $systemdsystemunitdir/ihttpd.service \
88 $systemdsystemunitdir/systemd-networkd.service \
89 $systemdsystemunitdir/systemd-tmpfiles-setup.service \
90 '/usr/bin/false' \
91 '/usr/bin/reboot' \
92 /usr/sbin/ihttpd
93
94 # Install ihttpd.path
95 ln -fs ../ihttpd.path $initdir$systemdsystemunitdir/sysinit.target.wants/
96
97 # Install resolv.conf as resolved service
98 #TODO: change this to have a content or depend on systemd-resolved
99 if [ -L /etc/resolv.conf ]; then
100
101 # Install systemd-resolved
102 if [ `readlink /etc/resolv.conf` = '/run/systemd/resolve/resolv.conf' ]; then
103
104 # Install resolv.conf as symlink
105 ln -fs '/run/systemd/resolve/resolv.conf' $initdir/etc/resolv.conf
106
107 # Install systemd-resolved
108 inst_multiple \
109 $systemdsystemunitdir/systemd-resolved.service \
110 $systemdutildir/systemd-resolved \
111 /etc/systemd/resolved.conf
112
113 # Require systemd-resolve user and group for our ihttpd process
114 `egrep -q '^systemd-resolve:' $initdir/etc/group` || egrep '^systemd-resolve:' /etc/group >> "$initdir/etc/group"
115 `egrep -q '^systemd-resolve:' $initdir/etc/passwd` || egrep '^systemd-resolve:' /etc/passwd >> "$initdir/etc/passwd"
116
117 # Install in ihttpd.service.wants
118 ln -fs ../systemd-resolved.service $initdir$systemdsystemunitdir/ihttpd.service.wants/
119
120 # Cleanup resolved.conf
121 perl -pne 'undef $_ if /^(?:#.*|Domains=|FallbackDNS=|DNS=(?:127.0.0.1|::1)$|$)/;/^DNS=/ && $_ =~ s/(?:127.0.0.1|::1)[ \t]*//g' \
122 -i "$initdir/etc/systemd/resolved.conf"
123
124 # Cleanup systemd-resolved.service
125 perl -pne 'undef $_ if /^(?:#|(?:Wants|After)=org\.freedesktop\.resolve1\.busname)/' \
126 -i "$initdir$systemdsystemunitdir/systemd-resolved.service"
127
128 # Try install the target file
129 else
130 inst_simple /etc/resolv.conf
131 fi
132
133 # Install resolv.conf as file
134 elif [ -e /etc/resolv.conf ]; then
135
136 # Install resolv.conf as file
137 inst_simple /etc/resolv.conf
138
139 # Cleanup resolv.conf
140 #XXX: strip search, localhost and ipv6
141 perl -pne 'undef $_ if /^(?:#.*|search\s+|nameserver\s+127.0.0.1|nameserver\s+[^:\s]+:[^\s]+|$)/' \
142 -i "$initdir/etc/resolv.conf"
143
144 # Touch resolv.conf file
145 else
146 # We did what we could
147 touch "$initdir/etc/resolv.conf"
148 fi
149
150 # Install ihttpd log
151 ln -fs ../../../run/ihttpd/log/{http,https,child.{askpassword,ihttpd},error}.log $initdir/var/www/html/
152
153 # Install in ihttpd.service.wants
154 ln -fs ../systemd-networkd.service $initdir$systemdsystemunitdir/ihttpd.service.wants/
155 ln -fs ../systemd-tmpfiles-setup.service $initdir$systemdsystemunitdir/ihttpd.service.wants/
156
157 # Include all ihttpd deps
158 inst_libdir_file \
159 "ld-linux-*.so.*" \
160 "libapr-1.so.*" \
161 "libaprutil-1.so.*" \
162 "libcrypto.so.*" \
163 "libcrypt.so.*" \
164 "libc.so.*" \
165 "libdb-*.so" \
166 "libdl.so.*" \
167 "libexpat.so.*" \
168 "libnsl.so.*" \
169 "libpcre.so.*" \
170 "libpthread.so.*" \
171 "libresolv.so.*" \
172 "librt.so.*" \
173 "libuuid.so.*" \
174 "libz.so.*" \
175 "libnss_files.so.*" \
176 "libnss_dns.so.*" \
177 "libnss_myhostname.so.*" \
178 {"tls/$_arch/",tls/,"$_arch/",}"libssl.so.*"
179
180 # Cleanup nsswitch.conf
181 if [ -f "$initdir/etc/nsswitch.conf" ]; then
182 perl -pne 'undef $_ if /^(?:#|$)/;s/compat/files/;s/ ?(?:nis|wins|mdns4_minimal |mdns4)( )?/\1/g' \
183 -i "$initdir/etc/nsswitch.conf"
184 fi
185
186 # Cleanup systemd-networkd.service
187 if [ -f "$initdir$systemdsystemunitdir/systemd-networkd.service" ]; then
188 perl -pne 'undef $_ if /^(?:#|(?:Wants|After)=org\.freedesktop\.network1\.busname)/;s/^After=(systemd-udevd.service )dbus.service network-pre.target systemd-sysusers.service /After=\1/' \
189 -i "$initdir$systemdsystemunitdir/systemd-networkd.service"
190 fi
191
192 # Cleanup systemd-tmpfiles-setup.service
193 if [ -f "$initdir$systemdsystemunitdir/systemd-tmpfiles-setup.service" ]; then
194 perl -pne 'undef $_ if /^#/;s/After=(.*) systemd-sysusers.service/After=\1/' \
195 -i "$initdir$systemdsystemunitdir/systemd-tmpfiles-setup.service"
196 fi
197
198 #XXX: bug: fix /usr/lib/tmpfiles.d/{systemd,dracut-tmpfiles}.conf missing user and group
199 `egrep -q '^utmp:' $initdir/etc/group` || egrep '^utmp:' /etc/group >> "$initdir/etc/group"
200 # Require root user and group for our ihttpd process
201 `egrep -q '^root:' $initdir/etc/group` || egrep '^root:' /etc/group >> "$initdir/etc/group"
202 `egrep -q '^root:' $initdir/etc/passwd` || egrep '^root:' /etc/passwd >> "$initdir/etc/passwd"
203 }