servnest-mkosi/mkosi.postinst

92 lines
2.4 KiB
Plaintext
Raw Normal View History

2022-04-20 00:29:47 +02:00
#!/usr/bin/bash
source /etc/os-release
# Create system users
useradd -U -r -s /usr/sbin/nologin nginx
2022-06-23 19:50:50 +02:00
useradd -U -r -s /usr/sbin/nologin niver
useradd -U -r -s /usr/sbin/nologin sftpgo
# Set proper permissions
2022-05-03 19:18:09 +02:00
chown -R knot:knot /var/lib/knot/confdb
chmod -R u=rwX,g=rwX,o= /var/lib/knot/confdb
2022-06-23 19:50:50 +02:00
usermod -aG knot niver
chown -R knot:knot /var/log/knot
2022-06-23 19:50:50 +02:00
chmod -R u=rwX,g=,o= /var/log/knot
2022-06-23 19:50:50 +02:00
chown -R niver:knot /srv/niver/ns
chmod -R u=rwX,g=rwX,o= /srv/niver/ns
chown -R niver:knot /srv/niver/reg
chmod -R u=rwX,g=rwX,o= /srv/niver/reg
2022-06-23 19:50:50 +02:00
chown -R niver:nginx /srv/niver/nginx
chmod -R u=rwX,g=rX,o= /srv/niver/nginx
chown -R sftpgo:sftpgo /etc/sftpgo
2022-05-31 23:56:38 +02:00
chmod -R u=rX,g=rX,o=rX /etc/sftpgo
chmod u=r,g=,o= /etc/sftpgo/ed25519
2022-06-23 19:50:50 +02:00
chown -R niver:sftpgo /srv/niver/ht
chmod -R u=rwX,g=rwX,o=rX /srv/niver/ht
2022-05-06 14:08:38 +02:00
if [[ $ID = "debian" ]]; then
2022-06-23 19:50:50 +02:00
chown -R niver:debian-tor /srv/niver/tor-config
chown -R debian-tor:debian-tor /srv/niver/tor-keys
2022-05-06 14:08:38 +02:00
else
2022-06-23 19:50:50 +02:00
chown -R niver:tor /srv/niver/tor-config
chown -R tor:tor /srv/niver/tor-keys
2022-05-06 14:08:38 +02:00
fi
2022-06-23 19:50:50 +02:00
chmod -R u=rwX,g=rX,o= /srv/niver/tor-config
chmod -R u=rwX,g=,o= /srv/niver/tor-keys
2022-05-05 02:03:01 +02:00
2022-06-23 19:50:50 +02:00
chown -R niver:nginx /srv/niver/core /srv/niver/errors
chmod -R u=rX,g=rX,o= /srv/niver/core /srv/niver/errors
chown -R niver:niver /srv/niver/core/db
chmod -R u=rwX,g=,o= /srv/niver/core/db
# Load configuration in Knot database
sudo -u knot knotc conf-import /etc/knot/knot.conf
2022-05-05 02:03:01 +02:00
# PHP paths unification across distributions
export PHP_INI=/etc/php/php.ini
if [[ $ID = "debian" ]]; then
2022-05-09 02:39:53 +02:00
rm /etc/php/8.1/fpm/php-fpm.conf
ln -s /etc/php/php-fpm.conf /etc/php/8.1/fpm/php-fpm.conf
ln -s /etc/php/php-fpm.d/ /etc/php/8.1/fpm/pool.d
2022-05-09 02:39:53 +02:00
export PHP_INI=/etc/php/8.1/fpm/php.ini
fi
# Configure PHP-FPM properly
cat >> $PHP_INI << EOF
expose_php = Off
display_errors = On
extension = pdo_sqlite
EOF
2022-06-10 03:20:19 +02:00
# Configure Tor
if [[ $ID = "debian" ]]; then
2022-06-10 03:20:19 +02:00
sed -i 's/User tor/User debian-tor/' /etc/tor/torrc
sed -i 's/reload tor/reload tor@default/' /etc/sudoers.d/niver
sed -i 's/ALL=(tor)/ALL=(debian-tor)/' /etc/sudoers.d/niver
2022-06-23 19:50:50 +02:00
sed -i 's/tor_service = "tor"/tor_service = "tor@default"/' /srv/niver/core/config.ini
sed -i 's/tor_user = "tor"/tor_user = "debian-tor"/' /srv/niver/core/config.ini
2022-05-05 02:03:01 +02:00
fi
# Start SystemD services at startup
systemctl enable sftpgo
2022-04-20 00:29:47 +02:00
if [[ $ID = "arch" ]]; then
systemctl enable sshd
systemctl enable knot
systemctl enable nginx
2022-05-04 17:45:05 +02:00
systemctl enable tor
2022-04-20 00:29:47 +02:00
systemctl enable php-fpm
fi