-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·62 lines (57 loc) · 1.71 KB
/
setup.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
#!/bin/sh
#
# Overleaf Git Tools
# This file is based on the equivalent in SolidWorks Git Tools
#
# Copyright (C) 2021 Tim Clifford
# Copyright (C) 2021 Tim Clifford, Henry Franks
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Remove existing sld config if it exists and replace it with the latest config
header_start="\
### ---------------- BEGIN AUTO ADDED OVERLEAF TOOLS ---------------------- ###\
"
header_end="\
### ----------------- END AUTO ADDED OVERLEAF TOOLS ----------------------- ###\
"
setup_config() { # args (header_start, header_end, file to add, file to add to)
if ! [ -f $4 ]; then
# Thanks, I hate it
echo "\
$1
$(cat "$3")
$2" >> $4
elif cat $4 | grep -q "$1"; then
echo "Found existing overleaf config in $4, replacing..."
# This is cursed, but at least it's not vba...
f="\
$(grep -B9999 "$1" $4 | grep -v "$1")
$1
$(cat "$3")
$2
$(grep -A9999 "$2" $4 | grep -v "$2")"
# Can't oneline this because of order of operations
echo "$f" > $4
else
# Thanks, I hate it
echo "\
$1
$(cat "$3")
$2" >> $4
fi
}
setup_config \
"$header_start" "$header_end" \
"ols-git-tools/gitconfig" \
".git/config"