Skip to content
Snippets Groups Projects
Commit 8ca631c2 authored by Thiago Abdo's avatar Thiago Abdo
Browse files

add last version of hd_user.sh as local_accounts.sh


Signed-off-by: default avatarThiago Abdo <tja14@inf.ufpr.br>
parent e4ea32e2
No related branches found
No related tags found
No related merge requests found
#!/bin/ash
#Check if the user running this code has permissoes to run it
if [ "$(/opt/openslx/bin/id -u)" != "0" ]; then
echo $0": Você não possue as permissoes necessárias para realizar essa operação"
exit 1
else
echo $0": Você tem permissoes para executar esse programa"
fi
if [ -z "$1" ];then
. /opt/openslx/config || { echo "Could not source config!"; exit 23; }
else
. "$1" || { echo "Could not source custom config!"; exit 23; }
fi
for file in passwd group shadow; do
if [ -e /home/openslx/localaccounts/bak/$file ]; then
echo $0": Copying "$file" from backup"
cp /home/openslx/localaccounts/bak/$file /etc/$file
fi
done
unset IFS
set $SLX_USERS
while (( [ $# -gt 0 ] )); do
#Get infos from file
passwdf=$(echo $1 | cut -d'=' -f2)
shift
shadowf=$(echo $1 | cut -d'=' -f2)
shift
groupf=$(echo $1 | cut -d'=' -f2)
shift
username=$( echo $passwdf | cut -d':' -f1 )
uID=$( echo $passwdf | cut -d':' -f3 )
globalID=$( echo $uID | grep -e "^3....$" )
groupname=$( echo $groupf | cut -d':' -f1 )
gID=$( echo $groupf | cut -d':' -f3 )
globalGID=$( echo $gID | grep -e "^3....$" )
#group == username
if [ "$username" = "$groupname" ]; then
#id no range certo(local user)
if [ -n "$globalID" ] && [ -n "$globalGID" ]; then
#add to files;
#echo "aqui"
/opt/openslx/scripts/adduser.sh "$passwdf" "$groupf" "$shadowf" "global"
fi
fi
done
#add groups to global users
for line in $SLX_GROUPS; do
echo $0": "$line
IFS=,
set $line
username=$1
shift
while (( [ $# -gt 0 ] )); do
echo $0:"addusertogroup "$username" "$1
temp=$(mktemp)
firstuser=$( cat /etc/group | grep -e "^$1:.*:.*:$" )
if [ -n "$firstuser" ]; then
sed -e "s/^$1.*/&$username/" /etc/group > $temp
else
sed -e "s/^$1.*/&,$username/" /etc/group > $temp
fi
cp $temp /etc/group
chown root:root /etc/group
chmod 644 /etc/group
rm $temp
shift
done
unset IFS
done
#Instanciates the configuration file
if [ ! -e /home/openslx/localaccounts/config ]; then
echo $0": Configuration of local users doesn't exist, creating a blank one"
> /home/openslx/localaccounts/config
fi
unset IFS
users=$(cat /home/openslx/localaccounts/config);
set $users
while (( [ $# -gt 0 ] )); do
#Get infos from file
passwdf=$(echo $1 | cut -d'=' -f2)
shift
shadowf=$(echo $1 | cut -d'=' -f2)
shift
groupf=$(echo $1 | cut -d'=' -f2)
shift
username=$( echo $passwdf | cut -d':' -f1 )
uID=$( echo $passwdf | cut -d':' -f3 )
localID=$( echo $uID | grep -e "^2....$" -e "^1....$" )
groupname=$( echo $groupf | cut -d':' -f1 )
gID=$( echo $groupf | cut -d':' -f3 )
localGID=$( echo $gID | grep -e "^2....$" -e "^1....$" )
#group == username
if [ "$username" = "$groupname" ]; then
#id no range certo(local user)
if [ -n "$localID" ] && [ -n "$localGID" ]; then
#add to files;
/opt/openslx/scripts/adduser.sh "$passwdf" "$groupf" "$shadowf"
fi
fi
done
#if [ -d /home/openslx ]; then
#Create records
#fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment