]>
Commit | Line | Data |
---|---|---|
1b8a4102 | 1 | #!/bin/sh |
03bc64c4 | 2 | |
8d4a98e1 | 3 | # install location and source files |
d23b28eb | 4 | : ${DEST:=$(realpath "$HOME")} |
5 | : ${SRC:=$(dirname "$(realpath "$0")")} | |
6 | ||
8d4a98e1 | 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 | ||
84251d17 | 20 | # test |
fef7b7c4 | 21 | devnull=/dev/null |
8720834f | 22 | if [ "$1" = "test" ]; then |
d23b28eb | 23 | echo "Running test -- no changes will be applied" |
24 | devnull=/dev/stdout | |
25 | _cd() { | |
26 | cd $*; | |
8d4a98e1 | 27 | echo "-- cd $* --> $PWD"; |
d23b28eb | 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" | |
7f359c8a | 34 | fi |
35 | ||
dcac60d9 | 36 | # ensure ostype |
8d4a98e1 | 37 | # NOTE: copied from .zshenv |
74024535 | 38 | if [ -z "$OSTYPE" ]; then |
d23b28eb | 39 | OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]') |
74024535 | 40 | fi |
dcac60d9 | 41 | |
42 | # accomodate multiple userlands | |
8d4a98e1 | 43 | # XXX: assuming GNU by default |
44 | # TODO: test for GNU, fallback to POSIX instead (no -n) | |
dcac60d9 | 45 | lnargs=-sfnv |
d877aef2 | 46 | case "$OSTYPE" in |
d23b28eb | 47 | freebsd*) lnargs=-sFhv;; |
48 | netbsd|openbsd*) lnargs=-sfhv;; | |
cf9ecb6f | 49 | esac |
50 | ||
8d4a98e1 | 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 | ||
7f359c8a | 71 | l() { |
d23b28eb | 72 | # TODO: use install? |
6d54344e | 73 | d="$DEST/${1:-$x}" |
74 | [ -L "$d" -o \! -e "$d" ] && ln $lnargs "$SRC/${2:-$x}" "$d" || | |
d23b28eb | 75 | echo "!!! File exists and is not a link: $1" |
7f359c8a | 76 | } |
77 | ||
d23b28eb | 78 | # generic links |
8d4a98e1 | 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 | |
d23b28eb | 83 | |
84 | # xorg/wayland resources | |
6d54344e | 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 | |
a2a81fa8 | 90 | command -v gtk-update-icon-cache >$devnull 2>&1 && |
6d54344e | 91 | gtk-update-icon-cache -f "$x" |
8d4a98e1 | 92 | l "$share${y#gui}/$(basename "$x")" |
6d54344e | 93 | done |
94 | ;; | |
95 | fonts) | |
96 | find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do | |
a2a81fa8 | 97 | command -v mkfontscale >$devnull 2>&1 && mkfontscale "$x" |
98 | command -v mkfontdir >$devnull 2>&1 && mkfontdir "$x" | |
6d54344e | 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" | |
8d4a98e1 | 103 | l "$share${y#gui}/$(basename "$x")" |
6d54344e | 104 | done |
105 | ;; | |
106 | *) | |
107 | find "$y" -mindepth 1 -maxdepth 1 | while read -r x; do | |
8d4a98e1 | 108 | l "$share${x#gui}" |
6d54344e | 109 | done |
110 | ;; | |
111 | esac | |
ff1a2414 | 112 | done |
d23b28eb | 113 | |
114 | # gpg | |
a2a81fa8 | 115 | if command -v gpg >$devnull 2>&1; then |
8d4a98e1 | 116 | mkdir -pm 700 "$DEST/$etc/gnupg" |
d23b28eb | 117 | find gnupg -mindepth 1 -maxdepth 1 \! -name '*.gpg' | while read -r x; do |
8d4a98e1 | 118 | l "$etc/$x" |
d23b28eb | 119 | done |
120 | find gnupg -mindepth 1 -maxdepth 1 -name '*.gpg' | while read -r x; do | |
121 | gpg --import "$x" | |
122 | done | |
372276b7 | 123 | fi |
d23b28eb | 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" | |
8d4a98e1 | 132 | find termux -mindepth 1 -maxdepth 1 | while read -r x; do l ".$x"; done |
ea963a90 | 133 | l '.termux/font.ttf' "gui/fonts/Dina-ttf/Dina.ttf" |
d23b28eb | 134 | fi |