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
Harbor Registry
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
e96cad5c
Commit
e96cad5c
authored
9 years ago
by
Thiago Abdo
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of gitlab.c3sl.ufpr.br:cdn/users-openslx
parents
8ca631c2
4491dced
No related branches found
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 @
e96cad5c
#!/bin/bash
DIR_USB
=
/media/usb_drive/
DIR_OPENSLX
=
/Openslx/
user_name
=
`
users
|
cut
-f
1
-d
' '
`
#!/bin/ash
# prepares openslx partition to be used
# mounts partition if not mounted
# blocks program execution if it is not a openslx partition
# param $1 is the devpath to be mounted
# param $2 is the uuid of the partition
# param $1 is the dev to be mounted
# return is done via the mountpath global variable, which is also used here
function
prepare_usb
{
prepare_usb
()
{
# get the usb_drive's path
local
dev
path
=
"/dev/"
$1
local
dev
=
$1
mountpath
=
""
if
[
!
0
-eq
$(
mount |
grep
-q
$devpath
)
]
;
then
echo
$0
": Device
$devpath
is already mounted"
mountpath
=
$(
mount |
grep
-w
$devpath
|
cut
-d
' '
-f3
)
if
$(
mount |
grep
-q
"/dev/
$dev
"
)
;
then
echo
"
$0
: Device /dev/
$dev
is already mounted"
mountpath
=
$(
df
|
grep
-w
$dev
|
cut
-d
'%'
-f2-
|
cut
-d
' '
-f2-
)
else
echo
$0
"
: Device
$dev
path
is not mounted"
mkdir
-p
/media/openslx/
$
2
if
$(
mount
$devpath
/media/openslx/
$
2
)
;
then
echo
$0
"
: Device
$dev
path
mounted successfully"
mountpath
=
"/media/openslx/
"
$2
echo
"
$0
: Device
/dev/
$dev
is not mounted"
mkdir
-p
/media/openslx/
$
dev
if
$(
mount
"/dev/
$dev
"
/media/openslx/
$
dev
)
;
then
echo
"
$0
: Device
/dev/
$dev
mounted successfully"
mountpath
=
"/media/openslx/
$dev
"
else
echo
$0
"
: Device
$dev
path
could not be mounted"
echo
"
$0
: Device
/dev/
$dev
could not be mounted"
exit
1
fi
fi
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
echo
$0
"
:
$dev
path
is not ready to be used as an openslx drive"
if
[
$mountpath
=
"/media/openslx/
$
2
"
]
;
then
echo
$0
"
: umounting
$dev
path
"
umount
$devpath
echo
"
$0
:
/dev/
$dev
is not ready to be used as an openslx drive"
if
[
"
$mountpath
"
=
"/media/openslx/
$
dev
"
]
;
then
echo
"
$0
: umounting
/dev/
$dev
"
umount
-f
-l
"/dev/
$dev
"
fi
exit
2
fi
}
sleep
3
#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
`
sleep
3
# let the system mount the drive first
prepare_usb
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
dev
=
"
$1
"
elif
[[
$type
==
"SLX_USB_SHADOW"
]]
then
prepare_usb
"
$dev
"
#returns $mountpath
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"
]]
then
group
=
`
eval echo
$user_info
|
cut
-f
2
-d
'='
`
username
=
$(
echo
$passwdf
|
cut
-d
':'
-f1
)
uID
=
$(
echo
$passwdf
|
cut
-d
':'
-f3
)
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
))
if
[[
$mod
==
0
]]
;
then
#insert data in the files
if
[[
(!
-n
$check_user
)&&(
-n
$passwd
)&&(
-n
$shadow
)&&(
-n
$group
)&&(
-n
$gshadow
)
]]
;
then
echo
"Insert
$counter
"
echo
$passwd
>>
/etc/passwd
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
#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"
/home/luiz/repos/users-openslx/hdd/adduser.sh
"
$passwdf
"
"
$groupf
"
"
$shadowf
"
fi
fi
passwd
=
""
shadow
=
""
group
=
""
gshadow
=
""
user
=
""
fi
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