From 482ef0e5e8cd68d5a37bf5d5c8828dc1c2cda83a Mon Sep 17 00:00:00 2001 From: James Read Date: Sun, 7 Jul 2024 23:10:33 +0100 Subject: [PATCH] feature: Helper scripts for ssh, themes, etc (#349) * feature: Helper scripts for ssh, themes, etc * cicd: Update goreleaser to support v2 .goreleaser.yml files --- .github/workflows/build-snapshot.yml | 2 +- .github/workflows/build-tag.yml | 2 +- .gitignore | 1 + .goreleaser.yml | 5 +-- Dockerfile | 3 +- Dockerfile.arm64 | 3 +- Dockerfile.armv7 | 2 +- config.yaml | 33 +++++++++++++++++-- internal/config/emoji.go | 2 ++ .../olivetin-get-dashboard-icons | 3 ++ var/helper-actions/olivetin-get-git-repo | 6 ++++ var/helper-actions/olivetin-get-theme | 12 +++++++ var/helper-actions/olivetin-setup-easy-ssh | 11 ++++--- 13 files changed, 71 insertions(+), 14 deletions(-) create mode 100755 var/helper-actions/olivetin-get-dashboard-icons create mode 100755 var/helper-actions/olivetin-get-git-repo create mode 100755 var/helper-actions/olivetin-get-theme diff --git a/.github/workflows/build-snapshot.yml b/.github/workflows/build-snapshot.yml index fac7797..00db81c 100644 --- a/.github/workflows/build-snapshot.yml +++ b/.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 diff --git a/.github/workflows/build-tag.yml b/.github/workflows/build-tag.yml index 2ac1ef7..616b77e 100644 --- a/.github/workflows/build-tag.yml +++ b/.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 diff --git a/.gitignore b/.gitignore index 91dd7d4..7cc4079 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ tmp/ webui/ webui.dev/node_modules webui.dev/.parcel-cache +custom-webui diff --git a/.goreleaser.yml b/.goreleaser.yml index dd55db7..8aec705 100644 --- a/.goreleaser.yml +++ b/.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 }} diff --git a/Dockerfile b/Dockerfile index 6fb94af..6d2ae43 100644 --- a/Dockerfile +++ b/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 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 74fd4fd..3657ad9 100644 --- a/Dockerfile.arm64 +++ b/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 diff --git a/Dockerfile.armv7 b/Dockerfile.armv7 index cbdc443..ebd2c88 100644 --- a/Dockerfile.armv7 +++ b/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 diff --git a/config.yaml b/config.yaml index 058370e..d627202 100644 --- a/config.yaml +++ b/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 diff --git a/internal/config/emoji.go b/internal/config/emoji.go index bd33771..91cc678 100644 --- a/internal/config/emoji.go +++ b/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 { diff --git a/var/helper-actions/olivetin-get-dashboard-icons b/var/helper-actions/olivetin-get-dashboard-icons new file mode 100755 index 0000000..dde596d --- /dev/null +++ b/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/ diff --git a/var/helper-actions/olivetin-get-git-repo b/var/helper-actions/olivetin-get-git-repo new file mode 100755 index 0000000..b3f6226 --- /dev/null +++ b/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" diff --git a/var/helper-actions/olivetin-get-theme b/var/helper-actions/olivetin-get-theme new file mode 100755 index 0000000..c68c391 --- /dev/null +++ b/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." diff --git a/var/helper-actions/olivetin-setup-easy-ssh b/var/helper-actions/olivetin-setup-easy-ssh index 65c7159..99a8779 100755 --- a/var/helper-actions/olivetin-setup-easy-ssh +++ b/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 < /config/ssh/config +cat < /config/ssh/easy.cfg Host * StrictHostKeyChecking no UserKnownHostsFile=/dev/null