slish rev 6

Bunch of improvments and new cmds
author Christophe Lincoln <pankso@slitaz.org>
date Thu Jan 23 22:51:29 2014 +0100 (2014-01-23)
parents e147172174de
children 65ad158a371b
files slish
line diff
     1.1 --- a/slish	Wed Jan 22 21:21:29 2014 +0000
     1.2 +++ b/slish	Thu Jan 23 22:51:29 2014 +0100
     1.3 @@ -18,7 +18,7 @@
     1.4  queue="${cache}/signup-queue"
     1.5  domain="slish.in"
     1.6  
     1.7 -# Basic chroot packages
     1.8 +# Default chroot packages
     1.9  chrootpkgs="glibc-base slitaz-base-files ncursesw nano ytree busybox-slish
    1.10  tcc rhapsody"
    1.11  
    1.12 @@ -38,10 +38,13 @@
    1.13    clean-chroot  Clean the chroot but skip home and root
    1.14    adduser       Add a user to the server with \$HOME in chroot
    1.15    deluser       Delete a SliSH user from server and chroot
    1.16 +  list-queue    List users in the signup queue
    1.17 +  chroot        Chroot to SliSH users default chroot
    1.18    
    1.19  $(boldify "Options:")
    1.20    --root=       Set the path to the SliSH or user chroot
    1.21    --clean       Clean the chroot before gen-chroot
    1.22 +  --queued      Add all users from the signup queue
    1.23  
    1.24  EOT
    1.25  }
    1.26 @@ -68,6 +71,19 @@
    1.27  	echo "All done!"
    1.28  }
    1.29  
    1.30 +# Show user configs
    1.31 +show_queued_user() {
    1.32 +	. ${queue}/${user}/account.conf
    1.33 +	newline
    1.34 +	separator
    1.35 +	cat << EOT
    1.36 +User : $user
    1.37 +Name : $name
    1.38 +Mail : $mail
    1.39 +EOT
    1.40 +	separator
    1.41 +}
    1.42 +
    1.43  # Gen a user config file
    1.44  user_config() {
    1.45  	echo -n "Creating SliSH account configuration..."
    1.46 @@ -80,7 +96,7 @@
    1.47  MAIL="$mail"
    1.48  
    1.49  ULIMIT="-d 4096 -m 4096 -l 32 -p 5 -v 16384"
    1.50 -QUOTA=""
    1.51 +QUOTA="50"
    1.52  
    1.53  EOT
    1.54  	chmod 0600 ${people}/${user}/account.conf
    1.55 @@ -123,8 +139,10 @@
    1.56  	if grep -q ^${user}: /etc/passwd; then
    1.57  		newline
    1.58  		echo -n "User already exists: "; colorize 31 "$user"
    1.59 -		newline && exit 0
    1.60 +		rm -rf ${queue}/${user}
    1.61 +		newline && exit 1
    1.62  	fi
    1.63 +	
    1.64  	newline
    1.65  	echo -n "$(boldify 'Creating user:') "; colorize 32 "$user"
    1.66  	separator
    1.67 @@ -153,6 +171,7 @@
    1.68  	chmod 0700 ${home}/.ssh
    1.69  	status
    1.70  	user_config
    1.71 +	
    1.72  	# Send mail to notify user account creation
    1.73  	if [ -x /usr/sbin/sendmail ]; then
    1.74  		echo -n "Sending mail to: $mail"
    1.75 @@ -162,6 +181,17 @@
    1.76  	separator && newline
    1.77  }
    1.78  
    1.79 +# Add all users from the signup queue
    1.80 +add_queued_user() {
    1.81 +	for user in $(ls ${queue})
    1.82 +	do
    1.83 +		. ${queue}/${user}/account.conf
    1.84 +		pass=$(cat ${queue}/${user}/passwd | base64 -d)
    1.85 +		add_user
    1.86 +		rm -rf ${queue}/${user}
    1.87 +	done
    1.88 +}
    1.89 +
    1.90  # Delete a SliSH user
    1.91  del_user() {
    1.92  	home="$root/home/$user"
    1.93 @@ -234,16 +264,33 @@
    1.94  #
    1.95  
    1.96  case "$1" in
    1.97 -	-i|info)
    1.98 +	info)
    1.99  		check_root
   1.100 -		echo -n "Chroot size : " && du -sh ${root} 
   1.101 -		echo -n "Users count : " && ls -1 ${people} | wc -l ;;
   1.102 +		newline
   1.103 +		boldify "Info"
   1.104 +		separator
   1.105 +		echo -n "Chroot size    : " && du -sh ${root} 
   1.106 +		echo -n "Users accounts : " && ls -1 ${people} | wc -l
   1.107 +		echo -n "Signup queue   : " && ls -1 ${queue} | wc -l
   1.108 +		separator && newline ;;
   1.109 +	last)
   1.110 +		check_root
   1.111 +		newline
   1.112 +		boldify "Last users"
   1.113 +		separator
   1.114 +		tac ${activity} | head -n 20
   1.115 +		separator && newline ;;
   1.116  	setup)
   1.117  		check_root
   1.118  		setup ;;
   1.119  	adduser)
   1.120 +		# We can adduser from cmdline or from the signup queue
   1.121  		check_root
   1.122 -		add_user ;;
   1.123 +		if [ "$from-queu" ]; then
   1.124 +			add_queued_user
   1.125 +		else
   1.126 +			add_user
   1.127 +		fi ;;
   1.128  	deluser)
   1.129  		check_root
   1.130  		del_user ;;
   1.131 @@ -257,22 +304,20 @@
   1.132  		echo "Chrooting to: $root"
   1.133  		chroot ${root} /bin/sh
   1.134  		echo "Exiting from: $root" ;;
   1.135 -	-cq|check-queue)
   1.136 -		# Check online registration queue
   1.137 -		for user in $(ls ${queue})
   1.138 +	-lq|list-queue)
   1.139 +		# Check online signup queue but do nothing
   1.140 +		for user in $(ls ${queued})
   1.141  		do
   1.142 -			. ${queue}/${user}/account.conf
   1.143 -			pass=$(cat ${queue}/${user}/passwd | base64 -d)
   1.144 -			add_user
   1.145 -			rm -rf ${queue}/${user}
   1.146 -		done ;;
   1.147 +			show_queued_user
   1.148 +		done 
   1.149 +		echo "" ;;
   1.150  	*)
   1.151 -		# /usr/bin/slish is be executed on login to chroot the user
   1.152 +		# /usr/bin/slish is executed on login to chroot the user
   1.153  		if [ -d "$root/home/$USER" ]; then
   1.154  			. ${people}/"$USER"/account.conf
   1.155  			log "Chrooting user: $USER"
   1.156  			ulimit $(echo "$ULIMIT")
   1.157 -			exec chroot $root /bin/slish.sh "$@"
   1.158 +			exec chroot ${root} /bin/slish.sh "$@"
   1.159  		else
   1.160  			usage
   1.161  		fi ;;