-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
executable file
·64 lines (59 loc) · 1.66 KB
/
bootstrap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env sh
#
# bootstrap.sh
# This script bootstraps the setup of a new machine. It checks
# if the necessary dependencies are installed and installs them
# if needed. After that, it runs the dotfiles script with --install.
#
set -o errexit
set -o nounset
#set -o xtrace
# set `magic` variable to the directory of the script
__dir="$(cd "$(dirname "$0")" && pwd)"
__file="${__dir}/$(basename "$0")"
__base="$(basename ${__file})"
__root="$(cd "$(dirname "${__dir}")" && pwd)"
install_zsh() {
dist=$(uname -s)
local uid=$(id -u)
if [ "$dist" = "Linux" ]; then
if [ -f /etc/os-release ]; then
local v=$(cat /etc/os-release | grep -i -e "^id=" | sed -r "s/^id=(.+)/\1/i")
if [ "$v" = "debian" ] || [ "$v" = "ubuntu" ]; then
cmd="apt-get -y install zsh"
[ $uid -gt 0 ] && cmd="sudo $cmd"
$cmd
elif [ "$v" = "arch" ]; then
cmd="pacman -S zsh"
[ $uid -gt 0 ] && cmd="sudo $cmd"
cmd
else
echo "linux variant not supported: $v" && exit 1
fi
else
echo "not supported" && exit 1
fi
fi
echo ""
zsh=$(command -v zsh)
echo "Setting 'zsh' as login shell, enter your"
echo "password when prompted"
if [ $uid -eq 0 ]; then
chsh -s "$zsh" $SUDO_USER || exit 1
else
chsh -s "$zsh" || exit 1
fi
echo ""
echo "You need to logout and login again or reboot and call this script again:"
echo "$__file"
exit 0
}
echo ""
if [ "$(expr "$SHELL" : '.*/\(.*\)')" = "zsh" ]; then
zsh "$__dir/dotfiles install"
else
echo "'zsh' is not your default shell, these dotfiles are build on zsh."
read -p "Install 'zsh' and call \`chsh /usr/bin/zsh\` now [Y/n]" a
[ "$a" = "" ] && a=y
[ "$a" = "y" ] || [ "$a" = "Y" ] && install_zsh || exit 0
fi