Compare commits

...

7 Commits

12 changed files with 216 additions and 93 deletions

5
patches/ssh-acd746d.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
cd /etc/ssh
ln -sf /etc/toolkit/ssh/sshd_config .

52
scripts/setup.sh Normal file → Executable file
View File

@ -3,29 +3,55 @@
set -e set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
TOOLKIT_DIR="$SCRIPT_DIR"/..
# Load default shell scripts # Load package manager script
. $SCRIPT_DIR/../sh/load.sh . "$SCRIPT_DIR"/util/pkg-mgr.sh
update_default_shell() { # Load color script
/usr/sbin/usermod -sf /usr/bin/zsh $1 . "$SCRIPT_DIR"/util/color.sh
update_user_shell() {
/usr/sbin/usermod -s /usr/bin/zsh "$1"
} }
install_shell_config() { install_user_config() {
/usr/bin/ln -s /etc/toolkit/sh/.zshrc $1 /usr/bin/ln -s /etc/toolkit/sh/"$1" "$2"
} }
print_info Installing necessary packages...
install_package zsh install_package zsh
update_default_shell root print_info Setting up user shells...
update_default_shell coby
install_shell_config /root/.zshrc update_user_shell root
install_shell_config /home/coby/.zshrc update_user_shell coby
install_user_config .zshrc /root/.
install_user_config .zshrc /home/coby/.
install_user_config .vimrc /root/.
install_user_config .vimrc /home/coby/.
# Replace old ssh server config # Replace old ssh server config
rm /etc/ssh/sshd_config if [[ -d /etc/ssh ]]; then
ln -sf /etc/toolkit/sshd/sshd_config /etc/ssh/. ln -sf "$TOOLKIT_DIR"/ssh/sshd_config /etc/ssh/.
elif
print_warn /etc/ssh does not exist, failed to install sshd config
fi
# Install cronjobs
if [[ -d /etc/cron.d ]]; then
ln -sf "$TOOLKIT_DIR"/cron/* /etc/cron.d/.
elif
print_warn /etc/cron.d does not exist, failed to install cronjobs
print_warn Are you running a debian-based distro?
fi
print_info Installing necessary submodules...
# Pull submodules # Pull submodules
. $SCRIPT_DIR/update.sh git submodule update --init --recursive
print_info Setup complete

View File

@ -1,13 +0,0 @@
# Setup tasks
- Determine which package manager to use based on distro
- Update & upgrade system
- Install necessary packages (zsh)
- Ask which user wants shell and dotfiles & install them
- Ask to install cronjobs & install them
- Ask to install SSH configurations & install them

33
scripts/update.sh Normal file → Executable file
View File

@ -1,6 +1,39 @@
#!/bin/bash #!/bin/bash
# Only begin update process if necessary
if [[ -z "$(git remote show origin | grep "out of date")" ]]; then
exit 0
fi
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
TOOLKIT_DIR="$SCRIPT_DIR"/..
# Load color script
. "$SCRIPT_DIR"/util/color.sh
last_hash=$( git rev-parse HEAD )
recent_hashes=$( git log --format=format:%H | grep -B 100 $last_hash)
print_info Resetting repo and pulling latest commits...
# Resets the repo to last state
git reset --hard git reset --hard
# Pulls new commits
git pull git pull
# Downloads or updates repo submodules
git submodule update --init --recursive git submodule update --init --recursive
# Removes untracked files and directories
git clean -fd --force git clean -fd --force
# Runs patch scripts to ensure machine state
# matches toolkit state
while IFS= read -r hash; do
short_hash=$( echo "$hash" | cut -c -7 )
print_info Running patch script \'"$short_hash"\'
. "$SCRIPT_DIR"/../patches/*-"$short_hash".sh 2>/dev/null
done <<< "$recent_hashes"
print_info Update complete

23
scripts/util/color.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
BLACK="\033[30m"
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BLUE="\033[34m"
PINK="\033[35m"
CYAN="\033[36m"
WHITE="\033[37m"
RESET="\033[0;39m"
print_info() {
echo -e "$RESET"["$BLUE"i"$RESET"] $@
}
print_warn () {
echo -e "$RESET"["$YELLOW"!"$RESET"] $@
}
print_error () {
echo -e "$RESET"["$RED"x"$RESET"] $@
}

23
scripts/util/pkg-mgr.sh Executable file
View File

@ -0,0 +1,23 @@
declare -A osInfo;
osInfo[/etc/redhat-release]=yum
osInfo[/etc/arch-release]=pacman
osInfo[/etc/gentoo-release]=emerge
osInfo[/etc/SuSE-release]=zypp
osInfo[/etc/debian_version]=apt-get
osInfo[/etc/alpine-release]=apk
for key val in "${(@kv)osInfo}"; do
if [[ -f $key ]]; then
PACKAGE_MANAGER=$val
fi
done
install_package() {
if [ "$PACKAGE_MANAGER" == "yum" ]; then yum install -y "$@"
elif [ "$PACKAGE_MANAGER" == "pacman" ]; then pacman -S --noconfirm "$@"
elif [ "$PACKAGE_MANAGER" == "emerge" ]; then emerge "$@"
elif [ "$PACKAGE_MANAGER" == "zypp" ]; then zypper install "$@"
elif [ "$PACKAGE_MANAGER" == "apt-get" ]; then apt-get install -y "$@"
elif [ "$PACKAGE_MANAGER" == "apk" ]; then apk add "$@"; fi
}

View File

@ -1,6 +1,84 @@
" ___ ___ ___ _____ ______ ________ ________
" |\ \ / /|\ \|\ _ \ _ \|\ __ \|\ ____\
" \ \ \ / / | \ \ \ \\\__\ \ \ \ \|\ \ \ \___|
" \ \ \/ / / \ \ \ \ \\|__| \ \ \ _ _\ \ \
" \ \ / / \ \ \ \ \ \ \ \ \ \\ \\ \ \____
" \ \__/ / \ \__\ \__\ \ \__\ \__\\ _\\ \_______\
" \|__|/ \|__|\|__| \|__|\|__|\|__|\|_______|
" by Coby Powers
" (inspired by https://www.freecodecamp.org/news/vimrc-configuration-guide-customize-your-vim-editor/)
" Remove compatibility with vi
set nocompatible
" Enable type file detection. Vim will be able to try to detect the type of file in use.
filetype on
" Enable plugins and load plugin for the detected file type.
filetype plugin on
" Load an indent file for the detected file type.
filetype indent on
" Turn syntax highlighting on.
syntax on
" Add numbers to each line on the left-hand side.
set number set number
set autoindent " Highlight cursor line underneath the cursor horizontally.
set noexpandtab set cursorline
set tabstop=2
" Highlight cursor line underneath the cursor vertically.
"set cursorcolumn
" Set shift width to 2 spaces.
set shiftwidth=2 set shiftwidth=2
" Set tab width to 2 columns.
set tabstop=2
" Use space characters instead of tabs.
set expandtab
" Do not save backup files.
set nobackup
" Do not let cursor scroll below or above N number of lines when scrolling.
set scrolloff=10
" Do not wrap lines. Allow long lines to extend as far as the line goes.
set nowrap
" While searching though a file incrementally highlight matching characters as you type.
set incsearch
" Ignore capital letters during search.
set ignorecase
" This will allow you to search specifically for capital letters.
set smartcase
" Show partial command you type in the last line of the screen.
set showcmd
" Show the mode you are on the last line.
set showmode
" Show matching words during a search.
set showmatch
" Use highlighting when doing a search.
set hlsearch
" Set the commands to save in history default number is 20.
set history=1000
" Enable auto completion menu after pressing TAB.
set wildmenu
" Make wildmenu behave like similar to Bash completion.
set wildmode=list:longest
" Wildmenu will ignore files with these extensions.
set wildignore=*.docx,*.jpg,*.png,*.gif,*.pdf,*.pyc,*.exe,*.flv,*.img,*.xlsx

View File

@ -1,3 +1,13 @@
# ________ ________ ___ ___ ________ ________
# |\_____ \|\ ____\|\ \|\ \|\ __ \|\ ____\
# \|___/ /\ \ \___|\ \ \\\ \ \ \|\ \ \ \___|
# / / /\ \_____ \ \ __ \ \ _ _\ \ \
# / /_/__\|____|\ \ \ \ \ \ \ \\ \\ \ \____
# |\________\____\_\ \ \__\ \__\ \__\\ _\\ \_______\
# \|_______|\_________\|__|\|__|\|__|\|__|\|_______|
# \|_________|
# by Coby Powers
TOOLKIT=/etc/toolkit TOOLKIT=/etc/toolkit
ZSH=$TOOLKIT/sh/ohmyzsh ZSH=$TOOLKIT/sh/ohmyzsh

View File

@ -10,6 +10,7 @@ alias ll='ls -l'
alias la='ls -A' alias la='ls -A'
alias lf='ls -F' alias lf='ls -F'
alias l.='ls -d .*' alias l.='ls -d .*'
alias lah='ls -lah'
alias lh='ls -lh' alias lh='ls -lh'
alias lr='ls -R' alias lr='ls -R'
alias l='ls' alias l='ls'
@ -18,28 +19,16 @@ alias md='mkdir -p'
alias rd='rm -rf' alias rd='rm -rf'
alias q='exit' alias q='exit'
alias c='clear' alias c='clear'
alias journal='journalctl -xe' alias journal='journalctl -xe'
alias journal-err='journalctl -p 3 -b' alias journal-err='journalctl -p 3 -b'
alias fstab='sudo vim /etc/fstab' alias fstab='_ vim /etc/fstab'
alias rcron='sudo crontab -e' alias rcron='sudo crontab -e'
alias cron='crontab -e' alias cron='crontab -e'
alias upd-arch='paru -S archlinux-keyring && paru'
alias upd-ubt='sudo apt update -y && sudo apt upgrade -y'
if [[ "$OS" == "Arch Linux" ]]; then
alias upd='upd-arch'
elif [[ $OS == "Ubuntu" ]]; then
alias upd='upd-ubt'
else
alias upd='echo Failed to detect distribution. The script needs to be able to determine the distribution to know which package manager to use'
fi
alias reload='source ~/.zshrc' alias reload='source ~/.zshrc'
alias aliases='cat $ALIASES' alias aliases='cat $ALIASES'

View File

@ -1,29 +0,0 @@
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$NAME
VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si)
VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS=Debian
VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
...
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
...
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
VER=$(uname -r)
fi

View File

@ -1,22 +0,0 @@
declare -A osInfo;
osInfo[/etc/redhat-release]=yum
osInfo[/etc/arch-release]=pacman
osInfo[/etc/gentoo-release]=emerge
osInfo[/etc/SuSE-release]=zypp
osInfo[/etc/debian_version]=apt-get
osInfo[/etc/alpine-release]=apk
for key val in "${(@kv)osInfo}"; do
if [[ -f $key ]];then
PACKAGE_MANAGER=$val
fi
done
install_package() {
if [ "$PACKAGE_MANAGER" == "yum" ]; then yum install -y $1
elif [ "$PACKAGE_MANAGER" == "pacman" ]; then pacman -S --noconfirm $1
elif [ "$PACKAGE_MANAGER" == "emerge" ]; then emerge $1
elif [ "$PACKAGE_MANAGER" == "zypp" ]; then zypper install $1
elif [ "$PACKAGE_MANAGER" == "apt-get" ]; then apt-get install -y $1
elif [ "$PACKAGE_MANAGER" == "apk" ]; then apk add $1; fi
}