This repository was archived by the owner on Feb 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·117 lines (100 loc) · 2.95 KB
/
install.sh
File metadata and controls
executable file
·117 lines (100 loc) · 2.95 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
set -euf
DOTFILES=$(dirname -- "$(readlink -f -- "$0")")
echo "DOTFILES = '$DOTFILES'"
unset CDPATH
cd "$DOTFILES" || exit 1
# find all links
links=()
while IFS='' read -r line ; do
links+=("$line")
done < <(find . -xtype l | awk '{ print length, $0 }' | sort -n | cut -d' ' -f2-)
# do mkdir for each link
for link in "${links[@]}" ; do
if [ ! -L "$link" ] ; then
>&2 echo "E [$0] '$link' is not of link type"
exit 1
fi
target=$(readlink -m -- "$link")
# skip existing targets
[ -e "$target" ] && continue
# check git ignore
[ -n "$(git check-ignore -v "$link")" ] && continue
# skip file targets (*.*)
if [[ $(basename -- "$target") = *.* ]] ; then
>&2 echo "I [$0] skip file link: '$link' -> '$target'"
continue
fi
# skip ext (outside $HOME) targets
[[ $target = $HOME/* ]] || continue
# mkdir (assume target should be directory)
mkdir -pv -- "$target"
done
# make links for targets (ln $DOTFILES/target $HOME/target)
targets=(
bin
.config
.var
.bashrc .zshrc
.profile
)
# create links that point to targets
for target in "${targets[@]}" ; do
link="$HOME/$target"
target="$DOTFILES/$target"
if [ ! -e "$target" ] ; then
>&2 echo "E [$0] target '$target' does not exist"
exit 1
fi
link_dir=$(dirname -- "$link")
# skip same links
if [ -L "$link" ] ; then
if command -v realpath &> /dev/null ; then
[ "$(readlink -- "$link")" = "$(realpath --relative-to="$link_dir" "$target")" ] && continue
else
[ "$(readlink -- "$link")" = "$target" ] && continue
fi
fi
# delete existing link
if [ -L "$link" ] ; then
>&2 echo "I [$0] link '$link -> $(readlink -- "$link")' exists"
while true ; do
read -r -p "Overwrite? [y,n,q,?] " sel
case "$sel" in
y) rm -fv -- "$link" ; break ;;
n) continue 2 ;;
q) exit 1 ;;
*) continue ;;
esac
done
elif [ -e "$link" ] ; then
>&2 echo "W [$0] file '$link' exists"
while true ; do
read -r -p "Overwrite? [y,n,q,?] " sel
case "$sel" in
y) rm -rfv -- "$link" ; break ;;
n) continue 2 ;;
q) exit 1 ;;
*) continue ;;
esac
done
fi
# make destination directory
if [ ! -d "$link_dir" ] ; then
mkdir -pv -- "$link_dir"
fi
if command -v realpath &> /dev/null ; then
# create relative link
target=$(realpath --relative-to="$link_dir" "$target")
ln -snv --relative -T "$target" "$link"
else
# create normal link
ln -snv -T "$target" "$link"
fi
done
# Media/MIME Types
make -C "$DOTFILES/.config/applications"
source .profile
while IFS='' read -r f ; do
[ -f "$f" ] && source "$f"
done < <(find "$DOTFILES/install.d/" -name '*.sh')