1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 02:29:06 -08:00
rc/install.sh

69 lines
1.5 KiB
Bash
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() {
[[ "${1:0:1}" == "." ]] && echo -E "${1:1}" || echo -E "$1"
}
hardlink() {
[ -e "$1" ] && {
[ "$1" -ef "$2" ] && return
[ -h "$1" ] && note "removing symbolic link $1" && echo rm "$1"
2013-06-29 09:52:14 -07:00
[ -s "$1" ] && die "$1 already exists" || echo 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"
echo 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
}
rc="$(readlink -f "$(dirname "$0")" )"
cd $HOME
PATH="$PATH:$rc/sh"
umask 027
2013-07-03 15:03:54 -07:00
for f in .bashrc .zshrc shrc.zsh mingw.sh .vimrc .conkyrc .inputrc .screenrc .xinitrc; do
2013-07-05 11:07:46 -07:00
r="$rc/home/$(dotless "$f")"
2013-06-28 05:22:14 -07:00
hardlink "$f" "$r"
done
for d in sh .vim .mpv; do
r="$rc/$(dotless "$d")"
softlink "$d" "$r"
done
# FIXME: this loop is pretty inefficient
for r in $rc/ssh/* $rc/config/menus/*; do
f=".${r#"$rc/"}"
mkdir -p "$(dirname "$f")"
hardlink "$f" "$r"
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
is_empty "$d" && echo rm -r "$d" || note "skipping unempty $d"
done
mkdir -p opt/local/bin src work play