Skip to content

Commit

Permalink
fixes for tool_swap script
Browse files Browse the repository at this point in the history
Thanks Hr_Ravn!
  • Loading branch information
rootiest committed Aug 12, 2023
1 parent 8ff1e14 commit 07d7a4c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions extras/tool_swap/tool_swap.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/bash

# Copyright (C) 2022 Chris Laprade
#
#
# This file is part of zippy_config.
#
#
# zippy_config is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# zippy_config is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with zippy_config. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -22,6 +22,8 @@
### Written with the assistance of an AI ###
############################################

# Define the file to be searched
filename=~/printer_data/config/printer.cfg

# Check if the required number of arguments have been provided
if [ $# -ne 1 ]
Expand All @@ -30,22 +32,23 @@ then
exit 1
fi

# Assign the argument to a variable
# Assign the argument to a variable as an integer

tool_number=$1
# Convert to an inteeger
tool_number=$((tool_number))


# Check if the input parameter is a valid integer
if ! [[ $tool_number =~ ^[0-9]+$ ]]
if [ $tool_number -lt 0 ]
then
echo "Error: Invalid input. Integer required."
echo "Error: Invalid input. Integer must be greater than or equal to 0."
exit 1
fi

# Construct the replacement string
replace_string="[include tool$tool_number.cfg]"

# Define the file to be searched
filename=~/printer_data/config/printer.cfg

# Check if the file exists
if [ ! -f "$filename" ]
then
Expand All @@ -69,7 +72,7 @@ else
echo "Error: More than one occurrence of the regex pattern was found."
exit 1
fi

mv "$temp_file" "$filename"
fi

0 comments on commit 07d7a4c

Please sign in to comment.