From b9d9a5c65df220366985e9554ba0472c0907f51c Mon Sep 17 00:00:00 2001 From: joseto1298 Date: Mon, 26 May 2025 20:06:13 +0200 Subject: [PATCH 1/4] Create install.sh --- install.sh | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 install.sh diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..66471fc --- /dev/null +++ b/install.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +# Function to check for updates +function check_for_updates() { + echo "▶ Checking for updates..." + if [ -d "$HOME/spoolman2slicer" ]; then + cd $HOME/spoolman2slicer || exit 1 + git fetch + LOCAL=$(git rev-parse @) + REMOTE=$(git rev-parse @{u}) + if [ "$LOCAL" != "$REMOTE" ]; then + echo "🔄 Updates available. Updating spoolman2slicer..." + git pull + source venv/bin/activate + pip install -r requirements.txt --upgrade + deactivate + echo "✅ spoolman2slicer updated successfully." + else + echo "✅ spoolman2slicer is up to date." + fi + fi +} + +# Function to select slicer and set variables +function choose_slicer() { + while true; do + # Prompt the user to select a slicer + echo "Select your slicer (default: OrcaSlicer):" + echo "1 - OrcaSlicer" + echo "2 - PrusaSlicer" + echo "3 - SuperSlicer" + echo "b - Back" + read -rp "Enter option [1-3 or b]: " slicer_option + + # Set slicer variables based on user input + case ${slicer_option:-1} in # Default to OrcaSlicer + 1) + SLICER="orcaslicer" + break + ;; + 2) + SLICER="prusaslicer" + break + ;; + 3) + SLICER="superslicer" + break + ;; + b|B) + return 1 + ;; + *) + echo "❌ Invalid slicer selected. Please try again." + ;; + esac + done + + # Prompt the user to enter the output directory + echo "Enter the output directory (default: $HOME/slicers/$SLICER):" + read -rp "Output directory: " output_dir + OUTPUT_DIR=${output_dir:-$HOME/slicers/$SLICER} + echo "✅ Output directory set to: $OUTPUT_DIR" + + # Create the output directory if it doesn't exist + if [ ! -d "$OUTPUT_DIR" ]; then + echo "📁 Creating output directory: $OUTPUT_DIR" + mkdir -p "$OUTPUT_DIR" + fi + + # Prompt the user to enter the Spoolman URL + echo "Enter the Spoolman URL (default: http://localhost:7912):" + read -rp "Spoolman URL: " spoolman_url + SPOOLMAN_URL=${spoolman_url:-http://localhost:7912} # Default to localhost + echo "✅ Spoolman URL set to: $SPOOLMAN_URL" + + # Activate the virtual environment and run the Python script + source $HOME/spoolman2slicer/venv/bin/activate + python $HOME/spoolman2slicer/spoolman2slicer.py -d "$OUTPUT_DIR" -s "$SLICER" -u "$SPOOLMAN_URL" + deactivate + + echo "✅ Templates created successfully in $OUTPUT_DIR" +} + +# Function to install spoolman2slicer and its dependencies +function install_spoolman2slicer() { + echo "▶ Installing spoolman2slicer..." + + cd $HOME + + # Clone the repository if it doesn't already exist + if [ ! -d "$HOME/spoolman2slicer" ]; then + git clone https://github.com/bofh69/spoolman2slicer.git + fi + + cd spoolman2slicer || exit 1 + + # Create a virtual environment if it doesn't already exist + if [ ! -d "$HOME/spoolman2slicer/venv" ]; then + echo "🐍 Creating virtual environment..." + python3 -m venv venv + fi + + # Activate the virtual environment and install dependencies + source $HOME/spoolman2slicer/venv/bin/activate + echo "📦 Installing dependencies..." + pip install -r requirements.txt + echo "✅ Installation complete." +} + +# Function to display the main menu +function show_menu() { + clear + echo "===== spoolman2slicer Setup =====" + echo "1 - Install spoolman2slicer" + echo "2 - Create templates" + echo "0 - Exit" + echo "=================================" + echo -n "Select an option: " + read -r option + + # Handle user selection + case $option in + 1) + install_spoolman2slicer + ;; + 2) + choose_slicer + ;; + 0) + echo "👋 Exiting..." + exit 0 + ;; + *) + echo "❌ Invalid option." + show_menu + ;; + esac +} + +# Start the script by checking for updates and displaying the menu +check_for_updates +show_menu From bab881a8a5025fc1bea5021377da046672948455 Mon Sep 17 00:00:00 2001 From: joseto1298 Date: Wed, 28 May 2025 10:09:56 +0200 Subject: [PATCH 2/4] ADD CopyrightText --- install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.sh b/install.sh index 66471fc..b3d159c 100644 --- a/install.sh +++ b/install.sh @@ -1,5 +1,7 @@ #!/bin/bash +# SPDX-FileCopyrightText: 2025 Jose Tomas Milla + # Function to check for updates function check_for_updates() { echo "▶ Checking for updates..." From 9125bd061b17b47c175fc59131630732c766c094 Mon Sep 17 00:00:00 2001 From: joseto1298 Date: Thu, 2 Oct 2025 18:53:12 +0200 Subject: [PATCH 3/4] Add interactive spoolman2slicer setup script - Bash script to install/update spoolman2slicer and its Python dependencies - Copies slicer templates to user config (~/.config/spoolman2slicer) - Generates filament configuration files for OrcaSlicer, PrusaSlicer, or SuperSlicer - Saves user preferences (slicer, output folder, Spoolman URL) - Includes interactive menu with validation and error handling --- install.sh | 263 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 159 insertions(+), 104 deletions(-) diff --git a/install.sh b/install.sh index b3d159c..ed69ef3 100644 --- a/install.sh +++ b/install.sh @@ -1,144 +1,199 @@ #!/bin/bash - -# SPDX-FileCopyrightText: 2025 Jose Tomas Milla - -# Function to check for updates +# ============================================================================= +# spoolman2slicer-setup.sh +# +# Author: Jose Tomas Milla +# Year: 2025 +# +# Description: +# Interactive Bash script to install and configure spoolman2slicer. +# - Installs or updates spoolman2slicer and its Python dependencies. +# - Copies slicer templates to user config directory (~/.config/spoolman2slicer). +# - Generates filament configuration files for OrcaSlicer, PrusaSlicer, or SuperSlicer. +# - Stores user preferences for slicer, output folder, and Spoolman URL. +# +# Usage: +# Run the script in a terminal: ./spoolman2slicer-setup.sh +# Follow the interactive menu to install or create filament config files. +# +# License: +# SPDX-License-Identifier: MIT +# +# Notes: +# - Requires Python 3 and git installed. +# - The script creates a virtual environment for spoolman2slicer dependencies. +# - Before creating filament configs, ensure templates exist by installing spoolman2slicer. +# ============================================================================= + + +# ========================= +# Colors +# ========================= +RED='\033[0;31m' +GREEN='\033[0;32m' +BLUE='\033[0;34m' +YELLOW='\033[1;33m' +NC='\033[0m' # No color + +# ========================= +# Directories +# ========================= +CONFIG_DIR="$HOME/.config/spoolman2slicer" # Stores user preferences +SP_DIR="$HOME/spoolman2slicer" # spoolman2slicer source code directory + +# Config file to save user preferences +CONFIG_FILE="$CONFIG_DIR/config.ini" +mkdir -p "$CONFIG_DIR" + +# Load previous user settings if available +[ -f "$CONFIG_FILE" ] && source "$CONFIG_FILE" + +# ========================= +# Function: Check for updates +# ========================= function check_for_updates() { - echo "▶ Checking for updates..." - if [ -d "$HOME/spoolman2slicer" ]; then - cd $HOME/spoolman2slicer || exit 1 + echo -e "${BLUE}Checking for updates...${NC}" + if [ -d "$SP_DIR" ]; then + cd "$SP_DIR" || exit 1 git fetch LOCAL=$(git rev-parse @) REMOTE=$(git rev-parse @{u}) if [ "$LOCAL" != "$REMOTE" ]; then - echo "🔄 Updates available. Updating spoolman2slicer..." + echo -e "${BLUE}Updates available. Updating spoolman2slicer...${NC}" git pull source venv/bin/activate pip install -r requirements.txt --upgrade deactivate - echo "✅ spoolman2slicer updated successfully." + echo -e "${GREEN}spoolman2slicer updated successfully.${NC}" else - echo "✅ spoolman2slicer is up to date." + echo -e "${GREEN}spoolman2slicer is up to date.${NC}" fi fi } -# Function to select slicer and set variables +# ========================= +# Function: Install spoolman2slicer +# ========================= +function install_spoolman2slicer() { + echo -e "${BLUE}Installing or updating spoolman2slicer...${NC}" + cd "$HOME" + + [ ! -d "$SP_DIR" ] && git clone https://github.com/bofh69/spoolman2slicer.git + cd "$SP_DIR" || exit 1 + + [ ! -d "$SP_DIR/venv" ] && python3 -m venv venv + + source "$SP_DIR/venv/bin/activate" + echo -e "${BLUE}Installing dependencies...${NC}" + pip install -r requirements.txt + deactivate + + for slicer in orcaslicer prusaslicer superslicer; do + mkdir -p "$CONFIG_DIR/templates-$slicer" + cp -r "$SP_DIR/templates-$slicer/"* "$CONFIG_DIR/templates-$slicer/" 2>/dev/null || true + done + + echo -e "${GREEN}spoolman2slicer installed successfully.${NC}" + read -rp "Press Enter to return to the main menu..." +} + +# ========================= +# Function: Create filament config files +# ========================= function choose_slicer() { + while true; do - # Prompt the user to select a slicer - echo "Select your slicer (default: OrcaSlicer):" + echo -e "${BLUE}Select your slicer (default: ${last_slicer:-OrcaSlicer}):${NC}" echo "1 - OrcaSlicer" echo "2 - PrusaSlicer" echo "3 - SuperSlicer" echo "b - Back" read -rp "Enter option [1-3 or b]: " slicer_option - # Set slicer variables based on user input - case ${slicer_option:-1} in # Default to OrcaSlicer - 1) - SLICER="orcaslicer" - break - ;; - 2) - SLICER="prusaslicer" - break - ;; - 3) - SLICER="superslicer" - break - ;; - b|B) - return 1 - ;; - *) - echo "❌ Invalid slicer selected. Please try again." - ;; + case ${slicer_option:-1} in + 1) SLICER="orcaslicer"; break ;; + 2) SLICER="prusaslicer"; break ;; + 3) SLICER="superslicer"; break ;; + b|B) return 1 ;; + *) echo -e "${RED}Invalid slicer selected. Please try again.${NC}" ;; esac done - # Prompt the user to enter the output directory - echo "Enter the output directory (default: $HOME/slicers/$SLICER):" - read -rp "Output directory: " output_dir - OUTPUT_DIR=${output_dir:-$HOME/slicers/$SLICER} - echo "✅ Output directory set to: $OUTPUT_DIR" - - # Create the output directory if it doesn't exist - if [ ! -d "$OUTPUT_DIR" ]; then - echo "📁 Creating output directory: $OUTPUT_DIR" - mkdir -p "$OUTPUT_DIR" + # Check if templates exist + TEMPLATE_DIR="$CONFIG_DIR/templates-$SLICER" + if [ ! -d "$TEMPLATE_DIR" ] || [ -z "$(ls -A "$TEMPLATE_DIR" 2>/dev/null)" ]; then + echo -e "${RED}No templates found for $SLICER.${NC}" + echo -e "Please run option 1 (Install spoolman2slicer) first to install templates." + read -rp "Press Enter to return to the main menu..." + return 1 fi - # Prompt the user to enter the Spoolman URL - echo "Enter the Spoolman URL (default: http://localhost:7912):" - read -rp "Spoolman URL: " spoolman_url - SPOOLMAN_URL=${spoolman_url:-http://localhost:7912} # Default to localhost - echo "✅ Spoolman URL set to: $SPOOLMAN_URL" + # Output directory inside $HOME + while true; do + read -rp "Enter the output subfolder (inside your home, default: ${last_output_dir:-filament}): " folder + SUBFOLDER=${folder:-${last_output_dir:-filament}} + SUBFOLDER="${SUBFOLDER%/}" # Remove trailing slash + OUTPUT_DIR="$HOME/$SUBFOLDER" + + if mkdir -p "$OUTPUT_DIR" 2>/dev/null; then + echo -e "${GREEN}Output directory set to: $OUTPUT_DIR${NC}" + break + else + echo -e "\nCannot create directory '$OUTPUT_DIR'. Please choose another subfolder." + fi + done - # Activate the virtual environment and run the Python script - source $HOME/spoolman2slicer/venv/bin/activate - python $HOME/spoolman2slicer/spoolman2slicer.py -d "$OUTPUT_DIR" -s "$SLICER" -u "$SPOOLMAN_URL" + # Ask for Spoolman URL without validation + read -rp "Enter the Spoolman URL (default: ${last_spoolman_url:-http://localhost:7912}): " spoolman_url + SPOOLMAN_URL=${spoolman_url:-${last_spoolman_url:-http://localhost:7912}} + echo -e "${GREEN}Spoolman URL set to: $SPOOLMAN_URL${NC}" + + # Save settings as defaults for next execution + { + echo "last_slicer=$SLICER" + echo "last_output_dir=$SUBFOLDER" + echo "last_spoolman_url=$SPOOLMAN_URL" + } > "$CONFIG_FILE" + + # Run Python script + source "$SP_DIR/venv/bin/activate" + python "$SP_DIR/spoolman2slicer.py" -d "$OUTPUT_DIR" -s "$SLICER" -u "$SPOOLMAN_URL" + PYTHON_EXIT_CODE=$? deactivate - echo "✅ Templates created successfully in $OUTPUT_DIR" -} - -# Function to install spoolman2slicer and its dependencies -function install_spoolman2slicer() { - echo "▶ Installing spoolman2slicer..." - - cd $HOME - - # Clone the repository if it doesn't already exist - if [ ! -d "$HOME/spoolman2slicer" ]; then - git clone https://github.com/bofh69/spoolman2slicer.git + if [ $PYTHON_EXIT_CODE -eq 0 ]; then + echo -e "\n${GREEN}Filament configuration files created successfully in $OUTPUT_DIR${NC}" + else + echo -e "\n${RED}Error: Python script failed. Filament configuration files were not created.${NC}" fi - cd spoolman2slicer || exit 1 - - # Create a virtual environment if it doesn't already exist - if [ ! -d "$HOME/spoolman2slicer/venv" ]; then - echo "🐍 Creating virtual environment..." - python3 -m venv venv - fi - - # Activate the virtual environment and install dependencies - source $HOME/spoolman2slicer/venv/bin/activate - echo "📦 Installing dependencies..." - pip install -r requirements.txt - echo "✅ Installation complete." + read -rp "Press Enter to return to the main menu..." } -# Function to display the main menu +# ========================= +# Function: Main menu +# ========================= function show_menu() { - clear - echo "===== spoolman2slicer Setup =====" - echo "1 - Install spoolman2slicer" - echo "2 - Create templates" - echo "0 - Exit" - echo "=================================" - echo -n "Select an option: " - read -r option - - # Handle user selection - case $option in - 1) - install_spoolman2slicer - ;; - 2) - choose_slicer - ;; - 0) - echo "👋 Exiting..." - exit 0 - ;; - *) - echo "❌ Invalid option." - show_menu - ;; - esac + while true; do + clear + echo "===== spoolman2slicer Setup =====" + echo "1 - Install spoolman2slicer" + echo "2 - Create filament configuration files" + echo "0 - Exit" + echo "=================================" + read -rp "Select an option: " option + + case $option in + 1) install_spoolman2slicer ;; + 2) choose_slicer ;; + 0) echo "Exiting..."; exit 0 ;; + *) echo -e "${RED}Invalid option.${NC}"; read -rp "Press Enter to continue..." ;; + esac + done } -# Start the script by checking for updates and displaying the menu +# ========================= +# Script start +# ========================= check_for_updates show_menu From b586563bf7002b291bfda8edf219c106cf17cc51 Mon Sep 17 00:00:00 2001 From: joseto1298 Date: Wed, 8 Oct 2025 16:53:40 +0200 Subject: [PATCH 4/4] Added an uninstaller --- install.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index ed69ef3..c96adc1 100644 --- a/install.sh +++ b/install.sh @@ -59,8 +59,10 @@ function check_for_updates() { LOCAL=$(git rev-parse @) REMOTE=$(git rev-parse @{u}) if [ "$LOCAL" != "$REMOTE" ]; then - echo -e "${BLUE}Updates available. Updating spoolman2slicer...${NC}" - git pull + echo -e "${BLUE}Updates available. Resetting local changes and pulling latest version...${NC}" + git reset --hard HEAD + git clean -fd + git pull --rebase source venv/bin/activate pip install -r requirements.txt --upgrade deactivate @@ -170,15 +172,66 @@ function choose_slicer() { read -rp "Press Enter to return to the main menu..." } +# ========================= +# Function: Uninstall spoolman2slicer (clean everything) +# ========================= +function uninstall_spoolman2slicer() { + echo -e "${RED}WARNING:${NC} This will completely remove spoolman2slicer, including source code, dependencies, configuration and generated profiles." + read -rp "Do you want to proceed with full uninstallation? (y/N): " confirm + if [[ "$confirm" =~ ^[Yy]$ ]]; then + + # Remove spoolman2slicer source directory + if [ -d "$SP_DIR" ]; then + rm -rf "$SP_DIR" + echo -e "${GREEN}spoolman2slicer source directory removed (${SP_DIR}).${NC}" + else + echo -e "${YELLOW}No spoolman2slicer found in ${SP_DIR}.${NC}" + fi + + # Remove configuration directory + if [ -d "$CONFIG_DIR" ]; then + rm -rf "$CONFIG_DIR" + echo -e "${GREEN}Configuration removed (${CONFIG_DIR}).${NC}" + else + echo -e "${YELLOW}No configuration found in ${CONFIG_DIR}.${NC}" + fi + + # Remove last output directory if defined + if [ -n "$last_output_dir" ] && [ -d "$HOME/$last_output_dir" ]; then + rm -rf "$HOME/$last_output_dir" + echo -e "${GREEN}Filament profiles removed (${HOME}/${last_output_dir}).${NC}" + fi + + echo -e "\n${GREEN}Full uninstallation completed.${NC}" + else + echo -e "${YELLOW}Uninstallation canceled.${NC}" + fi + + read -rp "Press Enter to exit..." + exit 0 +} + # ========================= # Function: Main menu # ========================= +/************* ✨ Windsurf Command ⭐ *************/ +# Show the main menu of spoolman2slicer setup script +# +# This function shows the main menu of the spoolman2slicer setup script. +# It will continue to show the menu until the user selects the "Exit" option. +# +# The menu options are: +# 1. Install spoolman2slicer +# 2. Create filament configuration files +# 3. Uninstall spoolman2slicer (clean everything) +/******* c84b53e3-0ca4-4e7a-9079-8b6d54356309 *******/ function show_menu() { while true; do clear echo "===== spoolman2slicer Setup =====" echo "1 - Install spoolman2slicer" echo "2 - Create filament configuration files" + echo "3 - Uninstall spoolman2slicer (clean everything)" echo "0 - Exit" echo "=================================" read -rp "Select an option: " option @@ -186,6 +239,7 @@ function show_menu() { case $option in 1) install_spoolman2slicer ;; 2) choose_slicer ;; + 3) uninstall_spoolman2slicer ;; 0) echo "Exiting..."; exit 0 ;; *) echo -e "${RED}Invalid option.${NC}"; read -rp "Press Enter to continue..." ;; esac