Bläddra i källkod

feature: Helper scripts for ssh, themes, etc (#349)

* feature: Helper scripts for ssh, themes, etc

* cicd: Update goreleaser to support v2 .goreleaser.yml files
James Read 2 år sedan
förälder
incheckning
482ef0e5e8

+ 1 - 1
.github/workflows/build-snapshot.yml

@@ -52,7 +52,7 @@ jobs:
         run: cd integration-tests && make -w
 
       - name: goreleaser
-        uses: goreleaser/goreleaser-action@v5
+        uses: goreleaser/goreleaser-action@v6
         with:
           distribution: goreleaser
           version: latest

+ 1 - 1
.github/workflows/build-tag.yml

@@ -54,7 +54,7 @@ jobs:
         run: make -w webui-dist
 
       - name: goreleaser
-        uses: goreleaser/goreleaser-action@v5
+        uses: goreleaser/goreleaser-action@v6
         with:
           distribution: goreleaser
           version: latest

+ 1 - 0
.gitignore

@@ -12,3 +12,4 @@ tmp/
 webui/
 webui.dev/node_modules
 webui.dev/.parcel-cache
+custom-webui

+ 3 - 2
.goreleaser.yml

@@ -1,4 +1,5 @@
 project_name: OliveTin
+version: 2
 before:
   hooks:
     - go mod download
@@ -98,7 +99,7 @@ dockers:
       - webui
       - var/entities/
       - config.yaml
-      - var/helper-actions/olivetin-setup-easy-ssh
+      - var/helper-actions/
 
   - image_templates:
       - "docker.io/jamesread/olivetin:{{ .Tag }}-arm64"
@@ -115,7 +116,7 @@ dockers:
       - webui
       - var/entities/
       - config.yaml
-      - var/helper-actions/olivetin-setup-easy-ssh
+      - var/helper-actions/
 
 docker_manifests:
   - name_template: docker.io/jamesread/olivetin:{{ .Version }}

+ 2 - 1
Dockerfile

@@ -11,6 +11,7 @@ RUN mkdir -p /config /config/entities/ /var/www/olivetin \
 		shadow-utils \
 		apprise \
 		jq \
+		git \
 		docker \
 	&& microdnf clean all
 
@@ -24,7 +25,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
+COPY var/helper-actions/* /usr/bin/
 
 USER olivetin
 

+ 2 - 1
Dockerfile.arm64

@@ -11,6 +11,7 @@ RUN mkdir -p /config /config/entities/ /var/www/olivetin \
 		shadow-utils \
 		apprise \
 		jq \
+		git \
 		docker \
 	&& microdnf clean all
 
@@ -24,7 +25,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
+COPY var/helper-actions/* /usr/bin/
 
 USER olivetin
 

+ 1 - 1
Dockerfile.armv7

@@ -20,7 +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
+COPY var/helper-actions/* /usr/bin/
 
 USER olivetin
 

+ 30 - 3
config.yaml

@@ -5,7 +5,6 @@
 # Listen on all addresses available, port 1337
 listenAddressSingleHTTPFrontend: 0.0.0.0:1337
 
-
 # Choose from INFO (default), WARN and DEBUG
 logLevel: "INFO"
 
@@ -111,17 +110,44 @@ actions:
       - type: confirmation
         title: Are you sure?!
 
+  # This is an action that runs a script included with OliveTin, that will
+  # download themes. You will still need to set theme "themeName" in your config.
+  #
+  # Docs: https://docs.olivetin.app/themes.html
+  - title: Get OliveTin Theme
+    shell: olivetin-get-theme {{ themeGitRepo }} {{ themeFolderName }}
+    icon: theme
+    arguments:
+      - name: themeGitRepo
+        title: Theme's Git Repository
+        description: Find new themes at https://olivetin.app/themes
+        type: url
+
+      - name: themeFolderName
+        title: Theme's Folder Name
+        type: ascii_identifier
 
   # Sometimes you want to run actions on other servers - don't overcomplicate
-  # it, just use SSH!
+  # it, just use SSH! OliveTin includes a helper to make this easier, which is
+  # entirely optional. You can also setup SSH manually.
   #
+  # Docs: https://docs.olivetin.app/action-ssh-easy.html
   # Docs: https://docs.olivetin.app/action-ssh.html
+  - title: "Setup easy SSH"
+    icon: ssh
+    shell: olivetin-setup-easy-ssh
+    popupOnStart: execution-dialog
+
+  # Here's how to use SSH with the "easy" config, to restart a service on
+  # another server.
+  #
+  # Docs: https://docs.olivetin.app/action-ssh-easy.html
   # Docs: https://docs.olivetin.app/action-service.html
   - title: Restart httpd on server1
     id: restart_httpd
     icon: restart
     timeout: 1
-    shell: ssh root@server1 'service httpd restart'
+    shell: ssh -F /config/ssh/easy.cg root@server1 'service httpd restart'
 
   # Lots of people use OliveTin to build web interfaces for their electronics
   # projects. It's best to install OliveTin as a native package (eg, .deb), and
@@ -272,3 +298,4 @@ dashboards:
 
           - title: 'Start {{ container.Names }}'
           - title: 'Stop {{ container.Names }}'
+themeName: buttonbox

+ 2 - 0
internal/config/emoji.go

@@ -14,6 +14,8 @@ var emojis = map[string]string{
 	"logs":        "🔍",
 	"light":       "💡",
 	"robot":       "🤖",
+	"ssh":         "🔐",
+	"theme":       "🎨",
 }
 
 func lookupHTMLIcon(keyToLookup string, defaultIcon string) string {

+ 3 - 0
var/helper-actions/olivetin-get-dashboard-icons

@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+olivetin-get-git-repo "https://github.com/walkxcode/dashboard-icons.git" /config/custom-webui/dashboard-icons/

+ 6 - 0
var/helper-actions/olivetin-get-git-repo

@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+REPO=$1
+DEST=$2
+
+git -C "$DEST" pull || git clone "$REPO" "$DEST"

+ 12 - 0
var/helper-actions/olivetin-get-theme

@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+
+olivetin-get-git-repo "$1" "/config/custom-webui/themes/$2"
+
+if grep -E -q "^themeName" /config/config.yaml; then
+	echo "Updating theme in config file"
+	sed -i "s/^themeName:.*/themeName: $2/g" /config/config.yaml
+else
+	echo "themeName: $2" >> /config/config.yaml
+fi
+
+echo "You must restart OliveTin for theme changes to take effect."

+ 7 - 4
var/helper-actions/olivetin-setup-easy-ssh

@@ -18,13 +18,16 @@ 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 "    shell: ssh -F /config/ssh/easy.cfg 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 "Note: This config has ssh key checking turned off so you don't have to "
+echo "keep approving host keys inside the OliveTin container. This should only"
+echo "be used in environments where checking SSH host keys is not important."
+echo ""
+echo "If validating SSH host keys is important, you should not use this config."
 echo ""
 
-cat <<EOF > /config/ssh/config
+cat <<EOF > /config/ssh/easy.cfg
 Host *
 	StrictHostKeyChecking no
 	UserKnownHostsFile=/dev/null