diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index a0e107e..744f1da 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:kmf-v2.5 diff --git a/Dockerfile b/Dockerfile index 8ed2256..3cdc533 100644 --- a/Dockerfile +++ b/Dockerfile @@ -83,6 +83,14 @@ RUN find /opt/lrgex/kiauh -type f -exec chmod +x {} \; \ # Set the default shell to bash instead of sh beacuse kiauh needs this terminal ENV TERM xterm +# this to install klipper, moonraker and fluidd, you can change fluidd to mainsail +ENV PACKAGES="klipper moonraker fluidd" + +# this has the script to install klipper, moonraker and fluidd +RUN ./klipper.sh + +ENV PACKAGES="" + # Enable systemd init system in the container VOLUME [ "/tmp", "/run", "/run/lock" ] diff --git a/reference.txt b/reference.txt index 516484a..4ce27d9 100644 --- a/reference.txt +++ b/reference.txt @@ -64,7 +64,7 @@ sudo docker run -d \ docker run --rm \ --v /mnt/backups/klipper:/backup \ +-v /mnt/fastshare/klipper:/backup \ -v klipper-config:/source \ -e LOCAL_BACKUP="true" \ -e TZ="Asia/Riyadh" \ @@ -94,15 +94,13 @@ services: ports: - "5001:80" - "7125:7125" - environment: - - PACKAGES="klipper moonraker fluidd" devices: - "/dev/ttyUSB0:/dev/ttyUSB0" klipper-backarosa: image: lrgex/backarosa container_name: klipper-backarosa - restart: always + restart: no command: backup volumes: - /mnt/fastshare/klipper:/backup @@ -116,4 +114,3 @@ services: volumes: klipper-config: - external: true \ No newline at end of file diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index a476fda..ed415b2 100644 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -6,22 +6,13 @@ cat << "EOF" ██║ ██╔══██╗██║ ██║██╔══╝ ██╔██╗ ███████╗██║ ██║╚██████╔╝███████╗██╔╝ ██╗ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ -╦╔═┬ ┬┌─┐┌─┐┌─┐┬─┐ -╠╩╗│ │├─┘├─┘├┤ ├┬┘ -╩ ╩┴─┘┴┴ ┴ └─┘┴└─ v2.3 +╦╔═┬ ┬┌─┐┌─┐┌─┐┬─┐ ╔╦╗┌─┐┌─┐┬┌─┌─┐┬─┐ +╠╩╗│ │├─┘├─┘├┤ ├┬┘───║║│ ││ ├┴┐├┤ ├┬┘ +╩ ╩┴─┘┴┴ ┴ └─┘┴└─ ═╩╝└─┘└─┘┴ ┴└─┘┴└─ v2.5 EOF ##################### Starting code ##################### -##################### Backarosa ##################### -backarosa=$(grep -c "restore done" /opt/lrgex/flags) -if [ ! $backarosa ]; then - echo "Backuping klipper files..." - cp -r /home/lrgex /tmp/lrgex -fi - -##################### End Backarosa ##################### - # This script will run on every container start if ! systemctl is-enabled nginx > /dev/null 2>&1; then echo "Enabling NGINX..." @@ -66,13 +57,6 @@ for package in "${packages_array[@]}"; do fi done -if [ "${RESTORE}" = "true" ] && [ ! $backarosa ]; then - echo "Restoring klipper files..." - cp -r /tmp/lrgex /home/lrgex - rm -rf /tmp/lrgex - echo "restore done" >> /opt/lrgex/flags -fi - ##################### End code ##################### diff --git a/scripts/klipper.sh b/scripts/klipper.sh new file mode 100644 index 0000000..028fb9f --- /dev/null +++ b/scripts/klipper.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +packages_str=$PACKAGES +IFS=' ' read -r -a packages_array <<< "$packages_str" + +for package in "${packages_array[@]}"; do + if [ "${package}" = "klipper" ] && [ ! -d "/home/lrgex/klipper" ]; then + echo "Installing Klipper with Kiauh..." + su lrgex -c 'expect ./klipper.exp' + fi + if [ "${package}" = "moonraker" ] && [ ! -d "/home/lrgex/moonraker" ]; then + echo "Installing Moonraker with Kiauh..." + su lrgex -c 'expect ./moonraker.exp' + fi + 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" ] && [ "${package}" = "fluidd" ]; then + echo -e "\e[31mMainsail detected, skipping Fluidd installation.\e[0m" + echo -e "\e[31mIf you want to install Fluidd, please re run the container without the Mainsail package. .e.g [-e PACKAGES=\"klipper moonraker fluidd\"]\e[0m" + sleep 5 + break + 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" ] && [ "${package}" = "mainsail" ]; then + echo -e "\e[31mFluidd detected, skipping Mainsail installation.\e[0m" + echo -e "\e[31mIf you want to install Mainsail, please re run the container without the Fluidd package. .e.g [-e PACKAGES=\"klipper moonraker mainsail\"]\e[0m" + sleep 5 + break + fi +done \ No newline at end of file diff --git a/test/test-entrypoint.sh b/test/test-entrypoint.sh index a476fda..a39ed9a 100644 --- a/test/test-entrypoint.sh +++ b/test/test-entrypoint.sh @@ -6,21 +6,13 @@ cat << "EOF" ██║ ██╔══██╗██║ ██║██╔══╝ ██╔██╗ ███████╗██║ ██║╚██████╔╝███████╗██╔╝ ██╗ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ -╦╔═┬ ┬┌─┐┌─┐┌─┐┬─┐ -╠╩╗│ │├─┘├─┘├┤ ├┬┘ -╩ ╩┴─┘┴┴ ┴ └─┘┴└─ v2.3 +╦╔═┬ ┬┌─┐┌─┐┌─┐┬─┐ ╔╦╗┌─┐┌─┐┬┌─┌─┐┬─┐ +╠╩╗│ │├─┘├─┘├┤ ├┬┘───║║│ ││ ├┴┐├┤ ├┬┘ +╩ ╩┴─┘┴┴ ┴ └─┘┴└─ ═╩╝└─┘└─┘┴ ┴└─┘┴└─ v2.5 EOF ##################### Starting code ##################### -##################### Backarosa ##################### -backarosa=$(grep -c "restore done" /opt/lrgex/flags) -if [ ! $backarosa ]; then - echo "Backuping klipper files..." - cp -r /home/lrgex /tmp/lrgex -fi - -##################### End Backarosa ##################### # This script will run on every container start if ! systemctl is-enabled nginx > /dev/null 2>&1; then @@ -66,12 +58,7 @@ for package in "${packages_array[@]}"; do fi done -if [ "${RESTORE}" = "true" ] && [ ! $backarosa ]; then - echo "Restoring klipper files..." - cp -r /tmp/lrgex /home/lrgex - rm -rf /tmp/lrgex - echo "restore done" >> /opt/lrgex/flags -fi + ##################### End code ##################### diff --git a/test/test.sh b/test/test.sh new file mode 100644 index 0000000..028fb9f --- /dev/null +++ b/test/test.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +packages_str=$PACKAGES +IFS=' ' read -r -a packages_array <<< "$packages_str" + +for package in "${packages_array[@]}"; do + if [ "${package}" = "klipper" ] && [ ! -d "/home/lrgex/klipper" ]; then + echo "Installing Klipper with Kiauh..." + su lrgex -c 'expect ./klipper.exp' + fi + if [ "${package}" = "moonraker" ] && [ ! -d "/home/lrgex/moonraker" ]; then + echo "Installing Moonraker with Kiauh..." + su lrgex -c 'expect ./moonraker.exp' + fi + 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" ] && [ "${package}" = "fluidd" ]; then + echo -e "\e[31mMainsail detected, skipping Fluidd installation.\e[0m" + echo -e "\e[31mIf you want to install Fluidd, please re run the container without the Mainsail package. .e.g [-e PACKAGES=\"klipper moonraker fluidd\"]\e[0m" + sleep 5 + break + 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" ] && [ "${package}" = "mainsail" ]; then + echo -e "\e[31mFluidd detected, skipping Mainsail installation.\e[0m" + echo -e "\e[31mIf you want to install Mainsail, please re run the container without the Fluidd package. .e.g [-e PACKAGES=\"klipper moonraker mainsail\"]\e[0m" + sleep 5 + break + fi +done \ No newline at end of file diff --git a/testfile2 b/testfile2 index 81d5868..b6a60ee 100644 --- a/testfile2 +++ b/testfile2 @@ -84,6 +84,11 @@ RUN find /opt/lrgex/kiauh -type f -exec chmod +x {} \; \ # Set the default shell to bash instead of sh beacuse kiauh needs this terminal ENV TERM xterm +ENV PACKAGES="klipper moonraker fluidd" + +RUN ./test.sh + +ENV PACKAGES="" # COPY scripts/docker-entrypoint.sh /usr/local/bin/