-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·132 lines (107 loc) · 3.03 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
function fail(){
EXCODE=$1
shift
echo "$@" >&2
exit "$EXCODE"
}
WORKDIR=$(realpath "$(dirname "$0")")
cd "$WORKDIR" || fail 1 "The working directory could not be determined."
# For hooks
export WORKDIR
# === CODE BELOW HERE ===
for f in lib/*.sh; do
source "$f" || fail 1 "Failed to load $f"
done
debug "Working in $WORKDIR"
debug "Homedir is $HOME"
if [ ! -f "config.csv" ] || [ ! -f "sets.csv" ]; then
# TODO Create them
fail 1 "Configuration files do not exist"
fi
# NOTE ['name']='install location relative to $HOME'
declare -A CONFIGS
while IFS=";" read -r CFG DEST _; do
CONFIGS[$CFG]="$DEST"
done < config.csv
unset CFG DEST
# NOTE ['name']='list of keys of CONFIGS (or SETS; Beware of BRB)'
declare -A SETS
while IFS=";" read -r SET PKGS _; do
SETS[$SET]="$PKGS"
done < sets.csv
unset SET PKGS
# NOTE PKGS does NOT refer to system packages
# NOTE ['filename in sysconf']='Install location relative to /'
# NOTE This should also support Folders, of which all contents are mirrored to dest,
# but removal is not tracked
declare -A SYSCONFIGS
while IFS=";" read -r CFG DEST _; do
SYSCONFIGS[$CFG]="$DEST"
done < sysconf.csv
unset SET PKGS
if [ $# -eq 0 ]; then
print_help "$0"
exit 1
fi
CMD=$1
shift
case $CMD in
install)
if [ $# -gt 0 ]; then
selected=( "$@" )
else
selected=( $(multiselector "${!CONFIGS[@]}" "${!SETS[@]}" ) )
fi
for cnf in "${selected[@]}"; do
choose_target "$cnf"
done
call_hook housekeeping;;
hook)
call_hook "$1";;
add)
test -e "$1" || fail 1 "Target file not found: $1"
TARGET=$(realpath "--relative-to=$HOME" "$1")
NAME=$(basename "$TARGET")
RELPATH=$(dirname "$TARGET")
# NOTE: This does not check SETS. Could be a problem
test -n "${CONFIGS[$NAME]}" && fail 1 "An object with the same name is already managed."
cp -r "$1" ./ || fail 1 "Failed to copy configuration"
echo "$NAME;$RELPATH" >> config.csv
call_hook post_add "$NAME" "$TARGET"
echo "Config was installed successfully."
echo "It can now be installed with $0 install $NAME"
echo "The following files were changed: config.csv $NAME"
;;
sysconf)
if [ $# -gt 0 ]; then
if [ ! -z "${SYSCONFIGS[$1]}" ]; then
selected=( "$1" )
fi
else
selected=( $(multiselector "${!SYSCONFIGS[@]}" ) )
fi
for cnf in "${selected[@]}"; do
install_sysconf "$cnf" "${SYSCONFIGS[$cnf]}"
done
call_hook housekeeping;;
add_sysconf)
test -e "$1" || fail 1 "Target file not found: $1"
TARGET=$(realpath "$1")
NAME=$(basename "$TARGET")
test -n "${SYSCONFIGS[$NAME]}" && \
fail 1 "An object with the same name is already managed."
# TODO vlt. wollen wir im fall eines ordners diesen erstellen,
# anstatt den Inhalt zu kopieren
cp -r "$1" ./sysconf/ || fail 1 "Failed to copy configuration"
echo "$NAME;$TARGET" >> sysconf.csv
call_hook post_add_sysconf "$NAME" "$TARGET"
echo "Config was installed successfully."
echo "It can now be installed with $0 sysconf $NAME"
echo "The following files were changed: sysconf.csv $NAME"
;;
*)
echo Invalid command: "$CMD"
exit 1
;;
esac