-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·123 lines (104 loc) · 4.21 KB
/
setup.sh
File metadata and controls
executable file
·123 lines (104 loc) · 4.21 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
# Color variables
GREEN="\033[0;32m"
RED="\033[0;33m"
RESET="\033[0;0m"
ALL_PLUGINS=(zsh-completions zsh-syntax-highlighting zsh-autosuggestions)
PACKAGES=("git curl zsh wget fzf lsd bat")
SCRIPT_DIR=$(pwd)
# Check sudo
test -f "/usr/bin/sudo" || eval " echo -e "[-] sudo not installed ! log as root and install it !" && exit 1"
# RED_HAT
test -f "/usr/bin/dnf" || test -f "/usr/bin/yum" && USER_DISTRO=RED_HAT
grep -iq "redhat" /etc/os-release && echo -e "["$GREEN"+"$RESET"] RedHat like OS\n"
USER_DISTRO="RED_HAT"
# Debian
test -f "/usr/bin/dnf" || test -f "/usr/bin/apt-get" && USER_DISTRO=DEBIAN
grep -iq "debian" /etc/os-release && echo -e "["$GREEN"+"$RESET"] Debian like OS\n" && USER_DISTRO="DEBIAN"
# Arch
test -f "/usr/bin/pacman" && USER_DISTRO=Arch
grep -iq "arch" /etc/os-release && echo -e "["$GREEN"+"$RESET"] Arch like OS\n" && USER_DISTRO="Arch"
case "$USER_DISTRO" in
DEBIAN)
echo -e "["$GREEN"+"$RESET"] Check Packages ..."
for package in ${PACKAGES[@]}; do
apt show $package 2>/dev/null | grep -i "APT-Manual-Installed: yes" >/dev/null
if [[ $? -eq "0" ]]; then
echo -e "["$GREEN"+"$RESET"] $package installed\n"
else
echo -e "["$RED"-"$RESET"] $package not installed"
echo -e "[*] Try to install $package"
sudo apt-get -qq install $package -y 2>/dev/null && echo -e "["$GREEN"+"$RESET"] $package installed\n"
fi
done
;;
RED_HAT)
echo -e "[$GREEN+$RESET] Check Packages ..."
for package in ${PACKAGES[@]}; do
rpm --query $package >/dev/null
if [[ $? -eq "0" ]]; then
echo -e "[$GREEN+$RESET] $package installed"
else
echo -e "[$RED-$RESET] "$package" not installed\n Install it ..."
sudo dnf install --quiet "$package" -y
fi
done
;;
Arch)
echo -e "["$GREEN"+"$RESET"] Check Packages ..."
for package in ${PACKAGES[@]}; do
pacman -Q $package >/dev/null
if [[ $? -eq "0" ]]; then
echo -e "["$GREEN"+"$RESET"] $package installed"
else
echo -e "[$RED-$RESET] "$package" not installed"
echo -e "[$GREEN+$RESET] Try to install "$package""
sudo pacman -Syu "$package"
fi
done
;;
esac
# Change shell
echo -e "["$GREEN"+"$RESET"] Make ZSH default shell"
# Do it with sed and grep if CHSH not installed
LINES_NUMBER=$(grep -n "$USER" /etc/passwd | grep -o "^[[:digit:]]*")
OLD_LINE_PASSWD=$(grep "$USER" /etc/passwd)
NEW_LINE_PASSWD=$(echo $OLD_LINE_PASSWD | sed "s|$SHELL|/usr/bin/zsh|")
sudo sed -i "s|$OLD_LINE_PASSWD|$NEW_LINE_PASSWD|" /etc/passwd
# Install OhMyZsh
cd ~
curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh >install.sh && chmod +x install.sh
sh install.sh --unattended >/dev/null
# Install Plugins
echo -e "["$GREEN"+"$RESET"] Install all oh-my-zsh plugins ..\n"
for plugin in ${ALL_PLUGINS[@]}; do
if [[ ! -d "$HOME/.oh-my-zsh/plugins/$plugin" ]]; then
echo -e "[$RED-$RESET]$plugin not installed, install it ..."
mkdir $HOME/.oh-my-zsh/plugins/$plugin
git clone --quiet https://github.com/zsh-users/$plugin $HOME/.oh-my-zsh/plugins/$plugin && echo -e "["$GREEN"+"$RESET"] $plugin installed\n"
else
echo -e "[$GREEN+$RESET]$plugin already installed.\n"
continue
fi
done
# Copy theme files
cp "$SCRIPT_DIR"/chibraax*.zsh-theme "$HOME"/.oh-my-zsh/themes/
# Alias for LSD,BATCAT
echo -e "# Custom alias made by script" >>~/.zshrc
test -f "/usr/bin/lsd" && echo -e "alias ls=/usr/bin/lsd" >>~/.zshrc
test -f "/usr/bin/bat" && echo -e "alias cat=/usr/bin/bat" >>~/.zshrc
test -f "/usr/bin/batcat" && echo -e "alias cat=/usr/bin/batcat" >>~/.zshrc
# .zshrc for plugins
sed -i "s/plugins=(git)/plugins=(git zsh-autosuggestions zsh-syntax-highlighting zsh-completions fzf)/g" .zshrc
# .zshrc for theme
sed -i "s/^ZSH_THEME=.*/ZSH_THEME="chibraax2"/g" "$HOME"/.zshrc
# Warn the user
echo -e "[$GREEN+$RESET] Theme added to ~/.zshrc"
echo -e "[$GREEN+$RESET] Theme located in : ~/.oh-my-zsh/themes/"
# Warn the user
echo -e "\n["$RED"*"$RESET"] NB: Now your 'ls' command will execute LSD, if you want change this uncomment the alias inside your .zshrc"
echo -e "["$RED"*"$RESET"] NB: Now your 'cat' command will execute BATCAT, if you want change this uncomment the alias inside your .zshrc\n"
# Execute the ZSH shell
rm ~/install.sh
exec zsh -l && source .zshrc
exit 0