Skip to content

Commit

Permalink
fix(ssh-adduser): use 'wget' when 'curl' isn't available
Browse files Browse the repository at this point in the history
  • Loading branch information
coolaj86 committed Nov 10, 2024
1 parent 257adec commit 93be13f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ssh-adduser/ssh-adduser
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ set -e
set -u

main() {
cmd_http_get="curl -fsS -#"
if ! command -v curl > /dev/null; then
cmd_http_get="wget -O -"
fi

# Add User 'app'
# Picking 'app' by common convention (what Docker & Vagrant use).
Expand All @@ -17,7 +21,7 @@ main() {

if [ -n "${my_key_url}" ]; then
my_keys="$(
curl -fsS "${my_key_url}"
$cmd_http_get "${my_key_url}"
)"
elif [ -e ~/.ssh/authorized_keys ] && grep -q -v '#' ~/.ssh/authorized_keys; then
my_keys="$(
Expand All @@ -29,7 +33,7 @@ main() {
echo " You must add a key to ~/.ssh/authorized_keys before adding a new ssh user."
echo ""
echo "To fix:"
echo " Run 'curl https://webinstall.dev/ssh-pubkey | sh' on your local system, "
echo " Run '$cmd_http_get https://webi.sh/ssh-pubkey | sh' on your local system, "
echo " then add that key to ~/.ssh/authorized_keys on this (the remote) system. "
echo ""
exit 1
Expand Down Expand Up @@ -58,8 +62,7 @@ main() {
# sudo -i -u "$my_new_user" sh -c \
# "ssh-keygen -b 2048 -t rsa -f '/home/$my_new_user/.ssh/id_rsa' -q -N ''"
WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"}
sudo -i -u "$my_new_user" sh -c "curl -fsSL '$WEBI_HOST/ssh-pubkey' | sh > /dev/null" ||
sudo -i -u "$my_new_user" sh -c "wget -q -O - '$WEBI_HOST/ssh-pubkey' | sh > /dev/null"
sudo -i -u "$my_new_user" sh -c "$cmd_http_get '$WEBI_HOST/ssh-pubkey' | sh > /dev/null"

if test -z "${SSH_ADDUSER_AUTO:-}"; then
echo ""
Expand Down

0 comments on commit 93be13f

Please sign in to comment.