Skip to content

Commit

Permalink
Merge pull request #3 from benjy8001/develop
Browse files Browse the repository at this point in the history
Refacto install script
  • Loading branch information
benjy8001 authored May 24, 2020
2 parents 3da12ee + f34863c commit 04c1ae1
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 79 deletions.
5 changes: 0 additions & 5 deletions Dockerfile

This file was deleted.

13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
DOCKER_COMPOSE = docker-compose

EXEC_DEBIAN = $(DOCKER_COMPOSE) exec -T debian /entrypoint
EXEC_DEBIAN = $(DOCKER_COMPOSE) exec debian

start: ## Pull and start docker debian
start:
printf "\033[32m You can go take a coffee while we work for you \033[0m\n"
$(DOCKER_COMPOSE) pull
$(DOCKER_COMPOSE) up -d --remove-orphans debian

stop: ## Stop docker
stop:
$(DOCKER_COMPOSE) stop

run:
run: ## Run the install script on debian
run: start
$(EXEC_DEBIAN) ./install_zsh.sh

connect: ## Connect to the container of the project
$(EXEC_DEBIAN)

.PHONY: start stop run connect

##
.DEFAULT_GOAL := help
help:
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
.PHONY: help
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ version: '3.4'
services:
debian:
image: debian:jessie
tty: true
working_dir: /srv
volumes:
- ./:/srv:ro
- ./:/srv:rw
181 changes: 110 additions & 71 deletions install_zsh.sh
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
#!/bin/bash
#!/usr/bin/env bash
# Install script for ZSH and Powerlevel9k

set -e
set -u

if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi

command -v git >/dev/null 2>&1 || {
echo "${RED}Error: git is not installed${NORMAL}"
exit 1
set -o errexit
set -o pipefail
set -o nounset

prepare_color() {
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
}

command -v tee >/dev/null 2>&1 || {
echo "${RED}Error: tee is not installed${NORMAL}"
exit 1
install_software() {
apt-get update && apt-get install -y git coreutils zsh fonts-powerline wget curl unzip
}

apt-get install -y git zsh fonts-powerline wget curl

printf "${BLUE}Installing nerd-fonts...${NORMAL}\n"
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.0.0/Hack.zip
mkdir hack
unzip Hack.zip -d hack
rm Hack.zip
mv hack /usr/share/fonts/truetype
fc-cache -f -v

printf "${BLUE}Cloning powerlevel9k...${NORMAL}\n"
env git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k || {
printf "${RED}Error: git clone of powerlevel9k repo failed${NORMAL}\n"
exit 1
install_fonts() {
printf "${BLUE}Installing nerd-fonts...${NORMAL}\n"
wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.0.0/Hack.zip
mkdir hack
unzip Hack.zip -d hack
rm Hack.zip
mv hack /usr/share/fonts/truetype
fc-cache -f -v
}
printf "${BLUE}Cloning zsh-autosuggestions...${NORMAL}\n"
env git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions || {
printf "${RED}Error: git clone of zsh-autosuggestions repo failed${NORMAL}\n"
exit 1

install_powerlevel9k() {
printf "${BLUE}Cloning powerlevel9k...${NORMAL}\n"
env git clone https://github.com/bhilburn/powerlevel9k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel9k || {
printf "${RED}Error: git clone of powerlevel9k repo failed${NORMAL}\n"
exit 1
}
}
printf "${BLUE}Cloning zsh-syntax-highlighting...${NORMAL}\n"
env git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting || {
printf "${RED}Error: git clone of zsh-syntax-highlighting repo failed\${NORMAL}n"
exit 1

install_zsh_plugins() {
printf "${BLUE}Cloning zsh-autosuggestions...${NORMAL}\n"
env git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions || {
printf "${RED}Error: git clone of zsh-autosuggestions repo failed${NORMAL}\n"
exit 1
}
printf "${BLUE}Cloning zsh-syntax-highlighting...${NORMAL}\n"
env git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting || {
printf "${RED}Error: git clone of zsh-syntax-highlighting repo failed\${NORMAL}n"
exit 1
}
}

printf "${BLUE}Editing ~/.zshrc${NORMAL}\n"
tee ~/.zshrc << END
set_zsh_config() {
printf "${BLUE}Editing ~/.zshrc${NORMAL}\n"
export ZSH="~/.oh-my-zsh"
tee ~/.zshrc << EOL
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/root/.oh-my-zsh"
export ZSH="~/.oh-my-zsh"
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
Expand Down Expand Up @@ -157,22 +161,13 @@ plugins=(
colored-man-pages
)
source $ZSH/oh-my-zsh.sh
source ~/.oh-my-zsh/oh-my-zsh.sh
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
Expand All @@ -187,13 +182,57 @@ source $ZSH/oh-my-zsh.sh
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
END
EOL
}

printf "${BLUE}Installing Oh My Zsh...${NORMAL}\n"
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
install_oh_my_zsh() {
printf "${BLUE}Installing Oh My Zsh...${NORMAL}\n"
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
}

set_zsh_as_default_shell() {
printf "${BLUE}Sourcing ~/.zshrc${NORMAL}\n"
/bin/zsh -c 'source ~/.zshrc'

printf "${BLUE}Setting zsh as default shell${NORMAL}\n"
chsh -s /bin/zsh
}

printf "${BLUE}Sourcing ~/.zshrc${NORMAL}\n"
/bin/zsh -c 'source ~/.zshrc'
main() {
prepare_color
install_software
install_fonts
install_oh_my_zsh
install_powerlevel9k
install_zsh_plugins
set_zsh_config
set_zsh_as_default_shell
}

cleanup() {
printf "${RED}Cleanup${NORMAL}\n"
if [ -f Hack.zip ]; then
rm Hack.zip
fi
if [ -d hack ]; then
rm -Rf hack
fi
if [ -d /usr/share/fonts/truetype/hack ]; then
rm -Rf /usr/share/fonts/truetype/hack
fi
if [ -d ~/.oh-my-zsh ]; then
rm -Rf ~/.oh-my-zsh
fi
if [ -d ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel9k ]; then
rm -Rf ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel9k
fi
if [ -d ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions ]; then
rm -Rf ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
fi
if [ -d ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting ]; then
rm -Rf ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
fi
}
trap cleanup EXIT

printf "${BLUE}Setting zsh as default shell${NORMAL}\n"
chsh -s /bin/zsh
main "${@}"

0 comments on commit 04c1ae1

Please sign in to comment.