-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
91 lines (79 loc) · 2.08 KB
/
install.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
#!/bin/bash
# This script will install the z_tramming macro and configuration files into your klipper configuration.
set -euo pipefail
function install() {
origin=https://github.com/Jomik/klipper-z-tramming.git
dir=$HOME/z_tramming
git clone $origin $dir
echo "Linking macros to into config"
ln -s $dir/macros $HOME/printer_data/config/z_tramming >/dev/null
echo "Copying z_tramming_settings.cfg to config directory"
cp $dir/macros/z_tramming_settings.cfg $HOME/printer_data/config/z_tramming_settings.cfg
}
function backup_file() {
local file=$1
local stamp=$(date +"%Y%m%d_%H%M%S")
local file_bak="${file}.${stamp}.bak"
echo "Backing up $file to $file_bak"
cp "$file" "$file_bak"
}
function include_in_config() {
backup_file "$HOME/printer_data/config/printer.cfg"
echo "Including macro and configuration at the top of printer.cfg"
temp_cfg=(mktemp)
cat >$temp_cfg <<EOF
# Include Z_Tramming macro
# $origin
[include z_tramming_settings.cfg]
[include ./z_tramming/z_tramming.cfg]
EOF
cat "$HOME/printer_data/config/printer.cfg" >>$temp_cfg
mv $temp_cfg "$HOME/printer_data/config/printer.cfg"
}
function add_to_moonraker() {
backup_file "$HOME/printer_data/config/moonraker.conf"
echo "Appending z_tramming to moonraker.conf"
cat >>$HOME/printer_data/config/moonraker.conf <<EOF
[update_manager Z_Tramming]
type: git_repo
channel: dev
path: ~/z_tramming
origin: $origin
managed_services: klipper
primary_branch: main
EOF
}
echo "Do you wish to install Z Tramming?"
select yn in "Yes" "No"; do
case $yn in
Yes)
install
break
;;
No) exit ;;
esac
done
echo "Do you wish to automatically include in printer.cfg?"
select yn in "Yes" "No"; do
case $yn in
Yes)
include_in_config
break
;;
No)
echo -e "Please include the following lines in your printer.cfg\n[include z_tramming_settings.cfg]\n[include ./z_tramming/z_tramming.cfg]"
break
;;
esac
done
echo "Do you wish to automatically add to moonraker?"
select yn in "Yes" "No"; do
case $yn in
Yes)
add_to_moonraker
break
;;
No) break ;;
esac
done
echo "Done! Please edit z_tramming_settings.cfg to match your printer."