Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssh-adduser): use 'wget' when 'curl' isn't available #913

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading