2018-03-28 03:14:52 +02:00
|
|
|
#!/bin/bash
|
2017-08-18 04:28:56 +02:00
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
# Setup
|
|
|
|
|
|
|
|
GROUPNAME="bitwarden"
|
2018-03-28 04:57:30 +02:00
|
|
|
USERNAME="bitwarden"
|
2018-04-16 21:30:07 +02:00
|
|
|
|
|
|
|
CURRENTGID=`getent group $GROUPNAME | cut -d: -f3`
|
|
|
|
LGID=${LOCAL_GID:-999}
|
|
|
|
|
2018-04-16 22:26:08 +02:00
|
|
|
NOUSER=`id -u $USERNAME > /dev/null 2>&1; echo $?`
|
2018-03-27 22:38:11 +02:00
|
|
|
LUID=${LOCAL_UID:-999}
|
2018-03-28 04:57:30 +02:00
|
|
|
|
|
|
|
# Step down from host root
|
2018-04-16 21:30:07 +02:00
|
|
|
|
|
|
|
if [ $LGID == 0 ]
|
|
|
|
then
|
|
|
|
LGID=999
|
|
|
|
fi
|
|
|
|
|
2018-03-28 04:57:30 +02:00
|
|
|
if [ $LUID == 0 ]
|
|
|
|
then
|
|
|
|
LUID=999
|
|
|
|
fi
|
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
# Create group
|
|
|
|
|
|
|
|
if [ $CURRENTGID ]
|
|
|
|
then
|
2018-04-16 22:09:08 +02:00
|
|
|
if [ "$CURRENTGID" != "$LGID" ]
|
2018-04-16 21:30:07 +02:00
|
|
|
then
|
|
|
|
groupmod -g $LGID $GROUPNAME
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
groupadd -g $LGID $GROUPNAME
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create user and assign group
|
|
|
|
|
2018-04-16 22:26:08 +02:00
|
|
|
if [ $NOUSER == 0 ] && [ `id -u $USERNAME` != $LUID ]
|
2018-03-27 22:38:11 +02:00
|
|
|
then
|
2018-03-28 04:57:30 +02:00
|
|
|
usermod -u $LUID $USERNAME
|
2018-03-27 22:38:11 +02:00
|
|
|
elif [ $NOUSER == 1 ]
|
|
|
|
then
|
2018-04-16 21:30:07 +02:00
|
|
|
useradd -r -u $LUID -g $GROUPNAME $USERNAME
|
2018-03-27 22:38:11 +02:00
|
|
|
fi
|
2018-03-27 20:55:33 +02:00
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
# Make home directory for user
|
|
|
|
|
2018-04-03 03:11:32 +02:00
|
|
|
if [ ! -d "/home/$USERNAME" ]
|
|
|
|
then
|
|
|
|
mkhomedir_helper $USERNAME
|
|
|
|
fi
|
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
# The rest...
|
|
|
|
|
2018-03-27 20:55:33 +02:00
|
|
|
touch /var/log/cron.log
|
2018-04-16 21:30:07 +02:00
|
|
|
chown $USERNAME:$GROUPNAME /var/log/cron.log
|
2018-03-27 20:55:33 +02:00
|
|
|
mkdir -p /etc/bitwarden/mssql/backups
|
2018-04-16 21:30:07 +02:00
|
|
|
chown -R $USERNAME:$GROUPNAME /etc/bitwarden
|
2018-03-27 20:55:33 +02:00
|
|
|
mkdir -p /var/opt/mssql/data
|
2018-04-16 21:30:07 +02:00
|
|
|
chown -R $USERNAME:$GROUPNAME /var/opt/mssql
|
|
|
|
chown $USERNAME:$GROUPNAME /backup-db.sh
|
|
|
|
chown $USERNAME:$GROUPNAME /backup-db.sql
|
2018-03-27 20:55:33 +02:00
|
|
|
|
2017-08-21 16:58:00 +02:00
|
|
|
env >> /etc/environment
|
|
|
|
cron
|
2018-03-27 03:38:32 +02:00
|
|
|
|
2018-04-16 21:30:07 +02:00
|
|
|
gosu $USERNAME:$GROUPNAME /opt/mssql/bin/sqlservr
|