1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 09:53:22 -07:00
rc/install
2015-03-06 07:14:33 -08:00

75 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
note() {
echo -E "$@"
}
die() {
echo -E "$@">&2
exit 1
}
dotless() {
[[ "${1:0:1}" == "." ]] && REPLY="${1:1}" || REPLY="$1"
}
hardlink() {
[ -e "$1" ] && {
[ "$1" -ef "$2" ] && return
[ -h "$1" ] && note "removing symbolic link $1" && rm "$1"
[ -s "$1" ] && die "$1 already exists" || rm "$1"
}
ln "$2" "$1" || die "couldn't hardlink $1"
}
softlink() {
[ -e "$1" ] && {
[ -h "$1" ] && {
[ "$(readlink "$1")" == "$2" ] && return
note "removing symbolic link $1"
rm "$1"
} || die "$1 already exists and is not a symbolic link"
}
ln -s "$2" "$1" || die "couldn't symlink $1"
}
which readlink >/dev/null || exit 1
rc="$(readlink -f "$(dirname "$0")" )"
cd "$HOME"
PATH="${PATH:?No existing PATH}:$rc/sh"
umask 027
for f in .bashrc .zshrc .-shrc .vimrc .conkyrc \
.inputrc .screenrc .xinitrc .indent.pro .uncrustify.cfg; do
dotless "$f"
r="$rc/home/$REPLY"
hardlink "$f" "$r"
done
for d in sh .vim .mpv; do
dotless "$d"
r="$rc/$REPLY"
softlink "$d" "$r"
done
for d in ssh; do
mkdir -p ".$d"
for r in $rc/$d/*; do
f=".${r#"$rc/"}"
hardlink "$f" "$r"
done
done
grep .bashrc .bash_profile >/dev/null 2>&1 \
|| echo -e '\n[[ -f ~/.bashrc ]] && . ~/.bashrc' >> .bash_profile
for d in Desktop Documents Downloads Music Pictures Public Templates Video; do
[ -d "$d" ] || continue
is_empty "$d" && rm -r "$d" || note "skipping unempty $d"
done
mkdir -p opt/local/bin src work play