From ec782bab61ceb99a4cd0c901ceffe5c5b6aa8112 Mon Sep 17 00:00:00 2001 From: lrgex Date: Tue, 14 Nov 2023 14:55:58 +0300 Subject: [PATCH] v2.0 --- .github/workflows/docker-image.yml | 2 +- scripts/docker-entrypoint.sh | 14 +++++++++- scripts/mainsail.exp | 45 ++++++++++++++++++++++++++++++ test/test-entrypoint.sh | 25 +++++++++++++---- 4 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 scripts/mainsail.exp diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index a0e107e..bcaefa4 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -46,4 +46,4 @@ jobs: cache-to: type=local,dest=/tmp/.buildx-cache platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true - tags: lrgex/klipper-docker:latest + tags: lrgex/klipper-docker:2.0 diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 4a55450..d0c6b6d 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -37,9 +37,21 @@ for package in "${packages_array[@]}"; do echo "Installing Moonraker with Kiauh..." su lrgex -c 'expect ./moonraker.exp' fi - if [ "${package}" = "fluidd" ] && [ ! -d "/home/lrgex/fluidd" ]; then + if [ "${package}" = "fluidd" ] && [ ! -d "/home/lrgex/fluidd" ] && [ ! -d "/home/lrgex/mainsail" ]; then echo "Installing Fluidd with Kiauh..." su lrgex -c 'expect ./fluidd.exp' + elif [ -d "/home/lrgex/mainsail" ]; then + echo "Mainsail detected, skipping Fluidd installation." + echo "If you want to install Fluidd, please re run the container without the Mainsail package. .e.g [-e PACKAGES=klipper,moonraker,fluidd]]" + sleep 5 + fi + if [ "${package}" = "mainsail" ] && [ ! -d "/home/lrgex/mainsail" ] && [ ! -d "/home/lrgex/fluidd" ]; then + echo "Installing Mainsail with Kiauh..." + su lrgex -c 'expect ./mainsail.exp' + elif [ -d "/home/lrgex/fluidd" ]; then + echo "Fluidd detected, skipping Mainsail installation." + echo "If you want to install Mainsail, please re run the container without the Fluidd package. .e.g [-e PACKAGES=klipper,moonraker,mainsail]" + sleep 5 fi done diff --git a/scripts/mainsail.exp b/scripts/mainsail.exp new file mode 100644 index 0000000..c906b97 --- /dev/null +++ b/scripts/mainsail.exp @@ -0,0 +1,45 @@ +#!/usr/bin/expect + +# expect used tcl syntax which is very indetaion and spaces sensitive keep that in mind + + +# Set timeout +set timeout 60 + +# Start your process +spawn /opt/lrgex/kiauh/kiauh.sh + +# Initialize a variable to control the menu interaction +set menu 1 + +# Single expect block with multiple patterns +expect { + "*Main Menu*" { + # using condition here to make a break for the loop created by exp_continue as i need to use the pattern 2 times one for pressing 1 and one for pressing q + if {$menu} { + send "1\r" + exp_continue + } else { + send "q\r" + exp_continue + } + } + "*Installation Menu*" { + if {$menu} { + send "3\r" + exp_continue + } else { + send "b\r" + exp_continue + } + } + "*Download the recommended macros? (Y/n):*" { + send "y\r" + set menu 0 + exp_continue + } + timeout { + puts "Operation timed out" + exit 1 + } +} \ No newline at end of file diff --git a/test/test-entrypoint.sh b/test/test-entrypoint.sh index 49c3e44..d0c6b6d 100644 --- a/test/test-entrypoint.sh +++ b/test/test-entrypoint.sh @@ -2,13 +2,13 @@ cat << "EOF" ██╗ ██████╗ ██████╗ ███████╗██╗ ██╗ ██║ ██╔══██╗██╔════╝ ██╔════╝╚██╗██╔╝ -██║ ██████╔╝██║ ███╗█████╗ ╚███╔╝ -██║ ██╔══██╗██║ ██║██╔══╝ ██╔██╗ +██║ ██████╔╝██║ ███╗█████╗ ╚███╔╝ +██║ ██╔══██╗██║ ██║██╔══╝ ██╔██╗ ███████╗██║ ██║╚██████╔╝███████╗██╔╝ ██╗ -╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ +╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╦╔═┬ ┬┌─┐┌─┐┌─┐┬─┐ ╠╩╗│ │├─┘├─┘├┤ ├┬┘ -╩ ╩┴─┘┴┴ ┴ └─┘┴└─ v1.5.1 +╩ ╩┴─┘┴┴ ┴ └─┘┴└─ v2.0 EOF ##################### Starting code ##################### @@ -37,11 +37,24 @@ for package in "${packages_array[@]}"; do echo "Installing Moonraker with Kiauh..." su lrgex -c 'expect ./moonraker.exp' fi - if [ "${package}" = "fluidd" ] && [ ! -d "/home/lrgex/fluidd" ]; then + if [ "${package}" = "fluidd" ] && [ ! -d "/home/lrgex/fluidd" ] && [ ! -d "/home/lrgex/mainsail" ]; then echo "Installing Fluidd with Kiauh..." su lrgex -c 'expect ./fluidd.exp' + elif [ -d "/home/lrgex/mainsail" ]; then + echo "Mainsail detected, skipping Fluidd installation." + echo "If you want to install Fluidd, please re run the container without the Mainsail package. .e.g [-e PACKAGES=klipper,moonraker,fluidd]]" + sleep 5 + fi + if [ "${package}" = "mainsail" ] && [ ! -d "/home/lrgex/mainsail" ] && [ ! -d "/home/lrgex/fluidd" ]; then + echo "Installing Mainsail with Kiauh..." + su lrgex -c 'expect ./mainsail.exp' + elif [ -d "/home/lrgex/fluidd" ]; then + echo "Fluidd detected, skipping Mainsail installation." + echo "If you want to install Mainsail, please re run the container without the Fluidd package. .e.g [-e PACKAGES=klipper,moonraker,mainsail]" + sleep 5 fi done + ##################### End code ##################### @@ -57,4 +70,4 @@ exec /lib/systemd/systemd log-level=info unit=sysinit.target #exec "$@" & wait # This is needed to run other scripts or commands when running the container like docker run -it --rm backarosa:latest /bin/bash, backup,restore,container_start,container_stop ..etc -#so when you run the container it will run only one command from scripts folder and exit, however commands in line 3 and 4 will run on every docker run - mandatory hard coded - \ No newline at end of file +#so when you run the container it will run only one command from scripts folder and exit, however commands in line 3 and 4 will run on every docker run - mandatory hard coded - \ No newline at end of file