-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathinstall-pa_cal.sh
executable file
·114 lines (101 loc) · 3.6 KB
/
install-pa_cal.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash
KCONFIG_PATH="${HOME}/klipper_config"
link_macros()
{
echo "Linking macros to Klipper..."
ln -sf "${SRCDIR}/pa_cal.cfg" "${KCONFIG_PATH}/pa_cal.cfg"
}
configure_klipper()
{
echo -e "Adding [save_variables] to printer.cfg"
update_section=$(grep -c '\[save_variables\]' \
${KCONFIG_PATH}/printer.cfg || true)
if [ "${update_section}" -eq 0 ]; then
while read -r line; do
echo -e "${line}" >> ${KCONFIG_PATH}/.printer.cfg.tmp
done < "${SCRIPTDIR}/file_templates/printer.cfg_save_variables.txt"
echo >> ${KCONFIG_PATH}/.printer.cfg.tmp
cat ${KCONFIG_PATH}/printer.cfg >> ${KCONFIG_PATH}/.printer.cfg.tmp
mv ${KCONFIG_PATH}/.printer.cfg.tmp ${KCONFIG_PATH}/printer.cfg
else
echo -e "[save_variables] already exist in printer.cfg [SKIPPED]"
fi
# If saved_variables.cfg then merge the files
if [ -f "${KCONFIG_PATH}/saved_variables.cfg" ]; then
echo -e "Adding saved variables to saved_variables.cfg"
awk -F';' '{print $1}' "${SCRIPTDIR}/file_templates/saved_variables.txt" | awk -v OFS=' ' '{$1=$1}1' > "${SCRIPTDIR}/saved_variables_cleanup.temp"
awk '{if(!seen[$0]++)print $0}' "${SCRIPTDIR}/saved_variables_cleanup.temp" "${KCONFIG_PATH}/saved_variables.cfg" > "${SCRIPTDIR}/saved_variables_merged.temp"
cp "${SCRIPTDIR}/saved_variables_merged.temp" "${KCONFIG_PATH}/saved_variables.cfg"
else
echo -e "Creating saved_variables.cfg"
cp -n "${SCRIPTDIR}/file_templates/saved_variables.txt" "${KCONFIG_PATH}/saved_variables.cfg"
fi
echo -e "Adding [include pa_cal.cfg] to printer.cfg"
update_section=$(grep -c '\[include pa_cal.cfg\]' \
${KCONFIG_PATH}/printer.cfg || true)
rm -f ${KCONFIG_PATH}/.printer.cfg.tmp
if [ "${update_section}" -eq 0 ]; then
while read -r line; do
echo -e "${line}" >> ${KCONFIG_PATH}/.printer.cfg.tmp
done < "${SCRIPTDIR}/file_templates/printer.cfg_include_pa_cal.txt"
echo >> ${KCONFIG_PATH}/.printer.cfg.tmp
cat ${KCONFIG_PATH}/printer.cfg >> ${KCONFIG_PATH}/.printer.cfg.tmp
mv ${KCONFIG_PATH}/.printer.cfg.tmp ${KCONFIG_PATH}/printer.cfg
else
echo -e "[include pa_cal.cfg] already exist in printer.cfg [SKIPPED]"
fi
}
# Step 3: configure moonraker
configure_moonraker()
{
echo -e "Adding update manager to moonraker.conf"
update_section=$(grep -c '\[update_manager pa_cal\]' \
${KCONFIG_PATH}/moonraker.conf || true)
if [ "${update_section}" -eq 0 ]; then
echo >> ${KCONFIG_PATH}/moonraker.conf
while read -r line; do
echo -e "${line}" >> ${KCONFIG_PATH}/moonraker.conf
done < "${SCRIPTDIR}/file_templates/moonraker_update.txt"
echo >> ${KCONFIG_PATH}/moonraker.conf
else
echo -e "[update_manager pa_cal] already exist in moonraker.conf [SKIPPED]"
fi
}
# Step 4: restarting Klipper
restart_klipper()
{
echo "Restarting Klipper..."
sudo systemctl restart klipper
}
# Step 4: restarting Klipper
restart_moonraker()
{
echo "Restarting Moonraker..."
sudo systemctl restart moonraker
}
# Helper functions
verify_ready()
{
if [ "$EUID" -eq 0 ]; then
echo "This script must not run as root"
exit -1
fi
}
# Force script to exit if an error occurs
set -e
# Find SRCDIR from the pathname of this script
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/ && pwd )"
SRCDIR="${SCRIPTDIR}/src"
# Parse command line arguments
while getopts "k:" arg; do
case $arg in
k) KCONFIG_PATH=$OPTARG;;
esac
done
# Run steps
verify_ready
link_macros
configure_moonraker
restart_moonraker
configure_klipper
restart_klipper