diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2018-06-01 11:24:45 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2018-06-01 11:24:45 +0000 |
commit | 6c51576a20ed00b6ba7b3407f220862945b10c2f (patch) | |
tree | d5cf16a87de16ace92d14c6419bc6ec0fb99f20f /tcwg-base | |
parent | 52e9e1e3e6ead2bce0fc49ef824b0b00686f782f (diff) |
tcwg-build: Generalize new-user.sh to handle passwd entries as argument
.. in preparation to move it to tcwg-base/
Change-Id: I4263bb1b5cde191b85118b5aff4b1773b7ffc1ab
Diffstat (limited to 'tcwg-base')
-rw-r--r-- | tcwg-base/tcwg-build/Dockerfile.in | 5 | ||||
-rwxr-xr-x | tcwg-base/tcwg-build/new-user.sh | 38 |
2 files changed, 32 insertions, 11 deletions
diff --git a/tcwg-base/tcwg-build/Dockerfile.in b/tcwg-base/tcwg-build/Dockerfile.in index 39ef4f39..cbf4476b 100644 --- a/tcwg-base/tcwg-build/Dockerfile.in +++ b/tcwg-base/tcwg-build/Dockerfile.in @@ -2,8 +2,9 @@ FROM linaro/ci-#{ARCH}-tcwg-base-ubuntu:#{DISTRO} COPY new-user.sh /usr/local/bin/ -RUN new-user.sh --user tcwg-buildslave:11827 --group tcwg-infra:9000 \ - && new-user.sh --user tcwg-benchmark:12326 --group tcwg-infra \ +RUN new-user.sh --group tcwg-infra:9000 \ + && new-user.sh --passwd "tcwg-buildslave:x:11827:9000:TCWG Buildslave::/bin/bash" \ + && new-user.sh --passwd "tcwg-benchmark:x:12326:9000:TCWG Benchmark::/bin/bash" \ && mkdir -p /home/tcwg-buildslave/workspace COPY tcwg-buildslave /home/tcwg-buildslave diff --git a/tcwg-base/tcwg-build/new-user.sh b/tcwg-base/tcwg-build/new-user.sh index d1b18953..7bb022dc 100755 --- a/tcwg-base/tcwg-build/new-user.sh +++ b/tcwg-base/tcwg-build/new-user.sh @@ -7,6 +7,7 @@ usage () exit 1 } +passwd_ent="" group="" key="" user="" @@ -14,6 +15,7 @@ verbose=false while [ $# -gt 0 ]; do case "$1" in + --passwd) passwd_ent="$2" ;; --group) group="$2" ;; --key) key="$2" ;; --user) user="$2" ;; @@ -34,22 +36,40 @@ if [ x"$group" != x"" ]; then fi group_opt="-g $group" +elif [ x"$passwd_ent" != x"" ]; then + gid=$(echo $passwd_ent | cut -d: -f 4) + group_opt="-g $gid" else group_opt="" fi +if [ x"$user" = x"" ]; then + user=$(echo "$passwd_ent" | cut -s -d: -f 1,3) +fi + uid=$(echo "$user" | cut -s -d: -f 2) user=$(echo "$user" | cut -d: -f 1) -useradd -m $group_opt -G kvm ${uid:+-u $uid} $user +if [ x"$user" != x"" ]; then + if [ x"$passwd_ent" != x"" ]; then + comment=$(echo $passwd_ent | cut -d: -f 5) + shell=$(echo $passwd_ent | cut -d: -f 7) + fi -sudoers_file=/etc/sudoers.d/$(echo $user | tr "." "-") -echo "$user ALL = NOPASSWD: ALL" > $sudoers_file -chmod 0440 $sudoers_file + useradd -m $group_opt -G kvm \ + ${uid:+-u $uid} \ + ${comment:+-c "$comment"} \ + ${shell:+-s "$shell"} \ + $user -if [ x"$key" != x"" ] ; then - sudo -i -u $user mkdir -p /home/$user/.ssh - sudo -i -u $user chmod 0700 /home/$user/.ssh - cat "$key" | sudo -i -u $user tee /home/$user/.ssh/authorized_keys > /dev/null - sudo -i -u $user chmod 0600 /home/$user/.ssh/authorized_keys + sudoers_file=/etc/sudoers.d/$(echo $user | tr "." "-") + echo "$user ALL = NOPASSWD: ALL" > $sudoers_file + chmod 0440 $sudoers_file + + if [ x"$key" != x"" ] ; then + sudo -i -u $user mkdir -p /home/$user/.ssh + sudo -i -u $user chmod 0700 /home/$user/.ssh + cat "$key" | sudo -i -u $user tee /home/$user/.ssh/authorized_keys > /dev/null + sudo -i -u $user chmod 0600 /home/$user/.ssh/authorized_keys + fi fi |