]>
Commit | Line | Data |
---|---|---|
189288f7 | 1 | #!/bin/sh |
d9362f34 | 2 | |
b341b38a | 3 | # install location and source files |
2ec9d552 | 4 | : ${DEST:=$(realpath "$HOME")} |
5 | : ${SRC:=$(dirname "$(realpath "$0")")} | |
6 | ||
b341b38a | 7 | # confirm XDG vars we care about are set up |
8 | : ${LOCAL:=.local} # NOTE: needed for bin, which has no xdg var | |
9 | : ${XDG_DATA_HOME:=$DEST/$LOCAL/share} | |
10 | : ${XDG_CONFIG_HOME:=$DEST/.config} | |
11 | : ${XDG_STATE_HOME:=$DEST/$LOCAL/state} | |
12 | : ${XDG_CACHE_HOME:=$DEST/.cache} | |
13 | ||
14 | # these are the vars we actually use | |
15 | share="${XDG_DATA_HOME#$DEST/}" | |
16 | etc="${XDG_CONFIG_HOME#$DEST/}" | |
17 | state="${XDG_STATE_HOME#$DEST/}" | |
18 | cache="${XDG_CACHE_HOME#$DEST/}" | |
19 | ||
1f8bf106 | 20 | # test |
f993e922 | 21 | devnull=/dev/null |
7197cc5c | 22 | if [ "$1" = "test" ]; then |
2ec9d552 | 23 | echo "Running test -- no changes will be applied" |
24 | devnull=/dev/stdout | |
25 | _cd() { | |
26 | cd $*; | |
b341b38a | 27 | echo "-- cd $* --> $PWD"; |
2ec9d552 | 28 | } |
29 | alias cd="_cd" | |
30 | alias mkdir="echo -- mkdir" | |
31 | alias ln="echo -- ln" | |
32 | alias rm="echo -- rm" | |
33 | alias sh="echo -- sh" | |
9938f1e2 | 34 | fi |
35 | ||
a568f7fa | 36 | # ensure ostype |
b341b38a | 37 | # NOTE: copied from .zshenv |
3daa445f | 38 | if [ -z "$OSTYPE" ]; then |
2ec9d552 | 39 | OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]') |
3daa445f | 40 | fi |
a568f7fa | 41 | |
42 | # accomodate multiple userlands | |
b341b38a | 43 | # XXX: assuming GNU by default |
44 | # TODO: test for GNU, fallback to POSIX instead (no -n) | |
a568f7fa | 45 | lnargs=-sfnv |
ba63cd01 | 46 | case "$OSTYPE" in |
2ec9d552 | 47 | freebsd*) lnargs=-sFhv;; |
48 | netbsd|openbsd*) lnargs=-sfhv;; | |
138de127 | 49 | esac |
50 | ||
b341b38a | 51 | cd "$DEST" |
52 | ||
53 | # create preferred folder structure | |
54 | mkdir -pm 760 "$share" "$etc" "$state" "$cache" | |
55 | ln $lnargs "$DEST/$etc" "$LOCAL/etc" | |
56 | mkdir -p "$LOCAL/bin" "$share/fonts" "$share/themes" "$share/icons" | |
57 | ||
58 | # clean out old links | |
59 | # TODO: doesn't remove dead links if realpath fails; this happens if the link | |
60 | # target doesn't exist under busybox | |
61 | find . "$share" "$etc" \ | |
62 | "$LOCAL/bin" "$share/fonts" "$share/themes" "$share/icons" \ | |
63 | "$etc/gnupg" .ssh .termux \ | |
64 | -xdev -mindepth 1 -maxdepth 1 -type l -exec sh -c ' | |
65 | r="$(realpath "{}")" | |
66 | [ "${r#'"$SRC"'/}" != "$r" ] && | |
67 | '"$([ "$1" = test ] && echo 'echo +++ ')"'unlink "{}"' \; | |
68 | ||
69 | cd "$SRC" >$devnull | |
70 | ||
9938f1e2 | 71 | l() { |
2ec9d552 | 72 | # TODO: use install? |
e4677c6b | 73 | d="$DEST/${1:-$x}" |
74 | [ -L "$d" -o \! -e "$d" ] && ln $lnargs "$SRC/${2:-$x}" "$d" || | |
2ec9d552 | 75 | echo "!!! File exists and is not a link: $1" |
9938f1e2 | 76 | } |
77 | ||
2ec9d552 | 78 | # generic links |
b341b38a | 79 | find base -mindepth 1 -maxdepth 1 | while read -r x; do l "${x#base/}"; done |
80 | find bin -mindepth 1 -maxdepth 1 | while read -r x; do l "$LOCAL/$x"; done | |
81 | find share -mindepth 1 -maxdepth 1 | while read -r x; do l "$share${x#share}"; done | |
82 | find etc -mindepth 1 -maxdepth 1 | while read -r x; do l "$etc${x#etc}"; done | |
2ec9d552 | 83 | |
84 | # xorg/wayland resources | |
e4677c6b | 85 | find gui -mindepth 1 -maxdepth 1 | while read -r y; do |
86 | case "${y#gui/}" in | |
87 | icons|themes) | |
88 | find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do | |
89 | [ ! -e "$x/index.theme" ] && continue | |
ce09f45e | 90 | command -v gtk-update-icon-cache >$devnull 2>&1 && |
e4677c6b | 91 | gtk-update-icon-cache -f "$x" |
b341b38a | 92 | l "$share${y#gui}/$(basename "$x")" |
e4677c6b | 93 | done |
94 | ;; | |
95 | fonts) | |
96 | find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do | |
ce09f45e | 97 | command -v mkfontscale >$devnull 2>&1 && mkfontscale "$x" |
98 | command -v mkfontdir >$devnull 2>&1 && mkfontdir "$x" | |
e4677c6b | 99 | [ "$(head -1 "$x/fonts.scale" >$devnull 2>&1)" = 0 ] && |
100 | rm "$x/fonts.scale" | |
101 | [ "$(head -1 "$x/fonts.dir" >$devnull 2>&1)" = 0 ] && | |
102 | rm "$x/fonts.dir" | |
b341b38a | 103 | l "$share${y#gui}/$(basename "$x")" |
e4677c6b | 104 | done |
105 | ;; | |
106 | *) | |
107 | find "$y" -mindepth 1 -maxdepth 1 | while read -r x; do | |
b341b38a | 108 | l "$share${x#gui}" |
e4677c6b | 109 | done |
110 | ;; | |
111 | esac | |
f7960c69 | 112 | done |
2ec9d552 | 113 | |
114 | # gpg | |
ce09f45e | 115 | if command -v gpg >$devnull 2>&1; then |
b341b38a | 116 | mkdir -pm 700 "$DEST/$etc/gnupg" |
2ec9d552 | 117 | find gnupg -mindepth 1 -maxdepth 1 \! -name '*.gpg' | while read -r x; do |
b341b38a | 118 | l "$etc/$x" |
2ec9d552 | 119 | done |
120 | find gnupg -mindepth 1 -maxdepth 1 -name '*.gpg' | while read -r x; do | |
121 | gpg --import "$x" | |
122 | done | |
bf314d35 | 123 | fi |
2ec9d552 | 124 | |
125 | # ssh | |
126 | find ssh -mindepth 1 -maxdepth 1 | while read -r x; do | |
127 | l ".$x"; done | |
128 | ||
129 | # termux, assume it if android | |
130 | if [ $(uname -o) = 'Android' ]; then | |
131 | mkdir -p "$DEST/.termux" | |
b341b38a | 132 | find termux -mindepth 1 -maxdepth 1 | while read -r x; do l ".$x"; done |
133 | l '.termux/font.ttf' "$share/fonts/Dina-ttf/Dina.ttf" | |
2ec9d552 | 134 | fi |
135 | ||
136 | # vim: sts=4 sw=4 et |