From e72c0ed92a2318f429cb4a9ebf68a389c98fe4e1 Mon Sep 17 00:00:00 2001 From: Torben Haack Date: Thu, 10 Oct 2024 06:17:26 +0200 Subject: [PATCH] refactored structure --- .../reservation-platform/.containerignore | 4 +++ packages/reservation-platform/build.sh | 11 -------- .../docker/build_image.sh | 18 +++++++++++++ .../{ => scripts}/switch_network.sh | 25 +++++++++++++++++-- 4 files changed, 45 insertions(+), 13 deletions(-) delete mode 100755 packages/reservation-platform/build.sh create mode 100755 packages/reservation-platform/docker/build_image.sh rename packages/reservation-platform/{ => scripts}/switch_network.sh (52%) diff --git a/packages/reservation-platform/.containerignore b/packages/reservation-platform/.containerignore index 4e13ec6..47b7478 100644 --- a/packages/reservation-platform/.containerignore +++ b/packages/reservation-platform/.containerignore @@ -1,3 +1,7 @@ +# Build and utility assets +docker/ +scripts/ + # Ignore node_modules as they will be installed in the container node_modules diff --git a/packages/reservation-platform/build.sh b/packages/reservation-platform/build.sh deleted file mode 100755 index c23489c..0000000 --- a/packages/reservation-platform/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -# Build the Docker image -echo "Building the Docker image..." -if sudo docker build -t myp-rp:latest . -f Containerfile; then - echo "Docker image built successfully." -else - echo "Failed to build the Docker image." - exit 1 -fi - diff --git a/packages/reservation-platform/docker/build_image.sh b/packages/reservation-platform/docker/build_image.sh new file mode 100755 index 0000000..f2f7a7e --- /dev/null +++ b/packages/reservation-platform/docker/build_image.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Specify the image name and tag +IMAGE_NAME="myp-rp" +IMAGE_TAG="latest" + +# Specify the output file name +OUTPUT_FILE="myp-rp_latest.tar.xz" + +# Save the Docker image and compress it with xz +docker save ${IMAGE_NAME}:${IMAGE_TAG} | xz -z -T0 > ./${OUTPUT_FILE} + +# Check if the operation was successful +if [ $? -eq 0 ]; then + echo "Image successfully saved and compressed to ${OUTPUT_FILE}" +else + echo "Error occurred while saving and compressing the image" +fi diff --git a/packages/reservation-platform/switch_network.sh b/packages/reservation-platform/scripts/switch_network.sh similarity index 52% rename from packages/reservation-platform/switch_network.sh rename to packages/reservation-platform/scripts/switch_network.sh index 75a58d4..0960ae0 100755 --- a/packages/reservation-platform/switch_network.sh +++ b/packages/reservation-platform/scripts/switch_network.sh @@ -3,6 +3,15 @@ # Define the state file STATE_FILE="/tmp/network_toggle_state" +# Function to display current state +show_current_state() { + if [ "$1" == "down" ]; then + echo "Current state: Ethernet and MACVLAN active, Wi-Fi inactive" + else + echo "Current state: Wi-Fi active, Ethernet and MACVLAN inactive" + fi +} + # Check if the state file exists if [ -f "$STATE_FILE" ]; then # If the state file exists, read the state @@ -13,19 +22,31 @@ else echo "$STATE" > "$STATE_FILE" fi +# Show current state +show_current_state "$STATE" + # Toggle the state if [ "$STATE" == "down" ]; then - echo "Bringing interfaces down and up..." + echo "Switching to Wi-Fi mode..." + echo "Deactivating: Ethernet (eth0) and MACVLAN interfaces" sudo ip link set macvlan0 down sudo ip link set macvlan1 down sudo ip link set eth0 down + echo "Activating: Wi-Fi (wlan0)" sudo ip link set wlan0 up echo "up" > "$STATE_FILE" # Update the state to "up" else - echo "Bringing interfaces up and down..." + echo "Switching to Ethernet and MACVLAN mode..." + echo "Deactivating: Wi-Fi (wlan0)" sudo ip link set wlan0 down + echo "Activating: Ethernet (eth0) and MACVLAN interfaces" sudo ip link set eth0 up sudo ip link set macvlan1 up sudo ip link set macvlan0 up echo "down" > "$STATE_FILE" # Update the state to "down" fi + +# Show new state +echo "" +echo "Switch completed." +show_current_state $(cat "$STATE_FILE")