]> git.sev.monster Git - dotfiles.git/blame - install.sh
install.sh: install ssh conditionally, ensure dir
[dotfiles.git] / install.sh
CommitLineData
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
15share="${XDG_DATA_HOME#$DEST/}"
16etc="${XDG_CONFIG_HOME#$DEST/}"
17state="${XDG_STATE_HOME#$DEST/}"
18cache="${XDG_CACHE_HOME#$DEST/}"
19
84251d17 20# test
fef7b7c4 21devnull=/dev/null
8720834f 22if [ "$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 34fi
35
dcac60d9 36# ensure ostype
8d4a98e1 37# NOTE: copied from .zshenv
74024535 38if [ -z "$OSTYPE" ]; then
d23b28eb 39 OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]')
74024535 40fi
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 45lnargs=-sfnv
d877aef2 46case "$OSTYPE" in
d23b28eb 47 freebsd*) lnargs=-sFhv;;
48 netbsd|openbsd*) lnargs=-sfhv;;
cf9ecb6f 49esac
50
8d4a98e1 51cd "$DEST"
52
53# create preferred folder structure
54mkdir -pm 760 "$share" "$etc" "$state" "$cache"
55ln $lnargs "$DEST/$etc" "$LOCAL/etc"
56mkdir -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
61find . "$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
69cd "$SRC" >$devnull
70
7f359c8a 71l() {
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 79find base -mindepth 1 -maxdepth 1 | while read -r x; do l "${x#base/}"; done
80find bin -mindepth 1 -maxdepth 1 | while read -r x; do l "$LOCAL/$x"; done
81find share -mindepth 1 -maxdepth 1 | while read -r x; do l "$share${x#share}"; done
82find etc -mindepth 1 -maxdepth 1 | while read -r x; do l "$etc${x#etc}"; done
d23b28eb 83
84# xorg/wayland resources
6d54344e 85find 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 112done
d23b28eb 113
114# gpg
a2a81fa8 115if 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 123fi
d23b28eb 124
125# ssh
45662d3c 126if 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
129 l ".$x"; done
130fi
d23b28eb 131
132# termux, assume it if android
133if [ $(uname -o) = 'Android' ]; then
134 mkdir -p "$DEST/.termux"
8d4a98e1 135 find termux -mindepth 1 -maxdepth 1 | while read -r x; do l ".$x"; done
ea963a90 136 l '.termux/font.ttf' "gui/fonts/Dina-ttf/Dina.ttf"
d23b28eb 137fi
This page took 0.05859 seconds and 4 git commands to generate.