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

78 lines
1.7 KiB
Text
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
}
2015-03-13 13:04:17 -07:00
backup() {
note "backing up $1"
mkdir -p "${backup_dir:?backup_dir unset}/$(dirname "$1")"
[ -e "$backup_dir/$1" ] && die "backup already exists"
mv "$1" "$backup_dir/$1"
}
2013-06-28 05:22:14 -07:00
hardlink() {
2015-03-13 13:04:17 -07:00
if [ -e "$1" ]; then
2013-06-28 05:22:14 -07:00
[ "$1" -ef "$2" ] && return
2013-11-01 20:36:36 -07:00
[ -h "$1" ] && note "removing symbolic link $1" && rm "$1"
2015-03-13 13:04:17 -07:00
if [ -s "$1" ]; then
backup "$1" || die "$1 already exists"
fi
fi
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() {
2015-03-13 13:04:17 -07:00
if [ -e "$1" ]; then
if [ -h "$1" ]; then
2013-06-28 05:22:14 -07:00
[ "$(readlink "$1")" == "$2" ] && return
note "removing symbolic link $1"
2013-11-01 20:36:36 -07:00
rm "$1"
2015-03-13 13:04:17 -07:00
else
die "$1 already exists and is not a symbolic link"
fi
fi
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
2015-03-13 13:04:17 -07:00
backup_dir="$rc/backup-$(date '+%s')"
2013-06-28 05:22:14 -07:00
2015-12-11 01:06:01 -08:00
for f in .bashrc .zshrc .-shrc .streamcrap .vimrc \
2016-01-08 08:30:02 -08:00
.inputrc .Xresources .screenrc .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-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
2015-04-01 22:15:46 -07:00
for d in Desktop Documents Downloads Music Pictures Public Templates Video Videos; do
2013-06-28 05:22:14 -07:00
[ -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