-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall
More file actions
executable file
·66 lines (53 loc) · 1.85 KB
/
install
File metadata and controls
executable file
·66 lines (53 loc) · 1.85 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
#!/bin/sh
# Helper to install symlinks to `src` directory.
# Remove any existing file/symlink at $2, then symlink $2 -> $1.
install_symlink() {
echo "Symlinking: $2 -> $1"
rm -rf "$2"
ln -s "$1" "$2"
}
# Directories whose *contents* are symlinked individually into the corresponding ~/dir/ rather than
# symlinking the directory itself. This is needed for `.config` where AppArmor allows `~/.config`
# but doesn't follow symlinks to it.
EXPAND_DIRS=".config"
# Ensure current directory is the script location.
cd "`dirname "$0"`"
for path in ./src/.* ./src/*; do
# Get filename and ignore "." and "..".
fn=$(basename $path)
if [ $fn = "." ] || [ $fn = ".." ]; then continue; fi;
src_file="`pwd`/src/$fn"
# Check whether this entry should be expanded entry-by-entry.
expand=0
for expand_dir in $EXPAND_DIRS; do
if [ "$fn" = "$expand_dir" ]; then
expand=1
break
fi
done
if [ $expand -eq 1 ]; then
# Symlink each item inside the directory into ~/fn/.
home_dir=~/$fn
# If the target exists as a symlink (e.g. from a previous install), remove it.
if [ -L "$home_dir" ]; then
echo "Found existing symlink!"
echo "Removing: $home_dir symlink"
rm -rf "$home_dir"
# Print a warning that the user should move existing files out of the dotfiles tree and then
# re-execute this script.
echo "WARNING: Move any untracked files out of the dotfiles tree and re-run this script."
exit 1
fi
mkdir -p "$home_dir"
for entry_path in "$src_file"/.* "$src_file"/*; do
entry=$(basename "$entry_path")
if [ "$entry" = "." ] || [ "$entry" = ".." ]; then continue; fi;
home_entry="$home_dir/$entry"
install_symlink "$entry_path" "$home_entry"
done
else
home_file=~/$fn
# Remove and symlink the file.
install_symlink "$src_file" "$home_file"
fi
done