Created
July 4, 2024 10:48
-
-
Save tom4897/9224412c5942be94561aaacb938cf2eb to your computer and use it in GitHub Desktop.
Post Install Scripts for Ubuntu (Jammy)
This file contains hidden or 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
| #!/bin/bash |
This file contains hidden or 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
| DISP_OK="\033[0;38;5;2m [OK]\033[00m" | |
| DISP_NOK="\033[31m [NOK]\033[00m" | |
| DISP_WIP="\033[34m [WIP]\033[00m" | |
| DISP_SKIPPED="\033[90m [SKIPPED]\033[00m" | |
| if [ -n "$SHELL_CUSTOM_DEFINED" ]; then | |
| exit 0 | |
| fi | |
| # Get machine type | |
| machine_type=$( [ -d "/sys/class/dmi/id" ] && echo "Phy" || \ | |
| [ -d "/proc/vz" ] && echo "VM" || \ | |
| uname -r | grep -q 'microsoft' && echo "WSL" || \ | |
| echo "Unknown" ) | |
| echo $(uname -n) \ | |
| "| ($machine_type) $(lsb_release -ds 2>/dev/null || cat /etc/*release 2>/dev/null | head -n 1 || uname -om)" \ | |
| "| $(ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n 1) ($(ip route show default | awk '/default/ {print $3}'))" \ | |
| "| $(last -1 -i | head -n 1 | awk '{print $4, $5, $6, $7}')" | |
| echo "" | |
| echo "Custom shell definition $DISP_WIP" | |
| if [ -n "$ZSH_VERSION" ]; then | |
| alias zshconfig="nano ~/.zshrc" | |
| alias zshcustom="nano ~/.zshcustom" | |
| alias ohmyzsh="nano ~/.oh-my-zsh" | |
| alias zshperf="time zsh -i -c exit" | |
| fi | |
| if [ -n "$BASH_VERSION" ]; then | |
| alias bashconfig="nano ~/.bashrc" | |
| alias bashcustom="nano ~/.bashcustom" | |
| fi | |
| # Environment variables | |
| history_size=50000 | |
| export HISTCONTROL=ignoredups | |
| export HISTSIZE=$history_size | |
| export SAVEHIST=$history_size | |
| # Added to configure git cz behavior | |
| export CZ_JIRA_LOCATION="pre-type" | |
| export CZ_JIRA_PREPEND="[" | |
| export CZ_JIRA_APPEND="]" | |
| # Set the default pager | |
| export PAGER=$(command -v most || echo less) | |
| if uname -r | grep -q 'microsoft' ; then | |
| if [ -f /usr/bin/warp-terminal ]; then | |
| export WGPU_BACKEND=gl | |
| export WARP_ENABLE_WAYLAND=1 | |
| alias winhome='cd /mnt/c/Users/$(whoami)/' | |
| alias winc='cd /mnt/c/' | |
| alias wind='cd /mnt/d/' | |
| fi | |
| if [ -f /usr/bin/vagrant ]; then | |
| export VAGRANT_HOME="$HOME/.vagrant.d" | |
| export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox" | |
| export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1" | |
| fi | |
| fi | |
| # Aliases | |
| # File and directory navigation | |
| alias ll='ls -lahF --color=auto' | |
| alias la='ls -A' | |
| alias l='ls -CF' | |
| alias lsd='ls -l | grep "^d"' | |
| alias u='cd ..; ls --color' | |
| up() { cd $(printf "%0.s../" $(seq 1 $1)); pwd; } | |
| alias ..='cd ..' | |
| alias ...='cd ../../' | |
| alias ....='cd ../../../' | |
| cdls() { cd "$@" && ls --color=auto; } | |
| alias tree='tree -C -L 2' | |
| alias ncdu='ncdu --color dark' | |
| alias back='cd -' | |
| alias ls='ls --color=auto' | |
| # File search | |
| alias grep='grep --color=auto' | |
| alias rgrep='grep -rnw . -e --color=auto' | |
| lss() { ls -lrt | command grep "$1"; } | |
| alias dir='ls --color=auto --format=vertical' | |
| alias vdir='ls --color=auto --format=long' | |
| alias most='most -ct3 -s' | |
| alias rmdir='rmdir -v' | |
| lffile() { find . -maxdepth 3 -type f -exec grep --color=auto "$@" {} +; } | |
| lfkey() { find . -name "*.pub" -exec grep --color=auto "$@" {} +; } | |
| lflog() { find . -name "*.log" -exec grep --color=auto "$@" {} +; } | |
| lfphp() { find . -name "*.php" -exec grep --color=auto "$@" {} +; } | |
| lf() { find . -name "*.${1}" -exec grep --color=auto "$2" {} +; } | |
| # Disk usage | |
| alias duhome='/usr/bin/du -sh ~/' | |
| duls() { du -sh * | sort -h ;} | |
| alias du='du -h --max-depth=1 $@' | |
| alias dusort='du -x --block-size=1048576 | sort -nr' | |
| alias df='df -h' | |
| # Fail-safes | |
| alias rm='rm -i -v' | |
| alias mv='mv -i -v' | |
| alias cp='cp -i -v' | |
| alias ln='ln -i' | |
| trash() { command mv "$@" ~/.trash; } | |
| # Process management | |
| pssf() { ps -ef | grep "$1"; } | |
| psse() { ps -el | grep "$1"; } | |
| alias psz='ps -el | grep z' | |
| alias psr='ps -el | grep r' | |
| killbyname() { pkill -f "$1"; } | |
| alias meminfo='free -m' | |
| alias clearcache='sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"' | |
| alias psgrep='ps aux | grep' | |
| alias htop='htop --tree' | |
| # Log viewing | |
| logview() { ccze -A < "$1" | less -R; } | |
| logtail() { tail -f "$1" | ccze; } | |
| tail_latest_log() { | |
| ls -ltrh *.log | tail -n 1 | awk '{print $NF}' | xargs tail -f | |
| } | |
| # Directory creation and copying | |
| mkcd() { mkdir -p "$1" && cd "$1"; } | |
| cpbak() { cp "$1" "$1.bak"; } | |
| # Git commands | |
| alias gs='git status' | |
| alias gup='git pull --rebase' | |
| alias glg='git log --graph --oneline --decorate --all' | |
| alias gc='git commit' | |
| alias gp='git push' | |
| alias gl='git pull' | |
| alias gco='git checkout' | |
| alias gstash='git stash' | |
| alias ggpr='git config --global pull.rebase true' | |
| # Network utilities | |
| alias pingd='ping chloe.deerhide.run' | |
| alias check_ping='ping -c 1 8.8.8.8 &> /dev/null && echo "PING $DISP_OK" || echo "PING $DISP_NOK"' | |
| alias check_dns='host google.com &> /dev/null && echo "DNS $DISP_OK" || echo "DNS $DISP_NOK"' | |
| alias check_network='check_ping; check_dns' | |
| alias ports='netstat -tulanp' | |
| alias checkport='nc -zv' | |
| alias httpserve='python -m http.server' | |
| alias edithosts='sudo nano /etc/hosts' | |
| alias listening="sudo lsof -i -P -n | grep LISTEN" | |
| fixwebperms() { | |
| sudo find . -type d -exec chmod 755 {} \; | |
| sudo find . -type f -exec chmod 644 {} \; | |
| } | |
| # Additional aliases | |
| alias update="sudo apt update && sudo apt upgrade -y" | |
| alias cls="clear" | |
| alias mount='mount | column -t' | |
| alias uptime='uptime -p' | |
| alias shutdown='echo "Use shutdown -h now to shutdown"' | |
| alias reboot='echo "Use reboot now to reboot"' | |
| alias pman='man -t | ps2pdf - - | open -f -a Preview' | |
| alias keyAgent='echo "=== SSH Agent ==="; ssh-add -l; echo ""; echo "=== GPG Agent ==="; gpg --list-secret-keys' | |
| alias keyList='ls -al ~/.ssh' | |
| alias sshduser='~/.ssh/' | |
| alias sshdroot='/root/.ssh/' | |
| alias sshdconfig='/etc/ssh/' | |
| # Docker | |
| alias docker-clean='docker container prune -f' | |
| alias docker-info='docker images; docker ps -a; docker volume ls; docker network ls' | |
| # Functions | |
| extract() { | |
| if [ -f $1 ]; then | |
| case $1 in | |
| *.tar.bz2) tar xjf $1 ;; | |
| *.tar.gz) tar xzf $1 ;; | |
| *.bz2) bunzip2 $1 ;; | |
| *.rar) unrar x $1 ;; | |
| *.gz) gunzip $1 ;; | |
| *.tar) tar xf $1 ;; | |
| *.tbz2) tar xjf $1 ;; | |
| *.tgz) tar xzf $1 ;; | |
| *.zip) unzip $1 ;; | |
| *.Z) uncompress $1 ;; | |
| *.7z) 7z x $1 ;; | |
| *) echo "don't know how to extract '$1'..." ;; | |
| esac | |
| else | |
| echo "'$1' is not a valid file" | |
| fi | |
| } | |
| echo "Custom shell definition $DISP_OK" | |
| export SHELL_CUSTOM_DEFINED=true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment