1
0
mirror of https://github.com/myvesta/vesta.git synced 2025-03-12 04:35:23 -07:00
myvesta/bin/v-change-user-shell

64 lines
1.7 KiB
Plaintext
Raw Permalink Normal View History

2013-01-19 23:07:26 +02:00
#!/bin/bash
# info: change user shell
# options: USER SHELL
#
2015-11-06 17:38:58 +02:00
# The function changes system shell of a user. Shell gives ability to use ssh.
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2013-01-19 23:07:26 +02:00
user=$1
shell=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER SHELL'
is_format_valid 'user' 'shell'
2013-01-19 23:07:26 +02:00
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get shell full path
shell_path=$(grep -w "$shell" /etc/shells | head -n1)
2013-01-19 23:07:26 +02:00
# Changing passwd file
/usr/bin/chsh -s "$shell_path" "$user" >/dev/null 2>&1
2013-01-19 23:07:26 +02:00
shell=$(basename $shell_path)
2015-09-18 17:42:48 +03:00
# Adding jailed sftp env
if [ ! -z "$SFTPJAIL_KEY" ]; then
if [[ "$shell" =~ nologin ]] || [[ "$shell" =~ rssh ]]; then
$BIN/v-add-user-sftp-jail $user >/dev/null 2>&1
else
$BIN/v-delete-user-sftp-jail $user >/dev/null 2>&1
fi
2015-09-18 17:42:48 +03:00
fi
2013-01-19 23:07:26 +02:00
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Changing user shell
update_user_value "$user" '$SHELL' "$shell"
# Logging
log_history "changed $user shell to $shell" '' 'admin'
log_event "$OK" "$ARGUMENTS"
2013-01-19 23:07:26 +02:00
exit