Skip to content
Snippets Groups Projects
Commit 4491dced authored by Luiz Reis's avatar Luiz Reis
Browse files

Update insert_data


Signed-off-by: default avatarLuiz Reis <luizreis@outlook.com>
parent e4ea32e2
Branches
No related tags found
No related merge requests found
#!/bin/bash #!/bin/ash
DIR_USB=/media/usb_drive/
DIR_OPENSLX=/Openslx/
user_name=`users | cut -f 1 -d ' '`
# prepares openslx partition to be used # prepares openslx partition to be used
# mounts partition if not mounted # mounts partition if not mounted
# blocks program execution if it is not a openslx partition # blocks program execution if it is not a openslx partition
# param $1 is the devpath to be mounted # param $1 is the dev to be mounted
# param $2 is the uuid of the partition
# return is done via the mountpath global variable, which is also used here # return is done via the mountpath global variable, which is also used here
function prepare_usb { prepare_usb () {
# get the usb_drive's path # get the usb_drive's path
local devpath="/dev/"$1 local dev=$1
mountpath="" mountpath=""
if [ ! 0 -eq $(mount | grep -q $devpath) ]; then
echo $0": Device $devpath is already mounted" if $(mount | grep -q "/dev/$dev"); then
mountpath=$(mount | grep -w $devpath | cut -d' ' -f3) echo "$0: Device /dev/$dev is already mounted"
mountpath=$(df | grep -w $dev | cut -d'%' -f2- | cut -d' ' -f2-)
else else
echo $0": Device $devpath is not mounted" echo "$0: Device /dev/$dev is not mounted"
mkdir -p /media/openslx/$2 mkdir -p /media/openslx/$dev
if $(mount $devpath /media/openslx/$2); then if $(mount "/dev/$dev" /media/openslx/$dev); then
echo $0": Device $devpath mounted successfully" echo "$0: Device /dev/$dev mounted successfully"
mountpath="/media/openslx/"$2 mountpath="/media/openslx/$dev"
else else
echo $0": Device $devpath could not be mounted" echo "$0: Device /dev/$dev could not be mounted"
exit 1 exit 1
fi fi
fi fi
if [ -e "$mountpath/Openslx/config" ]; then if [ -e "$mountpath/Openslx/config" ]; then
echo $0": $devpath is an openslx ready drive" echo "$0: /dev/$dev is an openslx ready drive"
else else
echo $0": $devpath is not ready to be used as an openslx drive" echo "$0: /dev/$dev is not ready to be used as an openslx drive"
if [ $mountpath = "/media/openslx/$2" ]; then if [ "$mountpath" = "/media/openslx/$dev" ]; then
echo $0": umounting $devpath" echo "$0: umounting /dev/$dev"
umount $devpath umount -f -l "/dev/$dev"
fi fi
exit 2 exit 2
fi fi
} }
sleep 3 sleep 3 # let the system mount the drive first
#TIRAR FOR
# list all the usb_drives, mounted or not mounted
usb_drives=`ls -lt 2>/dev/null /dev/disk/by-id/usb* | rev | cut -f 3 -d ' ' | rev | head -1`
prepare_usb dev="$1"
echo $mount_path
counter=0
for user_info in `eval cat "$mount_path"/Openslx/config`; do
type=`eval echo $user_info | cut -f 1 -d '='`
counter=$(($counter+1))
if [[ $type == "SLX_USB_PASSWD" ]]
then
passwd=`eval echo $user_info | cut -f 2 -d '='`
user=` eval echo $user_info | cut -f 2 -d '=' | cut -f 1 -d ':'`
gshadow=`echo $user:!::`
echo "user"$user
check_user=`cat /etc/shadow | grep -w $user`
passwd=`eval echo $user_info | cut -f 2 -d '='`
if [[ ( ! -n $check_user) ]]; then
echo "não existe user"
fi
elif [[ $type == "SLX_USB_SHADOW" ]] prepare_usb "$dev" #returns $mountpath
then echo "$0: an openslx ready drive is mounted at: $mountpath"
shadow=`eval echo $user_info | cut -f 2 -d '='` unset IFS
users=$(cat "$mountpath/Openslx/config");
if [ -z "$users" ]; then
echo "$0: empty config file"
exit 3
fi
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
elif [[ $type == "SLX_USB_GROUP" ]] username=$( echo $passwdf | cut -d':' -f1 )
then uID=$( echo $passwdf | cut -d':' -f3 )
group=`eval echo $user_info | cut -f 2 -d '='` localID=$( echo $uID | grep -e "^2....$" -e "^1....$" )
fi groupname=$( echo $groupf | cut -d':' -f1 )
gID=$( echo $groupf | cut -d':' -f3 )
localGID=$( echo $gID | grep -e "^2....$" -e "^1....$" )
mod=$(( $counter % 3)) #group == username
if [[ $mod == 0 ]]; if [ "$username" = "$groupname" ]; then
then #id no range certo(local user)
#insert data in the files if [ -n "$localID" ] && [ -n "$localGID" ]; then
if [[ (! -n $check_user)&&(-n $passwd)&&(-n $shadow)&&(-n $group)&&(-n $gshadow) ]]; then #add to files;
echo "Insert $counter" #/opt/openslx/scripts/adduser.sh "$passwdf" "$groupf" "$shadowf"
echo $passwd >> /etc/passwd /home/luiz/repos/users-openslx/hdd/adduser.sh "$passwdf" "$groupf" "$shadowf"
echo $shadow >> /etc/shadow
echo $group >> /etc/group
#echo $gshadow >> /etc/gshadow
if [ ! -d "/home/"$user ]; then
mkdir /home/$user
chown $user:$user /home/$user
fi fi
fi fi
passwd=""
shadow=""
group=""
gshadow=""
user=""
fi
done done
echo $shadow
echo $group
#user=` eval cat "$mount_path"/Openslx/config | head -n 1 | cut -f 2 -d '=' | cut -f 1 -d ':'`
#gshadow=`echo $user:!::`
#check_user=`cat /etc/shadow | grep -w $user`
#echo $shadow
#echo $group
#echo $check_user
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment