Deals with already existing user/group backuppc

This commit is contained in:
Adrien Ferrand 2017-11-15 11:24:53 +01:00
parent 70d186880c
commit f603a49d1d
3 changed files with 22 additions and 10 deletions

View File

@ -10,14 +10,26 @@ if [ -f /firstrun ]; then
cp /usr/share/zoneinfo/$TZ /etc/localtime
fi
# Create backuppc user
addgroup -S -g ${BACKUPPC_GUID:-1000} backuppc
adduser -D -S -h /home/backuppc -G backuppc -u ${BACKUPPC_UUID:-1000} backuppc
chown backuppc:backuppc /home/backuppc
# Create backuppc user/group if needed
BACKUPPC_GROUPNAME=`getent group "${BACKUPPC_GUID:-1000}" | cut -d: -f1`
if [ -z "$BACKUPPC_GROUPNAME" ]; then
groupadd -r -g "${BACKUPPC_GUID:-1000}" backuppc
BACKUPPC_GROUPNAME="backuppc"
fi
BACKUPPC_USERNAME=`getent group "${BACKUPPC_UUID:-1000}" | cut -d: -f1`
if [ -z "$BACKUPPC_USERNAME" ]; then
useradd -r -d /home/backuppc -g "${BACKUPPC_GUID:-1000}" -u ${BACKUPPC_UUID:-1000} -M -N backuppc
BACKUPPC_USERNAME="backuppc"
else
usermod -d /home/backuppc "$BACKUPPC_USERNAME"
fi
chown "$BACKUPPC_USERNAME":"$BACKUPPC_GROUPNAME" /home/backuppc
export BACKUPPC_USERNAME
export BACKUPPC_GROUPNAME
# Generate cryptographic key
if [ ! -f /home/backuppc/.ssh/id_rsa ]; then
su backuppc -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/backuppc/.ssh/id_rsa"
su "$BACKUPPC_USERNAME" -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/backuppc/.ssh/id_rsa"
fi
# Extract BackupPC
@ -59,14 +71,14 @@ if [ -f /firstrun ]; then
-subj "/C=UK/ST=Warwickshire/L=Leamington/O=OrgName/OU=IT Department/CN=example.com"
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
cat server.key server.crt > server.pem
chown backuppc:backuppc server.pem
chown "$BACKUPPC_USERNAME":"$BACKUPPC_GROUPNAME" server.pem
chmod 0600 server.pem
rm -f server.pass.key server.key server.csr server.crt
# Reconfigure lighttpd to use ssl
echo "ssl.engine = \"enable\"" >> /etc/lighttpd/lighttpd.conf
echo "ssl.pemfile = \"/etc/lighttpd/server.pem\"" >> /etc/lighttpd/lighttpd.conf
fi
touch /var/log/lighttpd/error.log && chown -R backuppc:backuppc /var/log/lighttpd
touch /var/log/lighttpd/error.log && chown -R "$BACKUPPC_USERNAME":"$BACKUPPC_GROUPNAME" /var/log/lighttpd
# Configure standard mail delivery parameters (may be overriden by backuppc user-wide config)
echo "account default" > /etc/msmtprc

View File

@ -1,6 +1,6 @@
server.port = 8080
server.username = "backuppc"
server.groupname = "backuppc"
server.username = env.BACKUPPC_USERNAME
server.groupname = env.BACKUPPC_GROUPNAME
server.document-root = "/srv/http"
server.errorlog = "/var/log/lighttpd/error.log"
dir-listing.activate = "enable"

View File

@ -30,4 +30,4 @@ killasgroup = true
[program:backuppc]
command = /usr/local/BackupPC/bin/BackupPC
redirect_stderr = true
user = backuppc
user = %(ENV_BACKUPPC_USERNAME)s