diff --git a/.goreleaser.yml b/.goreleaser.yml index aaa6c31..dd55db7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -98,6 +98,7 @@ dockers: - webui - var/entities/ - config.yaml + - var/helper-actions/olivetin-setup-easy-ssh - image_templates: - "docker.io/jamesread/olivetin:{{ .Tag }}-arm64" @@ -114,6 +115,7 @@ dockers: - webui - var/entities/ - config.yaml + - var/helper-actions/olivetin-setup-easy-ssh docker_manifests: - name_template: docker.io/jamesread/olivetin:{{ .Version }} diff --git a/Dockerfile b/Dockerfile index 2c6f1a6..6fb94af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,6 +24,7 @@ VOLUME /config COPY OliveTin /usr/bin/OliveTin COPY webui /var/www/olivetin/ +COPY var/helper-actions/olivetin-setup-easy-ssh /usr/bin/olivetin-setup-easy-ssh USER olivetin diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 5970537..74fd4fd 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -24,6 +24,7 @@ VOLUME /config COPY OliveTin /usr/bin/OliveTin COPY webui /var/www/olivetin/ +COPY var/helper-actions/olivetin-setup-easy-ssh /usr/bin/olivetin-setup-easy-ssh USER olivetin diff --git a/Dockerfile.armv7 b/Dockerfile.armv7 index 537e67f..cbdc443 100644 --- a/Dockerfile.armv7 +++ b/Dockerfile.armv7 @@ -20,6 +20,7 @@ VOLUME /config COPY OliveTin /usr/bin/OliveTin COPY webui /var/www/olivetin/ +COPY var/helper-actions/olivetin-setup-easy-ssh /usr/bin/olivetin-setup-easy-ssh USER olivetin diff --git a/internal/installationinfo/runtimeinfo.go b/internal/installationinfo/runtimeinfo.go index ea96473..02e620e 100644 --- a/internal/installationinfo/runtimeinfo.go +++ b/internal/installationinfo/runtimeinfo.go @@ -34,11 +34,27 @@ var Runtime = &runtimeInfo{ SshFoundConfig: searchForSshConfig(), } +func fileExists(path string) bool { + if _, err := os.Stat(path); err == nil { + return true + } + + return false +} + func searchForSshKey() string { + if fileExists("/config/ssh/id_rsa") { + return "/config/ssh/id_rsa" + } + return searchForHomeFile(".ssh/id_rsa") } func searchForSshConfig() string { + if fileExists("/config/ssh/config") { + return "/config/ssh/config" + } + return searchForHomeFile(".ssh/config") } diff --git a/var/helper-actions/olivetin-setup-easy-ssh b/var/helper-actions/olivetin-setup-easy-ssh new file mode 100755 index 0000000..9fdbdca --- /dev/null +++ b/var/helper-actions/olivetin-setup-easy-ssh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +mkdir -p /config/ssh/ + +SSH_KEY=/config/ssh/id_rsa + +echo "Documentation for this script: https://docs.olivetin.app/setup-ssh" +echo "" + +if test -f "$SSH_KEY"; then + echo "Using existing SSH key at $SSH_KEY, not generating a new one" +else + ssh-keygen -f $SSH_KEY -N '' + echo "Your new SSH key has been generated and saved to $SSH_KEY" +fi + +echo "To use this SSH key with OliveTin, format your action line like this:" +echo "" +echo "actions:" +echo " - name: My SSH Action" +echo " shell: ssh -F /config/ssh/config user@host \"echo 'Hello, world!'\"" +echo "" +echo "Note: This config has ssh key checking turned off for convenience." +echo "If validating SSH keys is important to you, you should not use this config." +echo "" + +cat < /config/ssh/config +Host * + StrictHostKeyChecking no + UserKnownHostsFile=/dev/null + IdentityFile /config/ssh/id_rsa +EOF + +echo "Copy this line into your ~/.ssh/authorized_keys file to allow OliveTin to connect to your server:" +cat /config/ssh/id_rsa.pub