53 lines
1.4 KiB
Bash
Executable file
53 lines
1.4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
BASH_SRC="$REPO_DIR/.bashrc"
|
|
|
|
install_user() {
|
|
local target="$1"
|
|
if [ -z "$target" ]; then
|
|
target="~"
|
|
fi
|
|
if [ -f "$target/.bashrc" ] && [ ! -f "$target/.bashrc.bak" ]; then
|
|
cp "$target/.bashrc" "$target/.bashrc.bak"
|
|
echo "backup: $target/.bashrc -> $target/.bashrc.bak"
|
|
fi
|
|
cp "$BASH_SRC" "$target/.bashrc"
|
|
echo "installed: $target/.bashrc"
|
|
|
|
if command -v chsh >/dev/null 2>&1; then
|
|
local shell_path
|
|
shell_path="$(command -v bash)"
|
|
if [ "$SHELL" != "$shell_path" ]; then
|
|
echo "change default shell to $shell_path? [y/N]"
|
|
read -r ans
|
|
if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
|
|
chsh -s "$shell_path"
|
|
echo "default shell changed to bash"
|
|
fi
|
|
fi
|
|
fi
|
|
}
|
|
|
|
install_system() {
|
|
if [ ! -f /etc/skel/.bashrc.bak ] && [ -f /etc/skel/.bashrc ]; then
|
|
cp /etc/skel/.bashrc /etc/skel/.bashrc.bak
|
|
echo "backup: /etc/skel/.bashrc -> /etc/skel/.bashrc.bak"
|
|
fi
|
|
cp "$BASH_SRC" /etc/skel/.bashrc
|
|
echo "installed: /etc/skel/.bashrc"
|
|
}
|
|
|
|
case "${1:-user}" in
|
|
user)
|
|
install_user "${2:-$HOME}"
|
|
;;
|
|
system)
|
|
install_system
|
|
;;
|
|
*)
|
|
echo "usage: $0 [user|system] [target_dir]"
|
|
exit 1
|
|
;;
|
|
esac
|