0
0
Fork 0
mirror of https://github.com/atmoz/sftp.git synced 2025-03-16 15:23:25 -04:00

Simple help output

This commit is contained in:
Adrian Dvergsdal 2015-07-25 14:00:24 +02:00
parent 9ba2bfbe6d
commit 3c756a9b33

View file

@ -1,33 +1,32 @@
#!/bin/bash #!/bin/bash
if [ $1 == "--readme" ]; then function printHelp() {
cat /README.md
exit 0
fi
if [[ -z $1 || $1 =~ ^--help$|^-h$ ]]; then
echo "Syntax: user:pass[:e][:[uid][:gid]]..." echo "Syntax: user:pass[:e][:[uid][:gid]]..."
echo "Use --readme for information and examples." echo "Use --readme for information and examples."
exit 0 }
fi
for users in "$@"; do function printReadme() {
IFS=':' read -a data <<< "$users" cat /README.md
user="${data[0]}" }
pass="${data[1]}"
function createUser() {
IFS=':' read -a param <<< $@
user="${param[0]}"
pass="${param[1]}"
if [ -z "$user" -o -z "$pass" ]; then if [ -z "$user" -o -z "$pass" ]; then
echo "You must at least provide a username and a password." echo "You must at least provide a username and a password."
printHelp
exit 1 exit 1
fi fi
if [ "${data[2]}" == "e" ]; then if [ "${param[2]}" == "e" ]; then
chpasswdOptions="-e" chpasswdOptions="-e"
uid="${data[3]}" uid="${param[3]}"
gid="${data[4]}" gid="${param[4]}"
else else
uid="${data[2]}" uid="${param[2]}"
gid="${data[3]}" gid="${param[3]}"
fi fi
useraddOptions="--create-home --no-user-group" useraddOptions="--create-home --no-user-group"
@ -55,6 +54,20 @@ for users in "$@"; do
cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys cat /home/$user/.ssh/keys/* >> /home/$user/.ssh/authorized_keys
chown $user /home/$user/.ssh/authorized_keys chown $user /home/$user/.ssh/authorized_keys
chmod 600 /home/$user/.ssh/authorized_keys chmod 600 /home/$user/.ssh/authorized_keys
}
if [[ -z $1 || $1 =~ ^--help$|^-h$ ]]; then
printHelp
exit 0
fi
if [ "$1" == "--readme" ]; then
printReadme
exit 0
fi
for user in "$@"; do
createUser $user
done done
exec /usr/sbin/sshd -D exec /usr/sbin/sshd -D