Skip to content

Commit

Permalink
fix(scripts): 🚨 Fix shell script linting
Browse files Browse the repository at this point in the history
Fix shell script linting
  • Loading branch information
rootiest committed Aug 12, 2023
1 parent 31bd1b0 commit c1ca5a6
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

# Don't want to escape a single quote?
disable=SC1003

# Don't use a ( subshell ) to avoid having to cd back.
disable=SC2103

# Don't check exit code directly with e.g. 'if mycmd;', not indirectly with $?.
disable=SC2181
Empty file modified extras/tool_swap/tool_swap.sh
100755 → 100644
Empty file.
10 changes: 5 additions & 5 deletions scripts/datetime.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 @@ -23,4 +23,4 @@
time=$(date "+%c")

# Return the time
echo $time
echo "$time"
22 changes: 11 additions & 11 deletions scripts/fix_scripts.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
#!/bin/bash

# Copyright (C) 2023 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/>.

# Copyright (C) 2023 Chris Laprade ([email protected])
#
#
# This file is part of zippy_print.
#
#
# zippy_print 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_print 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_print. If not, see <http://www.gnu.org/licenses/>.

#!/bin/bash

# Help function
function show_help {
echo "Usage: $0 [directory_path]"
Expand All @@ -58,7 +58,7 @@ py_count=$(find "$1" -type f -name "*.py" | wc -l) # Count the number of .py fil
total_count=$((sh_count + py_count)) # Add the counts together to get the total count

# Make every .sh and .py file executable
find "$1" -type f \( -name "*.sh" -o -name "*.py" \) -print0 | while read -d $'\0' file # Find all .sh and .py files and loop through them
find "$1" -type f \( -name "*.sh" -o -name "*.py" \) -print0 | while read -rd $'\0' file # Find all .sh and .py files and loop through them
do
if [[ ! -x $file ]]; then # Check if the file is not executable
chmod -v +x "$file" # Make the file executable and print a message
Expand Down
74 changes: 37 additions & 37 deletions scripts/git_backup.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

export $(grep -v '^#' ~/.gh_token | xargs -0)
export "$(grep -v '^#' ~/.gh_token | xargs -0)"

#####################################################################
### Please set the paths accordingly. In case you don't have all ###
Expand Down Expand Up @@ -29,45 +29,45 @@ mainsail_folder=~/mainsail
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
#####################################################################
grab_version(){
if [ ! -z "$klipper_folder" ]; then
echo -n "Getting klipper version="
cd "$klipper_folder"
klipper_commit=$(git rev-parse --short=7 HEAD)
m1="Klipper on commit: $klipper_commit"
echo $klipper_commit
cd ..
fi
if [ ! -z "$moonraker_folder" ]; then
echo -n "Getting moonraker version="
cd "$moonraker_folder"
moonraker_commit=$(git rev-parse --short=7 HEAD)
m2="Moonraker on commit: $moonraker_commit"
echo $moonraker_commit
cd ..
fi
if [ ! -z "$mainsail_folder" ]; then
echo -n "Getting mainsail version="
mainsail_ver=$(head -n 1 $mainsail_folder/.version)
m3="Mainsail version: $mainsail_ver"
echo $mainsail_ver
fi
if [ ! -z "$fluidd_folder" ]; then
echo -n "Getting fluidd version="
fluidd_ver=$(head -n 1 $fluidd_folder/.version)
m4="Fluidd version: $fluidd_ver"
echo $fluidd_ver
fi
if [ -n "$klipper_folder" ]; then
echo -n "Getting klipper version="
cd "$klipper_folder" || exit
klipper_commit=$(git rev-parse --short=7 HEAD)
m1="Klipper on commit: $klipper_commit"
echo "$klipper_commit"
cd ..
fi
if [ -n "$moonraker_folder" ]; then
echo -n "Getting moonraker version="
cd "$moonraker_folder" || exit
moonraker_commit=$(git rev-parse --short=7 HEAD)
m2="Moonraker on commit: $moonraker_commit"
echo "$moonraker_commit"
cd ..
fi
if [ -n "$mainsail_folder" ]; then
echo -n "Getting mainsail version="
mainsail_ver=$(head -n 1 $mainsail_folder/.version)
m3="Mainsail version: $mainsail_ver"
echo "$mainsail_ver"
fi
if [ -n "$fluidd_folder" ]; then
echo -n "Getting fluidd version="
fluidd_ver=$(head -n 1 "$fluidd_folder"/.version)
m4="Fluidd version: $fluidd_ver"
echo "$fluidd_ver"
fi
}

push_config(){
cd $config_folder
echo Pushing updates
git pull -v
git add . -v
current_date=$(date +"%Y-%m-%d %T")
git commit -m "Backup triggered on $current_date" -m "$m1" -m "$m2" -m "$m3" -m "$m4"
# git push "https://rootiest:[email protected]/rootiest/zippy-klipper_config.git"
git push "[email protected]:rootiest/zippy-klipper_config.git"
cd $config_folder || exit
echo Pushing updates
git pull -v
git add . -v
current_date=$(date +"%Y-%m-%d %T")
git commit -m "Backup triggered on $current_date" -m "$m1" -m "$m2" -m "$m3" -m "$m4"
# git push "https://rootiest:[email protected]/rootiest/zippy-klipper_config.git"
git push "[email protected]:rootiest/zippy-klipper_config.git"
}

grab_version
Expand Down
25 changes: 12 additions & 13 deletions scripts/invert_file.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
#!/bin/bash
# Copyright (C) 2023 Chris Laprade ([email protected])
#
#
# This file is part of config.
#
#
# 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.
#
#
# 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 config. If not, see <http://www.gnu.org/licenses/>.

#!/bin/bash

# Check if both the source and output filename arguments are provided
if [ $# -lt 2 ]
then
then
echo "Error: Two filenames are required."
exit 1
fi

# Check if the source file exists
if [ ! -f $1 ]
then
if [ ! -f "$1" ]
then
echo "Error: Source file not found."
exit 1
fi
Expand All @@ -42,17 +41,17 @@ output_extension="${source_extension}"
output_basename=$(basename -- "$2")
output_basename="${output_basename%.*}"
if [ "${output_filename}" = "${output_basename}" ]
then
then
output_filename="${output_filename}.${output_extension}"
fi

# Invert the file
tac $1 > $output_filename
tac "$1" > "$output_filename"

# Confirm successful inversion
if [ $? -eq 0 ]
then
then
echo "File successfully inverted as $output_filename."
else
else
echo "Error: Unable to invert file."
fi
6 changes: 3 additions & 3 deletions scripts/kamp_patch.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
# This script is used to patch the stock Klipper install with the testing KAMP fork
cd ~
cd ~ || exit
git clone -b for/master/adaptive_bed_mesh https://github.com/voidtrance/klipper.git kamp-klipper
cd kamp-klipper
cd kamp-klipper || exit
mkdir ~/stock_klipper_files
mv ~/klipper/klippy/extras/bed_mesh.py ~/stock_klipper_files/bed_mesh.py
cd ~/kamp_klipper
cd ~/kamp_klipper || exit
ln -sr klippy/extras/bed_mesh.py ~/klipper/klippy/extras/
14 changes: 7 additions & 7 deletions scripts/mcu_timing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fi
if [ "$1" == "install" ]; then
echo -e "\e[31mWARNING: This will modify the mcu.py file and cause the klipper repo to fail verification.\e[0m"
echo "Press any key to continue or CTRL+C to cancel."
read -n 1 -s
read -rn 1 -s
echo "Installing custom mcu.py file..."
# change the 'TRSYNC_TIMEOUT = 0.025' line to 'TRSYNC_TIMEOUT = 0.05'
sed -i 's/TRSYNC_TIMEOUT = 0.025/TRSYNC_TIMEOUT = 0.05/g' ~/klipper/klippy/mcu.py
Expand All @@ -81,7 +81,7 @@ if [ "$1" == "update" ]; then
cp ~/klipper/klippy/mcu.py /tmp/mcu.py
# remove the custom mcu.py file
rm ~/klipper/klippy/mcu.py
cd ~/klipper
cd ~/klipper || exit
# update the klipper repo
git pull
# restore the custom mcu.py file
Expand All @@ -101,14 +101,14 @@ fi
if [ "$1" == "remove" ]; then
echo -e "\e[31mWARNING: This will remove the modification from the mcu.py file.\e[0m"
echo "Press any key to continue or CTRL+C to cancel."
read -n 1 -s
read -rn 1 -s
echo "Removing custom mcu.py file..."
# remove the custom mcu.py file
rm ~/klipper/klippy/mcu.py
# collect the latest mcu.py file from the klipper repo
curl -o ~/klipper/klippy/mcu.py https://raw.githubusercontent.com/Klipper3d/klipper/master/klippy/mcu.py
# update the klipper repo
cd ~/klipper
cd ~/klipper || exit
git pull
# Report success or failure
if grep -q "TRSYNC_TIMEOUT = 0.025" ~/klipper/klippy/mcu.py; then
Expand All @@ -123,14 +123,14 @@ fi
if [ "$1" == "patch" ]; then
echo -e "\e[31mWARNING: This will modify the mcu.py file and cause the klipper repo to fail verification.\e[0m"
echo "Press any key to continue or CTRL+C to cancel."
read -n 1 -s
read -rn 1 -s
echo "Patching mcu.py file..."
# remove the custom mcu.py file
rm ~/klipper/klippy/mcu.py
# collect the latest mcu.py file from the klipper repo
curl -o ~/klipper/klippy/mcu.py https://raw.githubusercontent.com/Klipper3d/klipper/master/klippy/mcu.py
# update the klipper repo
cd ~/klipper
cd ~/klipper || exit
git pull
# change the 'TRSYNC_TIMEOUT = 0.025' line to 'TRSYNC_TIMEOUT = 0.05'
sed -i 's/TRSYNC_TIMEOUT = 0.025/TRSYNC_TIMEOUT = 0.05/g' ~/klipper/klippy/mcu.py
Expand All @@ -150,4 +150,4 @@ if [ "$1" == "check" ]; then
else
echo -e "\e[31mmcu.py file has not been patched\e[0m"
fi
fi
fi

0 comments on commit c1ca5a6

Please sign in to comment.