jamesread 2 лет назад
Родитель
Сommit
c18b91f684

+ 2 - 0
.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 }}

+ 1 - 0
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
 

+ 1 - 0
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
 

+ 1 - 0
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
 

+ 16 - 0
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")
 }
 

+ 35 - 0
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 <<EOF > /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