diff options
author | Micah Anderson <micah@riseup.net> | 2014-12-18 12:22:01 -0500 |
---|---|---|
committer | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2015-01-22 13:54:58 -0500 |
commit | a829f13ca508e2b6d2e634a7aebd2a03cb6243d8 (patch) | |
tree | 0e1109c34c4134cc10da75adc3a8d5392f3d4476 /kvm-creator | |
parent | a9d58cdce28e684bbe481a5aee58af56b97bd48d (diff) | |
download | kvm-manager-a829f13ca508e2b6d2e634a7aebd2a03cb6243d8.tar.gz kvm-manager-a829f13ca508e2b6d2e634a7aebd2a03cb6243d8.tar.bz2 |
add CREATE_USER optional environment parameter to skip creating a user
if it is set to something other than 'yes'
Diffstat (limited to 'kvm-creator')
-rwxr-xr-x | kvm-creator | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/kvm-creator b/kvm-creator index 8d2afa7..0864ebe 100755 --- a/kvm-creator +++ b/kvm-creator @@ -15,6 +15,10 @@ SIZE="${3:-3G}" RAM="${4:-512}" DISK="/dev/mapper/${VG}-${NAME}" +if [ -z "$CREATE_USER" ]; then + CREATE_USER="yes" +fi + # for managing udev (we want to make sure that logical volumes get # created with ownership by the controlling user: UDEV_RULES_FILE="/etc/udev/rules.d/92-kvm_creator-%s.rules" @@ -56,9 +60,11 @@ validate() { [ -z "$NAME" ] && errors=$(printf "%s\n%s" "$errors" "Please pass the name of the virtual server to create") || : [ -z "$VG" ] && errors=$(printf "%s\n%s" "$errors" "Please pass the name of the volume group to use") || : vgs --noheadings --unbuffered -o name | tr -d ' ' | grep -q -F -x "$VG" || errors=$(printf "%s\n%s" "$errors" "Please pass the name of the volume group to use") || : - getent passwd "$NAME" > /dev/null && errors=$(printf "%s\n%s" "$errors" "The username '$NAME' already exists.") || : - getent group "$NAME" > /dev/null && errors=$(printf "%s\n%s" "The group '$NAME' already exists.") || : - [ -d /home/"$NAME" ] && errors=$(printf "%s\n%s" "The directory '/home/$NAME' already exists.") || : + if [ "$CREATE_USER" = "yes" ]; then + getent passwd "$NAME" > /dev/null && errors=$(printf "%s\n%s" "$errors" "The username '$NAME' already exists.") || : + getent group "$NAME" > /dev/null && errors=$(printf "%s\n%s" "The group '$NAME' already exists.") || : + [ -d /home/"$NAME" ] && errors=$(printf "%s\n%s" "The directory '/home/$NAME' already exists.") || : + fi [ -d /etc/sv/kvm/"$NAME" ] && errors=$(printf "%s\n%s" "The directory '/etc/sv/kvm/$NAME' already exists.") || : [ -e $DISK ] && errors=$(printf "%s\n%s" "The logical volume $NAME already exists.") || : [ -e "$(udevrulename "$NAME")" ] && errors=$(printf "%s\n%s" "The udev rules file '$(udevrulename "$NAME")' already exists.") || : @@ -92,7 +98,9 @@ create() { set -e validate - adduser "$NAME" --disabled-password --gecos "$NAME KVM user,,," + if [ "$CREATE_USER" = "yes" ]; then + adduser "$NAME" --disabled-password --gecos "$NAME KVM user,,," + fi USERHOMEDIR=$(getent passwd "$NAME" | cut -f6 -d:) chpst -u "$NAME:$NAME" mkdir -p "$USERHOMEDIR/"{.ssh,vms,"vms/$NAME"} if [ -f /root/.ssh/authorized_keys ]; then |