-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·97 lines (79 loc) · 1.83 KB
/
Copy pathinstall
File metadata and controls
executable file
·97 lines (79 loc) · 1.83 KB
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
#!/usr/bin/env bash
# install
#
# This is a script to install my dotfiles on a machine by symlinking
# everything into the right place in the home directory.
#
# ARGUMENTS
#
# - "rollback" - if passed as the first argument, we will remove all
# symlinks that have been created, uninstalling the dotfiles.
#
# ENVIRONMENT OPTIONS
#
# - `DEBUG=1` to dry run
#
# EXAMPLES
#
# Install all dotfiles into the home directory:
#
# ./install
#
#
# Uninstall everything that was previously symlinked:
#
# ./install rollback
#
#
# Do a dry run to see what commands the script would have run:
#
# DEBUG=1 ./install
set -uef -o pipefail
# --[ Configuration ]
# Set the "base" directory we should install dotfiles into. You can change this
# value to test the script without messing with a real home directory. Rather
# useful for debugging.
export BASE_DIR="$HOME"
# Set DEBUG=1 to echo all commands instead of running.
export DEBUG="${DEBUG:-}"
# --[ END Configuration ]
MKDIR="mkdir"
LN="ln"
RM="rm"
if [[ "${DEBUG:-}" != "" ]] ; then
# If we pass 'DEBUG=1' (value is irrelevant), we should prefix commands
# with 'echo' to do a dry run.
#
# These must respect the custom IFS set in `link_config`
MKDIR="echo mkdir"
LN="echo ln"
RM="echo rm"
fi
export MKDIR
export LN
export RM
export RECEIPT="./.receipt"
rollback() {
cat "$RECEIPT" | while read -r target ; do
$RM -f "$target"
done
[[ "$DEBUG" = "" ]] && echo > "$RECEIPT"
}
link_config() {
OLDIFS="$IFS"
IFS=" "
target="$2/${1#"$3/"}"
dirname="$(dirname "$target")"
if [ ! -e "$target" ] ; then
[[ ! -e "$dirname" ]] && $MKDIR -p "$dirname"
$LN -s "$PWD/$1" "$target"
echo "$target" >> "$RECEIPT"
fi
IFS="$OLDIFS"
}
export -f link_config
if [ "${1:-}" = "rollback" ] ; then
rollback
exit 0
fi
find configs -mindepth 1 -type f -exec bash -c 'link_config "$1" $BASE_DIR configs' _ {} \;