diff --git a/usb_drive/local_accounts.sh b/usb_drive/local_accounts.sh new file mode 100755 index 0000000000000000000000000000000000000000..1fa49ee1b0b1006d3607d7dd22aa730326e94e0f --- /dev/null +++ b/usb_drive/local_accounts.sh @@ -0,0 +1,118 @@ +#!/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 +