From 207733ab8d3863b469c0c173714953eedda60bb8 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 1 Jul 2022 12:56:55 +0200 Subject: setup-alpine: add USERSSHKEY option to answerfile Add a variable for user's ssh key, USERSSHKEY. We need this because the key is space separated and we want avoid parse USEROPTS with eval to handle quotes. fixes https://gitlab.alpinelinux.org/alpine/alpine-conf/-/issues/10520 --- setup-alpine.in | 5 +++-- tests/setup_alpine_test | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/setup-alpine.in b/setup-alpine.in index d393c5d..ad3c430 100644 --- a/setup-alpine.in +++ b/setup-alpine.in @@ -113,7 +113,8 @@ if [ -n "$CREATEANSWERFILE" ]; then APKREPOSOPTS="-1" # Create admin user - USEROPTS="-a -u -g audio,video,netdev -k https://example.com/juser.keys juser" + USEROPTS="-a -u -g audio,video,netdev juser" + USERSSHKEY="https://example.com/juser.keys" # Install Openssh SSHDOPTS=openssh @@ -231,7 +232,7 @@ if [ "$quick" = 1 ]; then exit 0 fi -setup-user ${USEROPTS:--a -g 'audio video netdev'} +setup-user ${USERSSHKEY+-k "$USERSSHKEY"} ${USEROPTS:--a -g 'audio video netdev'} setup-sshd ${SSHDOPTS} if is_xen_dom0; then diff --git a/tests/setup_alpine_test b/tests/setup_alpine_test index 22555ee..2c8b623 100755 --- a/tests/setup_alpine_test +++ b/tests/setup_alpine_test @@ -28,6 +28,9 @@ setup_alpine_create_answerfile_body() { mkdir -p usr/share/zoneinfo/ touch usr/share/zoneinfo/UTC + sed -i -e 's/^USERSSHKEY=.*/USERSSHKEY="ssh-rsa blahbla user@example.com"/' \ + answers + atf_check -s exit:0 \ -o match:"Starting hostname" \ -o match:"Starting mdev" \ @@ -35,5 +38,7 @@ setup_alpine_create_answerfile_body() { -o match:"adduser" \ -o match:"apk add" \ setup-alpine -f answers + grep "ssh-rsa blahbla user@example.com" home/juser/.ssh/authorized_keys \ + || atf_fail "ssh key not set for juser" } -- cgit v1.2.3