rs-backup-suite/server/usr/sbin/rs-add-user

58 lines
1.5 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2013-04-02 18:25:38 +00:00
##
# rs-add-user
# Copyright (C) 2013 by Janek Bevendorff
# Website: http://www.refining-linux.org/
#
# Set up a backup user
##
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo "Usage: $(basename $0) <remote host> <remote username> [<ssh public key file>]"
exit
fi
2014-09-12 16:47:10 +00:00
. /etc/rs-backup/server-config
2013-04-02 18:25:38 +00:00
remote_hostname="$1"
remote_username="$2"
ssh_key_file="$3"
local_username="${remote_hostname}-${remote_username}"
useradd -G backup -b "${BACKUP_ROOT}" -m -k /etc/rs-skel -p '*' -s /bin/bash "${local_username}"
2013-04-02 18:25:38 +00:00
rs-update-passwd
# Generate config files from templates
USERNAME="${local_username}"
GROUPNAME="${local_username}"
HOME_DIR="${BACKUP_ROOT}/${local_username}"
2014-09-12 16:47:10 +00:00
rsync_conf="$(cat /etc/rs-backup/rsync.conf.template)"
rsnapshot_conf="$(cat /etc/rs-backup/rsnapshot.conf.template)"
2013-04-02 18:25:38 +00:00
rsync_conf=$(eval "cat << EOF
${rsync_conf}
EOF")
rsnapshot_conf=$(eval "cat << EOF
${rsnapshot_conf}
EOF")
echo "${rsync_conf}" > "${HOME_DIR}/rsync.conf"
echo "${rsnapshot_conf}" > "${HOME_DIR}/rsnapshot.conf"
# Protect config files
chown root:root "${HOME_DIR}/rsync.conf"
chmod 0644 "${HOME_DIR}/rsync.conf"
chown root:root "${HOME_DIR}/rsnapshot.conf"
chmod 0644 "${HOME_DIR}/rsnapshot.conf"
2013-07-10 16:26:27 +00:00
# Set permissions for backup directory
chown -R "${USERNAME}:${GROUPNAME}" "${HOME_DIR}/${FILES_DIR}"
2013-07-15 16:51:04 +00:00
chmod -R 0755 "${HOME_DIR}/${FILES_DIR}"
2013-07-10 16:26:27 +00:00
2013-04-02 18:25:38 +00:00
# If SSH key file has been specified
if [ "${ssh_key_file}" != "" ]; then
rs-add-ssh-key "${remote_hostname}" "${remote_username}" "${ssh_key_file}"
fi