Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] server setup script #17

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions asdf/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby 2.6.3
helm 2.16.10
228 changes: 194 additions & 34 deletions server/.zshrc
Original file line number Diff line number Diff line change
@@ -1,48 +1,208 @@
export ZSH="$HOME/.oh-my-zsh"
#!/usr/bin/env zsh

ZSH_THEME="bureau"
# .zshrc - z shell configuration
# =========================================================
# - https://github.com/aaqaishtyaw/dotfiles
# - https://aaqa.dev

#Custom message when SSH and custom color
clear
fortune | cowsay -f tux
myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
echo "My Public IP address: ${myip}"
#-------------------------#
# BASE - Environment
#-------------------------#
command -v nvim > /dev/null && EDITOR='nvim' || EDITOR='vi'
export EDITOR

echo "$(uptime)"
echo ""

tmux list-sessions >/dev/null 2>&1
screen -ls >/dev/null 2>&1
#-------------------------#
# Aliases
#-------------------------#

if [ "$?" = "0" ] ; then
echo "Running tmux sessions:"
echo "$(tmux list-sessions)"
else
echo "No running tmux sessions."
if [ -n "$MACOS" ]; then
alias ls='ls -G'
else
alias ls='ls --color=auto'
fi
echo ""

if [ "$?" = "0" ] ; then
echo "Running GNU Screen sessions:"
echo "$(screen -ls)"
else
echo "No running GNU Screen sessions."
fi
alias la='ls -lah'
alias lh='ls -lh'
alias ll='ls -l'
alias sl="ls -al"
alias grep='grep --color=auto'
alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias glog="git log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias k='kubectl'

echo ""
#-------------------------#
# Options
#-------------------------#
HISTFILE=~/.histfile
HISTSIZE=50000
SAVEHIST=100000
REPORTTIME=3
setopt hist_ignore_all_dups hist_ignore_space share_history extended_history
setopt hist_expire_dups_first
setopt autocd correct extended_glob notify prompt_subst

plugins=(
git zsh-syntax-highlighting zsh-autosuggestions
)
unsetopt beep correct_all
bindkey -e
autoload -U select-word-style
select-word-style bash

ZSH_AUTOSUGGEST_USE_ASYNC=true

export EDITOR='vim'
#-------------------------#
# Completion
#-------------------------#
zstyle ':completion:*' completer _expand _complete _ignored
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}'
zstyle ':completion:*' menu select
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle :compinstall filename "$HOME/.zshrc"
bindkey '^[n' expand-or-complete
bindkey '^[p' reverse-menu-complete
bindkey '^[[Z' reverse-menu-complete

alias ip="dig +short myip.opendns.com @resolver1.opendns.com"
alias sl="ls -al"
alias glog="git log --all --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
fpath+=~/.zfunc

autoload -Uz compinit
# Instead of having compinit happen on every prompt, use the cached version in
# the prompt and have it re-load every 5 minutes via Cron
# * * * * * zsh -i -c 'compinit'
if [[ "$MACOS" && $(date +'%j') != $(stat -f '%Sm' -t '%j' ~/.zcompdump) ]]; then
compinit;
elif [[ -n $HOME/.zcompdump(#qN.mh+1) ]]; then
compinit;
else
compinit -C;
fi;

# Gray color for autosuggestions
# ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=247'
# async autosuggest
# ZSH_AUTOSUGGEST_USE_ASYNC=true


#-------------------------#
# Prompt
#-------------------------#
# Enable colors and change prompt:
autoload -U colors && colors # Load colors
#PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[cyan]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
setopt autocd # Automatically cd into typed directory.
stty stop undef # Disable ctrl-s to freeze terminal.
LS_COLORS=$LS_COLORS:'di=1;36:'
export LS_COLORS

# generate
# gen-prompt() {
# local prev_exit="$?"
# local user_color="red"

# if [ $prev_exit -eq 1 ]; then
# user_color="yellow"
# fi

# if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
# user_color="cyan"
# fi

# # local CONTEXT=$(cat ~/.kube/config | grep "current-context:" | sed "s/current-context: //")
# # local k8s_context = echo "(k8s: ${CONTEXT})"
# # [%B%F{$k8s_context}%B%F{red}]%f

# ## Generate a simple, informative multiline prompt.
# local _line_1="%B%F{$user_color}┌─[ %B%F{cyan}%1~ %f%F{$user_color}]"
# local _line_2="%B%F{$user_color}└─%(!.#.>)%f "

# local git_branch=$(git symbolic-ref --short HEAD 2> /dev/null || {
# git rev-list --max-count=1 HEAD 2>/dev/null | cut -c 1-8
# })

# # Render git info, if available, in the prompt.
# if [ "$git_branch" ]; then
# is_dirty() {
# test -n "$(git status --porcelain --ignore-submodules)"
# }

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# # ±
# PLUSMINUS="\u00b1"

source $ZSH/oh-my-zsh.sh
# local _git_status="$git_branch"
# if is_dirty; then
# color=yellow
# _git_status="${_git_status} $PLUSMINUS"
# else
# color=green
# _git_status="${_git_status}"
# fi

# _line_1="$_line_1 %B%F{$color}%b[$_git_status]%f"
# fi

# # Render python virtual env info, if available, in the prompt.
# if [[ -n "$VIRTUAL_ENV" ]];then
# local _venv_prompt=""
# _line_1="$_line_1 %F{blue}($(basename "$VIRTUAL_ENV"))%f"
# fi

# local _newline=$'\n'

# echo "$_line_1$_newline$_line_2"
# }

# PROMPT='$(gen-prompt)'

gen-prompt () {
local prev_exit="$?"
local user_color="green"

if [ $prev_exit -eq 1 ]; then
user_color="red"
fi

local host_color="green"

if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
host_color="red"
fi

## Generate a simple, informative multiline prompt.
local _line_1="%F{blue}┌─[%B%F{$user_color}%n%f%b@%F{${host_color}}%m%f%F{blue}]-[%F{yellow}%*%f%F{blue}]%f"
local _line_2="%F{blue}└─%(!.#.>)%f "

local git_branch=$(git symbolic-ref --short HEAD 2> /dev/null || {
git rev-list --max-count=1 HEAD 2>/dev/null | cut -c 1-8
})

# Render git info, if available, in the prompt.
if [ "$git_branch" ]; then
local _git_status="$git_branch$([ "$(git status --porcelain)" ] && echo "*")"
_line_1="$_line_1 %B%F{green}±%b %F{cyan}($_git_status)%f"
fi

# Render python virtual env info, if available, in the prompt.
if [[ -n "$VIRTUAL_ENV" ]];then
local _venv_prompt=""
_line_1="$_line_1 %F{blue}($(basename "$VIRTUAL_ENV"))%f"
fi

local _newline=$'\n'

echo "$_line_1$_newline$_line_2"
}

#-------------------------#
# Prompt
#-------------------------#
if [ -x "$(command -v starship)" ] && \
[ -f $HOME/.config/starship.toml ] && \
[ -n "$MACOS" -o -n "$DISPLAY" ]; then
eval "$(starship init zsh)"
else
PROMPT='$(gen-prompt)'
RPROMPT="%F{green}%~%f"
fi

export EDITOR='vim'
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
77 changes: 62 additions & 15 deletions server/server_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,67 @@

echo "Beginning with Debian setup. Have a walk while the machine is setup"

sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install git neofetch fortune cowsay wget curl htop tmux dnsutils screen
sudo apt-get -y install python3-pip
sudo apt-get -y install zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

# Zsh Syntax highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting"
cp -rf .zshrc ~/
cp .vimrc ~/
cp .screenrc ~/

chsh -s "$(command -v zsh)"
basic_utilities() {
sudo apt-get -y update && \
sudo apt-get -y upgrade

sudo apt-get -y install git \
neofetch fortune cowsay \
wget curl htop python3-pip \
dnsutils screen tmux locales

sudo locale-gen en_US.UTF-8

}

# setup_shell() {
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended

# git clone https://github.com/zsh-users/zsh-autosuggestions "$HOME"/.oh-my-zsh/custom/plugins/zsh-autosuggestions

# git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME"/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
# }

link_config() {
echo -e "\n\033[32mLinking Config!\033[0m"

cp .zshrc "$HOME"/.zshrc
cp .vimrc "$HOME"/.vimrc
cp .screenrc "$HOME"/.screenrc
}


setup_zsh() {
sudo apt -y install zsh
}

# Install docker
install_docker() {
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"

sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io

sudo usermod -aG docker "$USER"
newgrp docker
}

basic_utilities
install_docker
link_config
setup_zsh
# setup_shell

exit 0
4 changes: 2 additions & 2 deletions tmux/tmux/tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set -sg escape-time 0
set -g display-time 1500
set -g remain-on-exit off
set -g repeat-time 300
setw -g allow-rename off
setw -g automatic-rename off
setw -g allow-rename on
setw -g automatic-rename on
setw -g aggressive-resize on

# Change prefix key to C-a, easier to type, same to "screen"
Expand Down
5 changes: 5 additions & 0 deletions zsh/.zsh.paths
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export PATH="/usr/local/opt/[email protected]/bin:$PATH"
export GEM_PATH="/Users/aaqa/.asdf/shims/"
export PATH="$GEM_PATH/bin:$PATH"

GOROOT="$(brew --prefix golang)/libexec"
export GOPATH=$HOME/go
export GOROOT
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"

. $(brew --prefix asdf)/asdf.sh

# shellcheck disable=SC2206
Expand Down