add group option
- add group option - fix params check
This commit is contained in:
parent
36452c9e2d
commit
1e8416229d
@ -8,3 +8,6 @@ Usage: csc [OPTION]... [COMMAND]
|
||||
-v enable verbose mode
|
||||
-c specify config dir, default is /$HOME/.config/csc
|
||||
-u specify user, default is $USER
|
||||
-g specify hosts group
|
||||
|
||||
Host group file must exists under config dir, one host per line
|
||||
|
35
csc
35
csc
@ -8,6 +8,7 @@
|
||||
# -v enable verbose mode
|
||||
# -c specify config dir, default is $HOME/.config/csc
|
||||
# -u specify user, default is $USER
|
||||
# -g specify hosts group
|
||||
|
||||
# defaults
|
||||
verbose=false
|
||||
@ -15,7 +16,7 @@ confdir="$HOME/.config/csc"
|
||||
user=$USER
|
||||
|
||||
# get options
|
||||
while getopts ":vc:u:" opt; do
|
||||
while getopts ":vc:u:g:" opt; do
|
||||
case $opt in
|
||||
v)
|
||||
verbose=true
|
||||
@ -26,6 +27,9 @@ while getopts ":vc:u:" opt; do
|
||||
u)
|
||||
user=$OPTARG
|
||||
;;
|
||||
g)
|
||||
group=$OPTARG
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
exit 1
|
||||
@ -40,14 +44,6 @@ done
|
||||
# clean $@ of options
|
||||
shift $((OPTIND-1))
|
||||
|
||||
hosts="$confdir/hosts"
|
||||
|
||||
if [ ! -e "$hosts" ]
|
||||
then
|
||||
echo "Error: hosts file do not exists !"
|
||||
exit
|
||||
fi
|
||||
|
||||
cmd=$@
|
||||
|
||||
if [ -z "$cmd" ]
|
||||
@ -57,9 +53,30 @@ then
|
||||
echo " -v enable verbose mode"
|
||||
echo " -c specify config dir, default is $HOME/.config/csc"
|
||||
echo " -u specify user, default is $USER"
|
||||
echo " -g specify group"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$user" ]
|
||||
then
|
||||
echo "Error: user is not defined !"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z "$group" ]
|
||||
then
|
||||
echo "Error: group is not defined !"
|
||||
exit
|
||||
fi
|
||||
|
||||
hosts="$confdir/$group"
|
||||
|
||||
if [ -z "$hosts" ]
|
||||
then
|
||||
echo "Error: hosts file $confdir/$group do not exists !"
|
||||
exit
|
||||
fi
|
||||
|
||||
# see http://askubuntu.com/questions/506158/unable-to-initialize-frontend-dialog-when-using-ssh
|
||||
#FRONTEND="DEBIAN_FRONTEND=noninteractive" # then you should use clush instead :)
|
||||
FRONTEND="TERM=$TERM DEBIAN_FRONTEND=dialog"
|
||||
|
Loading…
Reference in New Issue
Block a user