Skip to content

Commit 6ba66e6

Browse files
authored
Refactor install script to improve variable handling and ensure directory creation (#417)
* Updated `afc_config_dir` in `include/constants.sh` to use curly braces for variable expansion, ensuring consistency and avoiding potential parsing issues. * Modified the `copy_config` function in `include/utils.sh` to copy only the contents of the source directory (`config/*`) instead of the directory itself, preventing redundant directory nesting.
1 parent 667516f commit 6ba66e6

3 files changed

Lines changed: 31 additions & 25 deletions

File tree

include/constants.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
printer_config_dir="$HOME/printer_data/config"
1111
klipper_dir="$HOME/klipper"
1212
afc_path="$HOME/AFC-Klipper-Add-On"
13-
afc_config_dir="$printer_config_dir/AFC"
13+
afc_config_dir="${printer_config_dir}/AFC"
1414
afc_file="$afc_config_dir/AFC.cfg"
1515
moonraker_config_file="$printer_config_dir/moonraker.conf"
1616
klipper_venv="$HOME/klippy-env/bin"

include/utils.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ function show_help() {
3232
}
3333

3434
function copy_config() {
35-
if [ -d "${afc_config_dir}" ]; then
36-
mkdir -p "${afc_config_dir}"
37-
fi
38-
cp -R "${afc_path}/config" "${afc_config_dir}"
35+
mkdir -p "${afc_config_dir}"
36+
cp -R ${afc_path}/config/* "${afc_config_dir}"
3937
}
4038

4139
function clone_repo() {

install-afc.sh

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,53 @@ export LC_ALL=C
1010

1111
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1212

13+
source include/constants.sh
14+
1315
# Menu functions
1416
source include/menus/main_menu.sh
1517
source include/menus/install_menu.sh
1618
source include/menus/update_menu.sh
1719
source include/menus/utilities_menu.sh
1820
source include/menus/additional_system_menu.sh
1921

20-
# Install / Update functions
21-
source include/buffer_configurations.sh
22-
source include/check_commands.sh
23-
source include/colors.sh
24-
source include/constants.sh
25-
source include/install_functions.sh
26-
source include/uninstall.sh
27-
source include/update_commands.sh
28-
source include/update_functions.sh
29-
source include/utils.sh
30-
source include/unit_functions.sh
3122

3223
###################### Main script logic below ######################
3324

3425
while getopts "a:k:s:m:n:b:p:y:u:th" arg; do
3526
case ${arg} in
36-
a) moonraker_address=${OPTARG} ;;
37-
k) klipper_dir=${OPTARG} ;;
38-
m) moonraker_config_file=${OPTARG} ;;
39-
n) moonraker_port=${OPTARG} ;;
40-
s) klipper_service=${OPTARG} ;;
41-
b) branch=${OPTARG} ;;
42-
p) printer_config_dir=${OPTARG} ;;
43-
y) klipper_venv=${OPTARG} ;;
44-
t) test_mode=True ;;
27+
a) export moonraker_address=${OPTARG} ;;
28+
k) export klipper_dir=${OPTARG} ;;
29+
m) export moonraker_config_file=${OPTARG} ;;
30+
n) export moonraker_port=${OPTARG} ;;
31+
s) export klipper_service=${OPTARG} ;;
32+
b) export branch=${OPTARG} ;;
33+
p) export printer_config_dir=${OPTARG} ;;
34+
y) export klipper_venv=${OPTARG} ;;
35+
t) export test_mode=True ;;
4536
h) show_help
4637
exit 0 ;;
4738
*) exit 1 ;;
4839
esac
4940
done
5041

5142
moonraker="${moonraker_address}:${moonraker_port}"
43+
afc_config_dir="${printer_config_dir}/AFC"
44+
afc_file="${afc_config_dir}/AFC.cfg"
45+
moonraker_config_file="${printer_config_dir}/moonraker.conf"
46+
afc_path="$HOME/AFC-Klipper-Add-On"
47+
48+
# Install / Update functions
49+
source include/buffer_configurations.sh
50+
source include/check_commands.sh
51+
source include/colors.sh
52+
source include/install_functions.sh
53+
source include/uninstall.sh
54+
source include/update_commands.sh
55+
source include/update_functions.sh
56+
source include/utils.sh
57+
source include/unit_functions.sh
58+
59+
5260
# Make sure necessary directories exist
5361
echo "Ensuring we are not running as root.."
5462
check_root

0 commit comments

Comments
 (0)