1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-01 15:33:07 -07:00
rc/install

75 lines
1.5 KiB
Plaintext
Raw Normal View History

2013-06-28 05:22:14 -07:00
#!/usr/bin/env bash
note() {
echo -E "$@"
}
2013-06-29 09:52:14 -07:00
die() {
2013-06-28 05:22:14 -07:00
echo -E "$@">&2
exit 1
}
dotless() {
2013-07-09 15:10:54 -07:00
[[ "${1:0:1}" == "." ]] && REPLY="${1:1}" || REPLY="$1"
2013-06-28 05:22:14 -07:00
}
hardlink() {
[ -e "$1" ] && {
[ "$1" -ef "$2" ] && return
2013-11-01 20:36:36 -07:00
[ -h "$1" ] && note "removing symbolic link $1" && rm "$1"
[ -s "$1" ] && die "$1 already exists" || rm "$1"
2013-06-28 05:22:14 -07:00
}
2013-06-29 09:52:14 -07:00
ln "$2" "$1" || die "couldn't hardlink $1"
2013-06-28 05:22:14 -07:00
}
softlink() {
[ -e "$1" ] && {
[ -h "$1" ] && {
[ "$(readlink "$1")" == "$2" ] && return
note "removing symbolic link $1"
2013-11-01 20:36:36 -07:00
rm "$1"
2013-06-29 09:52:14 -07:00
} || die "$1 already exists and is not a symbolic link"
2013-06-28 05:22:14 -07:00
}
2013-06-29 09:52:14 -07:00
ln -s "$2" "$1" || die "couldn't symlink $1"
2013-06-28 05:22:14 -07:00
}
2014-02-14 08:05:48 -08:00
which readlink >/dev/null || exit 1
2013-06-28 05:22:14 -07:00
rc="$(readlink -f "$(dirname "$0")" )"
2013-11-01 20:36:36 -07:00
cd "$HOME"
2013-07-09 15:10:54 -07:00
PATH="${PATH:?No existing PATH}:$rc/sh"
2013-06-28 05:22:14 -07:00
umask 027
2015-03-06 07:14:33 -08:00
for f in .bashrc .zshrc .-shrc .vimrc .conkyrc \
.inputrc .screenrc .xinitrc .indent.pro .uncrustify.cfg; do
2013-07-09 15:10:54 -07:00
dotless "$f"
r="$rc/home/$REPLY"
2013-06-28 05:22:14 -07:00
hardlink "$f" "$r"
done
for d in sh .vim .mpv; do
2013-07-09 15:10:54 -07:00
dotless "$d"
r="$rc/$REPLY"
2013-06-28 05:22:14 -07:00
softlink "$d" "$r"
done
2013-11-12 21:49:39 -08:00
for d in ssh; do
2013-07-09 15:10:54 -07:00
mkdir -p ".$d"
for r in $rc/$d/*; do
f=".${r#"$rc/"}"
hardlink "$f" "$r"
done
2013-06-28 05:22:14 -07:00
done
2013-07-01 18:05:17 -07:00
grep .bashrc .bash_profile >/dev/null 2>&1 \
|| echo -e '\n[[ -f ~/.bashrc ]] && . ~/.bashrc' >> .bash_profile
2013-06-28 05:22:14 -07:00
for d in Desktop Documents Downloads Music Pictures Public Templates Video; do
[ -d "$d" ] || continue
2013-09-15 18:41:18 -07:00
is_empty "$d" && rm -r "$d" || note "skipping unempty $d"
2013-06-28 05:22:14 -07:00
done
mkdir -p opt/local/bin src work play