22
33show_help () {
44cat <<  EOF 
5- Usage: ${0##*/ }  [-hv] [-a ARN] [-i GROUP,GROUP,...] [-l GROUP,GROUP,...] [-s GROUP] 
5+ Usage: ${0##*/ }  [-hv] [-a ARN] [-i GROUP,GROUP,...] [-l GROUP,GROUP,...] [-s GROUP] [-p PROGRAM] [-u "ARGUMENTS"]  
66Install import_users.sh and authorized_key_commands. 
77
8-     -h              display this help and exit 
9-     -v              verbose mode. 
10- 
11-     -a arn          Assume a role before contacting AWS IAM to get users and keys. 
12-                     This can be used if you define your users in one AWS account, while the EC2 
13-                     instance you use this script runs in another. 
14-     -i group,group  Which IAM groups have access to this instance 
15-                     Comma seperated list of IAM groups. Leave empty for all available IAM users 
16-     -l group,group  Give the users these local UNIX groups 
17-                     Comma seperated list 
18-     -s group        Specify an IAM group for users who should be given sudo privileges, or leave 
19-                     empty to not change sudo access, or give it the value '##ALL##' to have all 
20-                     users be given sudo rights. 
8+     -h                 display this help and exit 
9+     -v                 verbose mode. 
10+ 
11+     -a arn             Assume a role before contacting AWS IAM to get users and keys. 
12+                        This can be used if you define your users in one AWS account, while the EC2 
13+                        instance you use this script runs in another. 
14+     -i group,group     Which IAM groups have access to this instance 
15+                        Comma seperated list of IAM groups. Leave empty for all available IAM users 
16+     -l group,group     Give the users these local UNIX groups 
17+                        Comma seperated list 
18+     -s group           Specify an IAM group for users who should be given sudo privileges, or leave 
19+                        empty to not change sudo access, or give it the value '##ALL##' to have all 
20+                        users be given sudo rights. 
21+     -p program         Specify your useradd program to use. 
22+                        Defaults to '/usr/sbin/useradd' 
23+     -u "useradd args"  Specify arguments to use with useradd. 
24+                        Defaults to '--create-home --shell /bin/bash' 
2125
2226
2327EOF 
@@ -27,6 +31,8 @@ IAM_GROUPS=""
2731SUDO_GROUP=" " 
2832LOCAL_GROUPS=" " 
2933ASSUME_ROLE=" " 
34+ USERADD_PROGRAM=" " 
35+ USERADD_ARGS=" " 
3036
3137while  getopts  :hva:i:l:s: opt
3238do 
5056        a)
5157            ASSUME_ROLE=" $OPTARG " 
5258            ;;
59+         p)
60+             USERADD_PROGRAM=" $OPTARG " 
61+             ;;
62+         u)
63+             USERADD_ARGS=" $OPTARG " 
64+             ;;
5365        \? )
5466            echo  " Invalid option: -$OPTARG " >&2 
5567            show_help
@@ -107,6 +119,16 @@ then
107119    echo  " ASSUMEROLE=\" ${ASSUME_ROLE} \" " >>  /etc/aws-ec2-ssh.conf
108120fi 
109121
122+ if  [ " ${USERADD_PROGRAM} " !=  " " 
123+ then 
124+     echo  " USERADD_PROGRAM=\" ${USERADD_PROGRAM} \" " >>  /etc/aws-ec2-ssh.conf
125+ fi 
126+ 
127+ if  [ " ${USERADD_ARGS} " !=  " " 
128+ then 
129+     echo  " USERADD_ARGS=\" ${USERADD_ARGS} \" " >>  /etc/aws-ec2-ssh.conf
130+ fi 
131+ 
110132sed -i ' s:#AuthorizedKeysCommand none:AuthorizedKeysCommand /opt/authorized_keys_command.sh:g' 
111133sed -i ' s:#AuthorizedKeysCommandUser nobody:AuthorizedKeysCommandUser nobody:g' 
112134
0 commit comments