You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
1.8 KiB
82 lines
1.8 KiB
#!/bin/bash
|
|
# info: list system users
|
|
# options: [FORMAT]
|
|
#
|
|
# example: v-list-sys-users
|
|
#
|
|
# This function for obtaining the list of system users without
|
|
# detailed information.
|
|
|
|
#----------------------------------------------------------#
|
|
# Variables & Functions #
|
|
#----------------------------------------------------------#
|
|
|
|
# Argument definition
|
|
format=${1-shell}
|
|
|
|
# Includes
|
|
# shellcheck source=/etc/hestiacp/hestia.conf
|
|
source /etc/hestiacp/hestia.conf
|
|
# shellcheck source=/usr/local/hestia/func/main.sh
|
|
source $HESTIA/func/main.sh
|
|
# load config file
|
|
source_conf "$HESTIA/conf/hestia.conf"
|
|
|
|
# JSON list function
|
|
json_list() {
|
|
objects=$(grep @ /etc/passwd | wc -l)
|
|
i=1
|
|
echo '['
|
|
while read user; do
|
|
if [ "$i" -lt "$objects" ]; then
|
|
echo -e "\t\"$user\","
|
|
else
|
|
echo -e "\t\"$user\""
|
|
fi
|
|
((++i))
|
|
done < <(grep @ /etc/passwd | cut -f 1 -d :)
|
|
echo "]"
|
|
}
|
|
|
|
# SHELL list function
|
|
shell_list() {
|
|
echo "USER"
|
|
echo "----"
|
|
while read user; do
|
|
echo "$user"
|
|
done < <(grep @ /etc/passwd | cut -f 1 -d :)
|
|
}
|
|
|
|
# PLAIN list function
|
|
plain_list() {
|
|
while read user; do
|
|
echo "$user"
|
|
done < <(grep @ /etc/passwd | cut -f 1 -d :)
|
|
}
|
|
|
|
# CSV list function
|
|
csv_list() {
|
|
echo "USER"
|
|
while read user; do
|
|
echo "$user"
|
|
done < <(grep @ /etc/passwd | cut -f 1 -d :)
|
|
}
|
|
|
|
#----------------------------------------------------------#
|
|
# Action #
|
|
#----------------------------------------------------------#
|
|
|
|
# Listing data
|
|
case $format in
|
|
json) json_list ;;
|
|
plain) plain_list ;;
|
|
csv) csv_list ;;
|
|
shell) shell_list ;;
|
|
esac
|
|
|
|
#----------------------------------------------------------#
|
|
# Hestia #
|
|
#----------------------------------------------------------#
|
|
|
|
exit
|