????
| Current Path : /etc/Acronis/Scripts/ |
| Current File : //etc/Acronis/Scripts/add_user_to_acronis_group.sh |
#!/bin/bash
# This script is part of Acronis Backup
# It is supported by Acronis only as part of the entire solution in accordance with http://www.acronis.com/support/eula-corp.html
# By using this script you accept the terms of the EULA http://www.acronis.com/support/eula-corp.html
# Use outside of the solution is done at your own risk and will not be supported by Acronis
# Contact http://www.acronis.com/en-us/support/ with any questions or concerns
# Copyright (C) 2020 Acronis
# args - USER GROUP_TO_ADD DIR_TO_ADJUST_ATTRS
USER="$1"; shift
GROUP_TO_ADD="$1"; shift
DIR_TO_ADJUST_ATTRS="$1"; shift
function check_user_exists()
{
id "$1" &>/dev/null;
}
function check_group_exists()
{
getent group "$1" &>/dev/null;
}
if [ -z "$USER" -o -z "$GROUP_TO_ADD" -o -z "$DIR_TO_ADJUST_ATTRS" ]; then
exit 1
fi
check_user_exists "$USER"
if [ "$?" != "0" ]; then
exit 1
fi
check_group_exists "$GROUP_TO_ADD"
if [ "$?" != "0" ]; then
groupadd -f "$GROUP_TO_ADD"
if [ "$?" != "0" ]; then
exit 1
fi
fi
if [ ! -d "$DIR_TO_ADJUST_ATTRS" ]; then
mkdir -m 770 -p "$DIR_TO_ADJUST_ATTRS"
if [ "$?" != "0" ]; then
exit 1
fi
fi
usermod -a -G "$GROUP_TO_ADD" "$USER"
if [ "$?" != "0" ]; then
exit 1
fi
chown -f "root.$GROUP_TO_ADD" "$DIR_TO_ADJUST_ATTRS"
if [ "$?" != "0" ]; then
exit 1
fi
exit 0