From 4047951dafeaa811da9c574b646dd20d9cb94188 Mon Sep 17 00:00:00 2001 From: Christopher Date: Sat, 4 Nov 2023 12:21:38 -0500 Subject: [PATCH] Add script to edit CasaOS apps using chosen editor --- edit-casaos-apps/README.md | 5 +++ edit-casaos-apps/run.sh | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 edit-casaos-apps/README.md create mode 100644 edit-casaos-apps/run.sh diff --git a/edit-casaos-apps/README.md b/edit-casaos-apps/README.md new file mode 100644 index 0000000..40520fd --- /dev/null +++ b/edit-casaos-apps/README.md @@ -0,0 +1,5 @@ +# Run command + +```bash +bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/edit-casaos-apps/run.sh)" +``` diff --git a/edit-casaos-apps/run.sh b/edit-casaos-apps/run.sh new file mode 100644 index 0000000..4518676 --- /dev/null +++ b/edit-casaos-apps/run.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Define the apps directory +APPS_DIR="/var/lib/casaos/apps" + +# Function to list all apps +list_apps() { + echo "Available apps:" + ls "$APPS_DIR" +} + +# Function to edit the docker-compose file with the chosen editor +edit_docker_compose() { + local service_name=$1 + local editor_choice=$2 + local docker_compose_path="${APPS_DIR}/${service_name}/docker-compose.yml" + + if [[ ! -f "$docker_compose_path" ]]; then + echo "The docker-compose.yml file does not exist for the service: $service_name" + exit 1 + fi + + # Open the editor + if [[ "$editor_choice" == "nano" ]]; then + nano "$docker_compose_path" + elif [[ "$editor_choice" == "vim" ]]; then + vim "$docker_compose_path" + else + echo "Invalid editor choice. Please select 'nano' or 'vim'." + exit 1 + fi + + # Apply the changes using casaos-cli + casaos-cli app-management apply "$service_name" --file="$docker_compose_path" +} + +# Main script starts here +echo "Welcome to the CasaOS App Editor." + +# List all apps for the user to choose from +list_apps + +# Prompt the user for the app to edit +read -p "Enter the name of the app you want to edit: " SERVICE_NAME + +# Check if the service directory exists +if [[ ! -d "${APPS_DIR}/${SERVICE_NAME}" ]]; then + echo "The selected app does not exist. Please try again." + exit 1 +fi + +# Ask the user to choose an editor +echo "Please select an editor:" +echo "1. nano" +echo "2. vim" +read -p "Enter your choice (1 or 2): " EDITOR_CHOICE + +case $EDITOR_CHOICE in + 1) + edit_docker_compose "$SERVICE_NAME" "nano" + ;; + 2) + edit_docker_compose "$SERVICE_NAME" "vim" + ;; + *) + echo "Invalid choice. Please enter 1 for nano or 2 for vim." + exit 1 + ;; +esac + +echo "Editing complete."