-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocommit.sh
executable file
·102 lines (85 loc) · 4.15 KB
/
autocommit.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
#!/bin/bash
#######################################################################
## NOTE: This script originates from here but I tweaked the pull ##
## command, changed default location for backup, and added a comment ##
## for reference later. ##
#######################################################################
#####################################################################
### Please set the paths accordingly. In case you don't have all ###
### the listed folders, just keep that line commented out. ###
#####################################################################
### Path to your config folder you want to backup
config_folder=~/printer_data/config
# NOTE: The above should work for just about everyone, but a somewhat
# recent update to moonraker changed paths, etc. You can run the
# provided moonraker script 'data-path-fix.sh' to fix/update
# older installs
### Path to your Klipper folder, by default that is '~/klipper'
klipper_folder=~/klipper
### Path to your Moonraker folder, by default that is '~/moonraker'
moonraker_folder=~/moonraker
### Path to your Mainsail folder, by default that is '~/mainsail'
mainsail_folder=~/mainsail
### Path to your Fluidd folder, by default that is '~/fluidd'
#fluidd_folder=~/fluidd
### The branch of the repository that you want to save your config
### By default that is 'main'
branch=main
### Set this to true if you want ONLY the history table to be dumped
### from data.mdb.
history_only=false
#####################################################################
#####################################################################
#####################################################################
################ !!! DO NOT EDIT BELOW THIS LINE !!! ################
#####################################################################
grab_version(){
if [ ! -z "$klipper_folder" ]; then
klipper_commit=$(git -C $klipper_folder describe --always --tags --long | awk '{gsub(/^ +| +$/,"")} {print $0}')
m1="Klipper version: $klipper_commit"
fi
if [ ! -z "$moonraker_folder" ]; then
moonraker_commit=$(git -C $moonraker_folder describe --always --tags --long | awk '{gsub(/^ +| +$/,"")} {print $0}')
m2="Moonraker version: $moonraker_commit"
fi
if [ ! -z "$mainsail_folder" ]; then
mainsail_ver=$(head -n 1 $mainsail_folder/.version)
m3="Mainsail version: $mainsail_ver"
fi
if [ ! -z "$fluidd_folder" ]; then
fluidd_ver=$(head -n 1 $fluidd_folder/.version)
m4="Fluidd version: $fluidd_ver"
fi
}
# Here we dump stats database to text format for backup, IF the right software is found
# To RESTORE the database, use the following command:
# mdb_load -f ~/printer_data/config/data.mdb.backup -s -T ~/printer_data/database/
if command -v /usr/bin/mdb_dump &> /dev/null
then
if $history_only
then
echo "mdb_dump found! Exporting history table from data.mdb to ~/printer_data/config/data.mdb.backup"
mdb_dump -s history -n ~/printer_data/database/data.mdb -f ~/printer_data/config/data.mdb.backup
else
echo "mdb_dump found! Exporting ALL tables data.mdb to ~/printer_data/config/data.mdb.backup"
mdb_dump -a -n ~/printer_data/database/data.mdb -f ~/printer_data/config/data.mdb.backup
fi
else
echo "mdb_dump not found! Consider installing it via 'sudo apt install lmdb-utils' if you want to back up your statistics database!"
fi
# To fully automate this and not have to deal with auth issues, generate a legacy token on Github
# then update the command below to use the token. Run the command in your base directory and it will
# handle auth. This should just be executed in your shell and not committed to any files or
# Github will revoke the token. =)
# git remote set-url origin https://[email protected]/EricZimmerman/Voron24Configs.git/
# Note that that format is for changing things after the repository is in use, vs initially
push_config(){
cd $config_folder
git pull origin $branch --no-rebase
git add .
current_date=$(date +"%Y-%m-%d %T")
git commit -m "Autocommit from $current_date" -m "$m1" -m "$m2" -m "$m3" -m "$m4"
git push origin $branch
}
grab_version
push_config