Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
users-openslx
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cdn
users-openslx
Commits
4491dced
Commit
4491dced
authored
9 years ago
by
Luiz Reis
Browse files
Options
Downloads
Patches
Plain Diff
Update insert_data
Signed-off-by:
Luiz Reis
<
luizreis@outlook.com
>
parent
e4ea32e2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
usb_drive/insert_data.sh
+54
-83
54 additions, 83 deletions
usb_drive/insert_data.sh
with
54 additions
and
83 deletions
usb_drive/insert_data.sh
+
54
−
83
View file @
4491dced
#!/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
dev
path
=
"/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
$dev
path
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
$dev
path
mounted successfully"
echo
"
$0
: Device
/dev/
$dev
mounted successfully"
mountpath
=
"/media/openslx/
"
$2
mountpath
=
"/media/openslx/
$dev
"
else
else
echo
$0
"
: Device
$dev
path
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
"
:
$dev
path
is an openslx ready drive"
echo
"
$0
:
/dev/
$dev
is an openslx ready drive"
else
else
echo
$0
"
:
$dev
path
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
$dev
path
"
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment