]> git.sev.monster Git - dotfiles.git/blame - install.sh
zsh: dfu updates submodules too
[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
b63487b0 22if [ "${DOTFILES_TEST+x}" = x ]; then
d23b28eb 23 echo "Running test -- no changes will be applied"
24 devnull=/dev/stdout
25 _cd() {
398a3a5e 26 echo "-- cd $PWD --> $*";
abc62f2c 27 cd $*;
d23b28eb 28 }
29 alias cd="_cd"
30 alias mkdir="echo -- mkdir"
abc62f2c 31 alias rmdir="echo -- rmdir"
d23b28eb 32 alias ln="echo -- ln"
33 alias rm="echo -- rm"
abc62f2c 34 alias mv="echo -- mv"
d23b28eb 35 alias sh="echo -- sh"
7f359c8a 36fi
37
dcac60d9 38# ensure ostype
8d4a98e1 39# NOTE: copied from .zshenv
74024535 40if [ -z "$OSTYPE" ]; then
d23b28eb 41 OSTYPE=$(uname -s | tr '[:upper:]' '[:lower:]')
74024535 42fi
dcac60d9 43
44# accomodate multiple userlands
8d4a98e1 45# XXX: assuming GNU by default
46# TODO: test for GNU, fallback to POSIX instead (no -n)
dcac60d9 47lnargs=-sfnv
d877aef2 48case "$OSTYPE" in
d23b28eb 49 freebsd*) lnargs=-sFhv;;
50 netbsd|openbsd*) lnargs=-sfhv;;
cf9ecb6f 51esac
52
abc62f2c 53# save pwd
54old_pwd="$PWD"
55
8d4a98e1 56cd "$DEST"
57
58# create preferred folder structure
59mkdir -pm 760 "$share" "$etc" "$state" "$cache"
60ln $lnargs "$DEST/$etc" "$LOCAL/etc"
61mkdir -p "$LOCAL/bin" "$share/fonts" "$share/themes" "$share/icons"
62
63# clean out old links
64# TODO: doesn't remove dead links if realpath fails; this happens if the link
65# target doesn't exist under busybox
66find . "$share" "$etc" \
67 "$LOCAL/bin" "$share/fonts" "$share/themes" "$share/icons" \
68 "$etc/gnupg" .ssh .termux \
69 -xdev -mindepth 1 -maxdepth 1 -type l -exec sh -c '
70 r="$(realpath "{}")"
71 [ "${r#'"$SRC"'/}" != "$r" ] &&
b63487b0 72 '"$([ "${DOTFILES_TEST+x}" = x ] && echo 'echo +++ ')"'unlink "{}"' \;
8d4a98e1 73
74cd "$SRC" >$devnull
75
7f359c8a 76l() {
d23b28eb 77 # TODO: use install?
6d54344e 78 d="$DEST/${1:-$x}"
79 [ -L "$d" -o \! -e "$d" ] && ln $lnargs "$SRC/${2:-$x}" "$d" ||
d23b28eb 80 echo "!!! File exists and is not a link: $1"
7f359c8a 81}
82
d23b28eb 83# generic links
8d4a98e1 84find base -mindepth 1 -maxdepth 1 | while read -r x; do l "${x#base/}"; done
85find bin -mindepth 1 -maxdepth 1 | while read -r x; do l "$LOCAL/$x"; done
86find share -mindepth 1 -maxdepth 1 | while read -r x; do l "$share${x#share}"; done
87find etc -mindepth 1 -maxdepth 1 | while read -r x; do l "$etc${x#etc}"; done
d23b28eb 88
89# xorg/wayland resources
6d54344e 90find gui -mindepth 1 -maxdepth 1 | while read -r y; do
91 case "${y#gui/}" in
92 icons|themes)
93 find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do
94 [ ! -e "$x/index.theme" ] && continue
a2a81fa8 95 command -v gtk-update-icon-cache >$devnull 2>&1 &&
6d54344e 96 gtk-update-icon-cache -f "$x"
8d4a98e1 97 l "$share${y#gui}/$(basename "$x")"
6d54344e 98 done
99 ;;
100 fonts)
101 find "$y" -mindepth 1 -maxdepth 2 -type d | while read -r x; do
a2a81fa8 102 command -v mkfontscale >$devnull 2>&1 && mkfontscale "$x"
103 command -v mkfontdir >$devnull 2>&1 && mkfontdir "$x"
6d54344e 104 [ "$(head -1 "$x/fonts.scale" >$devnull 2>&1)" = 0 ] &&
105 rm "$x/fonts.scale"
106 [ "$(head -1 "$x/fonts.dir" >$devnull 2>&1)" = 0 ] &&
107 rm "$x/fonts.dir"
8d4a98e1 108 l "$share${y#gui}/$(basename "$x")"
6d54344e 109 done
110 ;;
111 *)
112 find "$y" -mindepth 1 -maxdepth 1 | while read -r x; do
8d4a98e1 113 l "$share${x#gui}"
6d54344e 114 done
115 ;;
116 esac
ff1a2414 117done
d23b28eb 118
119# gpg
a2a81fa8 120if command -v gpg >$devnull 2>&1; then
8d4a98e1 121 mkdir -pm 700 "$DEST/$etc/gnupg"
d23b28eb 122 find gnupg -mindepth 1 -maxdepth 1 \! -name '*.gpg' | while read -r x; do
8d4a98e1 123 l "$etc/$x"
d23b28eb 124 done
125 find gnupg -mindepth 1 -maxdepth 1 -name '*.gpg' | while read -r x; do
126 gpg --import "$x"
127 done
372276b7 128fi
d23b28eb 129
130# ssh
45662d3c 131if command -v ssh >$devnull 2>&1; then
132 mkdir -pm 700 "$DEST/.ssh"
133 find ssh -mindepth 1 -maxdepth 1 | while read -r x; do
54b4032b 134 l ".$x"
135 done
136fi
137
138# librewolf
139if command -v librewolf >$devnull 2>&1; then
ed157589 140 # XXX: MOZ_USER_DIR is compiletime, can't move to .config :(
141 mkdir -p "$DEST/.librewolf"
54b4032b 142 find librewolf -mindepth 1 -maxdepth 1 -type f | while read -r x; do
143 l ".$x"
144 done
ed157589 145 profiles="$DEST/.librewolf/profiles.ini"
146 if [ -f "$profiles" ]; then
147 find librewolf/chrome -mindepth 1 -maxdepth 1 -type f | while read -r x; do
148 # vv arcane bullshit vv
0b6d64fd 149 sed -En 's/^Path=(.+)/\1/;T;p' "$profiles" | while read -r y; do
ed157589 150 # ignore profiles that are most likely unused
151 # TODO: actually check profiles.ini
152 profile="$DEST/.librewolf/$y"
153 [ -d "$profile" -a -f "$profile/prefs.js" ] || continue
154 mkdir -p "$profile/chrome"
155 l "${profile#$DEST/}/chrome/${x#librewolf/chrome/}"
156 done
157 done
158 fi
45662d3c 159fi
d23b28eb 160
161# termux, assume it if android
162if [ $(uname -o) = 'Android' ]; then
163 mkdir -p "$DEST/.termux"
8d4a98e1 164 find termux -mindepth 1 -maxdepth 1 | while read -r x; do l ".$x"; done
ea963a90 165 l '.termux/font.ttf' "gui/fonts/Dina-ttf/Dina.ttf"
d23b28eb 166fi
abc62f2c 167
168cd "$DEST" >$devnull
169
170# ensure xdg user dirs, and move old to new while we're at it
3cfa9e5d 171. $etc/user-dirs.dirs
172fixup_xdg_home() {
abc62f2c 173 if [ -z "$1" -o "${1#/}" = "$1" -o "$(realpath "$1")" = "$(realpath "$HOME")" ]; then
174 return;
175 fi
176 mkdir -p "$1"
177 if [ $? -eq 0 -a -n "$2" -a -d "$2" ]; then
178 mv "$2"/* $1
179 rmdir "$2"
180 fi
181}
3cfa9e5d 182fixup_xdg_home "$XDG_DESKTOP_DIR" Desktop
183fixup_xdg_home "$XDG_DOWNLOAD_DIR" Downloads
184fixup_xdg_home "$XDG_TEMPLATES_DIR"
185fixup_xdg_home "$XDG_PUBLICSHARE_DIR" Public
186fixup_xdg_home "$XDG_DOCUMENTS_DIR" Documents
187fixup_xdg_home "$XDG_MUSIC_DIR" Music
188fixup_xdg_home "$XDG_PICTURES_DIR" Pictures
189fixup_xdg_home "$XDG_VIDEOS_DIR" Videos
abc62f2c 190
191cd "$old_pwd"
This page took 0.071448 seconds and 4 git commands to generate.