3 # install location and source files
4 : ${DEST:=$(realpath "$HOME")}
5 : ${SRC:=$(dirname "$(realpath "$0")")}
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}
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/}"
22 if [ "$1" = "test" ]; then
23 echo "Running test -- no changes will be applied"
27 echo "-- cd $* --> $PWD";
30 alias mkdir="echo -- mkdir"
37 # NOTE: copied from .zshenv
38 if [ -z "$OSTYPE" ]; then
39 OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]')
42 # accomodate multiple userlands
43 # XXX: assuming GNU by default
44 # TODO: test for GNU, fallback to POSIX instead (no -n)
47 freebsd*) lnargs=-sFhv;;
48 netbsd|openbsd*) lnargs=-sfhv;;
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"
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 '
66 [ "${r#'"$SRC"'/}" != "$r" ] &&
67 '"$([ "$1" = test ] && echo 'echo +++ ')"'unlink "{}"' \;
74 [ -L "$d" -o \! -e "$d" ] && ln $lnargs "$SRC/${2:-$x}" "$d" ||
75 echo "!!! File exists and is not a link: $1"
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
84 # xorg/wayland resources
85 find gui -mindepth 1 -maxdepth 1 | while read -r y; do
88 find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do
89 [ ! -e "$x/index.theme" ] && continue
90 command -v gtk-update-icon-cache >$devnull 2>&1 &&
91 gtk-update-icon-cache -f "$x"
92 l "$share${y#gui}/$(basename "$x")"
96 find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do
97 command -v mkfontscale >$devnull 2>&1 && mkfontscale "$x"
98 command -v mkfontdir >$devnull 2>&1 && mkfontdir "$x"
99 [ "$(head -1 "$x/fonts.scale" >$devnull 2>&1)" = 0 ] &&
101 [ "$(head -1 "$x/fonts.dir" >$devnull 2>&1)" = 0 ] &&
103 l "$share${y#gui}/$(basename "$x")"
107 find "$y" -mindepth 1 -maxdepth 1 | while read -r x; do
115 if command -v gpg >$devnull 2>&1; then
116 mkdir -pm 700 "$DEST/$etc/gnupg"
117 find gnupg -mindepth 1 -maxdepth 1 \! -name '*.gpg' | while read -r x; do
120 find gnupg -mindepth 1 -maxdepth 1 -name '*.gpg' | while read -r x; do
126 if command -v ssh >$devnull 2>&1; then
127 mkdir -pm 700 "$DEST/.ssh"
128 find ssh -mindepth 1 -maxdepth 1 | while read -r x; do
132 # termux, assume it if android
133 if [ $(uname -o) = 'Android' ]; then
134 mkdir -p "$DEST/.termux"
135 find termux -mindepth 1 -maxdepth 1 | while read -r x; do l ".$x"; done
136 l '.termux/font.ttf' "gui/fonts/Dina-ttf/Dina.ttf"