Last active
December 26, 2021 14:57
-
-
Save souhaiebtar/61cfaefc28fdbd213efec572487d36e9 to your computer and use it in GitHub Desktop.
Post install script ubuntu or debian shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
CAN_I_RUN_SUDO=$(sudo -n uptime 2>&1|grep "load"|wc -l) | |
if [ $CAN_I_RUN_SUDO -ne 0 ]; then | |
echo "Installing sudo" | |
apt-get install -y sudo | |
fi | |
# function to get distro and version used by vim install | |
get_distribution_version() { | |
lsb_dist="" | |
# Every system that we officially support has /etc/os-release | |
if [ -r /etc/os-release ]; then | |
lsb_dist_vers="$(. /etc/os-release && echo "$ID $VERSION_ID")" | |
fi | |
# Returning an empty string here should be alright since the | |
# case statements don't act unless you provide an actual value | |
echo "$lsb_dist_vers" | |
} | |
get_docker_compose_latest_release() { | |
DOCKER_COMPOSE="docker/compose" | |
curl --silent "https://api.github.com/repos/$DOCKER_COMPOSE/releases/latest" | # Get latest release from GitHub api | |
grep '"tag_name":' | # Get tag line | |
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value | |
} | |
lsb_dist_vers=$( get_distribution_version ) | |
distro=$(echo $lsb_dist_vers | awk '{ print $1 }' | tr '[:upper:]' '[:lower:]') | |
version=$(echo $lsb_dist_vers | awk '{ print $2 }' | tr '[:upper:]' '[:lower:]') | |
case "$distro" in | |
ubuntu) | |
if [ $version = "16.04" ] || [ $version = "14.04" ]; then | |
sudo add-apt-repository -y ppa:jonathonf/vim | |
sudo apt-get update | |
sudo apt-get install -y vim | |
fi | |
;; | |
debian) | |
if [ $version = "9" ]; then | |
sudo apt-get install -y software-properties-common dirmngr --install-recommends | |
sudo add-apt-repository 'deb http://ppa.launchpad.net/jonathonf/vim/ubuntu xenial main' | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8CF63AD3F06FC659 | |
sudo apt-get update | |
sudo apt-get install -y vim | |
fi | |
;; | |
*) | |
echo 'sorry, the script is currently support ubuntu1604 and debian9 only' | |
;; | |
esac | |
#fix error on some debian version when updating(debian 9.4 scaleway) | |
sed -i 's/^deb[[:space:]]\{1,\}http:\/\/ftp.debian.org\/debian[[:space:]]\{1,\}stretch\/updates[[:space:]]\{1,\}main/#&/g' /etc/apt/sources.list | |
sed -i 's/^deb-src[[:space:]]\{1,\}http:\/\/ftp.debian.org\/debian[[:space:]]\{1,\}stretch\/updates[[:space:]]\{1,\}main/#&/g' /etc/apt/sources.list | |
#change localtime to localtime | |
sudo rm /etc/localtime | |
sudo ln -s /usr/share/zoneinfo/Africa/Tunis /etc/localtime | |
echo "check if curl is installed and installed it if not" | |
curl --version > /dev/null 2>&1 | |
CURL_IS_INSTALLED=$? | |
if [ $CURL_IS_INSTALLED -ne 0 ]; then | |
echo "Installing curl" | |
sudo apt-get install -y curl | |
else | |
echo "curl is already installed" | |
fi | |
echo "Install git and tmux" | |
sudo apt-get install -y git tmux | |
git config --global user.email "you@example.com" | |
git config --global user.name "Your Name" | |
echo "installing zsh" | |
#echo "installing zsh 5.5.1" | |
#curl -fLo libtinfo6_6.1+20180210-4_amd64.deb http://ftp.br.debian.org/debian/pool/main/n/ncurses/libtinfo6_6.1+20180210-4_amd64.deb | |
#curl -fLo zsh-common_5.5.1-1_all.deb http://ftp.br.debian.org/debian/pool/main/z/zsh/zsh-common_5.5.1-1_all.deb | |
#curl -fLo zsh_5.5.1-1+b1_amd64.deb http://ftp.br.debian.org/debian/pool/main/z/zsh/zsh_5.5.1-1+b1_amd64.deb | |
#sudo dpkg -i libtinfo6_6.1+20180210-4_amd64.deb | |
#sudo dpkg -i zsh-common_5.5.1-1_all.deb | |
#sudo dpkg -i zsh_5.5.1-1+b1_amd64.deb | |
#rm -f libtinfo6_6.1+20180210-4_amd64.deb zsh-common_5.5.1-1_all.deb zsh_5.5.1-1+b1_amd64.deb | |
sudo apt-get install -y zsh | |
echo "tmux config" | |
USER=`whoami` | |
USER_HOME="$(echo -n $(bash -c "cd ~${USER} && pwd"))" | |
echo "set-option -g default-shell /bin/zsh"$'\n'"set -g status off" >> "$USER_HOME"/.tmux.conf | |
# Get prezto | |
git clone --recursive https://github.com/sorin-ionescu/prezto.git ~/.zprezto | |
# Backup zsh config if it exists | |
if [ -f ~/.zshrc ]; | |
then | |
mv ~/.zshrc ~/.zshrc.backup | |
fi | |
# Create links to zsh config files | |
ln -s ~/.zprezto/runcoms/zlogin ~/.zlogin | |
ln -s ~/.zprezto/runcoms/zlogout ~/.zlogout | |
ln -s ~/.zprezto/runcoms/zpreztorc ~/.zpreztorc | |
ln -s ~/.zprezto/runcoms/zprofile ~/.zprofile | |
ln -s ~/.zprezto/runcoms/zshenv ~/.zshenv | |
ln -s ~/.zprezto/runcoms/zshrc ~/.zshrc | |
curl https://gist.githubusercontent.com/souhaiebtar/738c13454c547bc22629fcb80fed747f/raw/1664b93216f78fad2289aa75549ac8d16cde44cc/zpreztorc > ~/.zprezto/runcoms/zpreztorc | |
curl -fLo ~/.zprezto/modules/completion/external/src/_docker \ | |
https://raw.github.com/felixr/docker-zsh-completion/master/_docker | |
sudo sed -i "/$USER/s/bash/zsh/g" /etc/passwd | |
docker --version > /dev/null 2>&1 | |
DOCKER_IS_INSTALLED=$? | |
if [ $DOCKER_IS_INSTALLED -gt 0 ]; then | |
echo "Install docker and adding it to the docker group" | |
sudo apt-get -f install | |
sudo curl https://get.docker.com/ | bash | |
username=`whoami` | |
sudo usermod -aG docker $username | |
fi | |
echo "copying docker compose and adding execute permission to it" | |
sudo curl -L https://github.com/docker/compose/releases/download/$(get_docker_compose_latest_release)/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
#fix things | |
sudo apt-get -f install | |
echo "installing vim-plug and plugin" | |
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ | |
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
curl -L https://gist.githubusercontent.com/souhaiebtar/d6d246b3e038abf26e72be5f113ace75/raw/d2c7868bdf73e71649710464af26c90eb5217acc/.vimrc > ~/.vimrc | |
rm -f ~/.zshrc | |
curl -L https://gist.githubusercontent.com/souhaiebtar/9ad3f5f9387b72ac1f005567bde6c91e/raw/ed53b1b742ed8235f2ac4524207809145d2fbcdf/.zshrc > ~/.zshrc | |
sudo apt-get install -y ufw | |
sudo ufw allow ssh | |
# read -p "add port needed by docker swarm? (y/n) " RESP | |
# if [ "$RESP" = "y" ]; then | |
# echo "adding port needed by docker swarm" | |
# sudo ufw allow 2376/tcp && sudo ufw allow 7946/udp | |
# sudo ufw allow 7946/tcp && sudo ufw allow 80/tcp | |
# sudo ufw allow 2377/tcp && sudo ufw allow 4789/udp | |
# else | |
# echo "OKAY" | |
# fi | |
sudo ufw reload | |
sudo ufw --force enable | |
echo "vim +PlugInstall" | |
vim +PlugInstall +qall | |
#echo "zsh" | |
#zsh | |
#echo "for a docker swarm manager" | |
#echo "ufw allow 2376/tcp" | |
#echo "ufw allow 2377/tcp" | |
#echo "ufw allow 7946/tcp" | |
#echo "ufw allow 7946/udp" | |
#echo "ufw allow 4789/udp" | |
#echo "for a docker swarm worker" | |
#echo "ufw allow 2376/tcp" | |
#echo "ufw allow 7946/tcp" | |
#echo "ufw allow 7946/udp" | |
#echo "ufw allow 4789/udp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment