diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf1b7ef --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/log/singleton.log diff --git a/domain-check.sh b/domain-check.sh new file mode 100755 index 0000000..c4596e4 --- /dev/null +++ b/domain-check.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# check https status code, for domain, and lookup ip address. +# check-domain.sh www.example.com [example.org] + +# check for "-v" in command prompt +VERBOSE=false +while getopts "v" OPTION; do + case $OPTION in + v) + VERBOSE=true + ;; + esac +done + +if [ "$VERBOSE" = false ]; then + echo "use -v for verbose mode (to also get TTL)" +fi + +function process_domain_list () { + for domain in "$@"; do + # skip "-v" option if given + if [[ "$domain" == "-v" ]]; then + continue + fi + + # get current https status code from this domain + curl -s -o /dev/null --connect-timeout 0.5 -I -w "%{http_code} " "https://$domain/" + + # we lookup the name-server for the base domain, and use that as our resolver + # TODO need to fix, as this will not work with domains like: "example.co.uk" + basedomain=$(expr match "$domain" '.*\.\(.*\..*\)') + if [[ -z $basedomain ]]; then + # input may have not had a subdomain + basedomain="$domain" + fi + nameserver=$(dig +short NS $basedomain | head -n 1) + + # if verbose, we show full answer, instead of just the ip (adds TTL and Record Type) + if [ $VERBOSE = true ]; then + output=$(dig @$nameserver +noall +answer $domain) + printf "%-39.39s %5.5s %-2.2s %-10.10s %-39.39s\n" $output + else + output=$(dig @$nameserver +short $domain) + printf "%-39.39s %-39.39s\n" "$domain." $output + fi + done +} + +echo "----- Domain Check -------------------------------------------" + +process_domain_list "$@" + diff --git a/fetch-all.sh b/fetch-all.sh new file mode 100755 index 0000000..10ccde6 --- /dev/null +++ b/fetch-all.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# perform a "git fetch" on each location specified +# fetch-all.sh ~/project [~/second-project] + +function process_git_fetch () { + BOB=`pwd` + for location in "$@"; do + if [ -d "$location/.git" ]; then + echo -n "----- git fetch $location " + printf "%*.*s" 0 $((40 - ${#location} )) "----------------------------------------" + echo "-----" + cd "$location" + git fetch --prune + fi + done + cd "$BOB" +} + +process_git_fetch "$@" + diff --git a/identify-missing.sh b/identify-missing.sh new file mode 100755 index 0000000..d725d17 --- /dev/null +++ b/identify-missing.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# identify-missing.sh ./* < file_list.txt +# will list all files from file/input which is not present in the given loction. + +while IFS= read -r name; do + [ -n "$(find . -name "$name" -print | head -n 1)" ] || printf '%s\n' "$name" +done + diff --git a/is-restart-needed.sh b/is-restart-needed.sh new file mode 100755 index 0000000..a03bf52 --- /dev/null +++ b/is-restart-needed.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ -f "/var/run/reboot-required" ]; then + echo "----- Reboot Needed ---------------------------------" +else + echo "----- Reboot *Not* Needed ---------------------------" +fi + diff --git a/log/.gitkeep b/log/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/named-cat.sh b/named-cat.sh new file mode 100755 index 0000000..5435c92 --- /dev/null +++ b/named-cat.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# cat given files prefixed with their filenames. +# named-cat.sh file1.txt file2.txt + +tail -n +1 "$@" + diff --git a/one-time-stuff/basic-settings.sh b/one-time-stuff/basic-settings.sh new file mode 100755 index 0000000..ced31ec --- /dev/null +++ b/one-time-stuff/basic-settings.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# configure basic settings, will prompt for input + +echo "----- GIT Global Config, Name and Email -------------" +read -p 'Name for GIT (leave blank to skip): ' git_name +if [[ ! -z "$git_name" ]]; then + echo 'Setting git name' + git config --global user.name "$git_name" +else + echo 'Skipping' +fi + +read -p 'Email for GIT (leave blank to skip): ' git_email +if [[ ! -z "$git_email" ]]; then + echo 'Setting git email' + git config --global user.email "$git_email" +else + echo 'Skipping' +fi + +# ---------------------------------------------------------- + +echo "----- User Groups (requires sudo) -------------------" +read -p 'Add yourself to "www-data" group? [y/N]: ' add_www +case $add_www in + [Yy]* ) + echo 'Adding to group' + sudo usermod -a -G www-data `whoami` + ;; + * ) + echo 'Skipping' + ;; +esac + +# ---------------------------------------------------------- + +echo "----- Install vim configuration ---------------------" +read -p 'Setup vim, colors, defaults, etc? [y/N]: ' set_vim +case $set_vim in + [Yy]* ) + echo 'Appending ~/.bashrc' + ( + cat << 'VIM' + +# ABS default to using vim +export EDITOR=vim +export VISUAL=vim + +VIM +) >> "$HOME/.bashrc" + + echo 'Installing vim color "colorful256"' + mkdir -p "${HOME}/.vim/colors" + LOCATION=`dirname "$0"` + cp "${LOCATION}/vim/colorful256.vim" "${HOME}/.vim/colors/colorful256.vim" + + echo 'Installing vimrc' + if [ -f "${HOME}/.vimrc" ]; then + echo 'existing vimrc file detected, backing up' + mv "${HOME}/.vimrc" "${HOME}/.vimrc_`date +%s`" + fi + cp "${LOCATION}/vim/vimrc" "${HOME}/.vimrc" + ;; + * ) + echo 'Skipping' + ;; +esac + +# ---------------------------------------------------------- + +echo "----- Append prompt style to ~/.bashrc --------------" +read -p 'Add prompt style to bash config? [y/N]: ' add_style +case $add_style in + [Yy]* ) + echo 'Appending ~/.bashrc' + ( + cat << 'STYLE' + +# ABS prompt color dependent on hostname containing "dev" +if [[ $HOSTNAME == *dev* ]] ; then + PS1="\[\033[38;5;9m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\[$(tput sgr0)\]\[\033[38;5;11m\]\h\[$(tput sgr0)\]\[\033[38;5;15m\]:\[$(tput sgr0)\]\[\033[38;5;14m\]\w\[$(tput sgr0)\]\\$ \[$(tput sgr0)\]" +else + PS1="\[\033[38;5;10m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\]@\[$(tput sgr0)\]\[\033[38;5;11m\]\h\[$(tput sgr0)\]\[\033[38;5;15m\]:\[$(tput sgr0)\]\[\033[38;5;14m\]\w\[$(tput sgr0)\]\\$ \[$(tput sgr0)\]" +fi + +STYLE +) >> "$HOME/.bashrc" + ;; + * ) + echo 'Skipping' + ;; +esac + +# ---------------------------------------------------------- + +echo "----- Done ------------------------------------------" +echo "to take effect now, you may need to run:" +echo "source ~/.bashrc" + diff --git a/one-time-stuff/install-software.sh b/one-time-stuff/install-software.sh new file mode 100755 index 0000000..be2e3c0 --- /dev/null +++ b/one-time-stuff/install-software.sh @@ -0,0 +1,82 @@ +#!/bin/bash +# install common software, will prompt before each step + +echo "----- Use nginx straight from nginx.org -------------" +read -p 'Add nginx.org to apt source list? [y/N]: ' add_nginx +case $add_nginx in + [Yy]* ) + echo 'Adding nginx.org' + # check that such a distro/release exists on nginx.org + distro=`lsb_release -i -s | tr '[:upper:]' '[:lower:]'` + release=`lsb_release -c -s` + http_code=`curl -s -o /dev/null --connect-timeout 0.5 -I -w "%{http_code}" "https://nginx.org/packages/$distro/dists/$release/nginx/"` + if [[ "$http_code" == "200" ]]; then + ( + cat << NGINX +deb https://nginx.org/packages/$distro/ $release nginx +deb-src https://nginx.org/packages/$distro/ $release nginx +NGINX +) | sudo tee /etc/apt/sources.list.d/nginx.list + + curl -L https://nginx.org/keys/nginx_signing.key | sudo apt-key add - + else + echo "nginx.org appears to be missing $distro/$release" + fi + ;; + * ) + echo 'Skipping' + ;; +esac + +# ---------------------------------------------------------- + +called_update=false + +function install_collection () { + read -p "Install $1? [y/N]: " response + case $response in + [Yy]* ) + if [ $called_update = false ]; then + echo "Updating APT before Installing" + sudo apt update + called_update=true + fi + echo "Installing $1" + sudo apt install "${@:2}" + ;; + * ) + echo 'Skipping' + ;; + esac +} + +# ---------------------------------------------------------- + +echo "----- Install extra utilities: ncdu, zip ------------" +install_collection 'extra utilities' ncdu zip unzip + +echo "----- Install nginx + php-fpm + certbot -------------" +install_collection 'nginx, php-fpm, certbot' nginx certbot python-certbot-nginx php-cli php-fpm php-curl php-gd php-imagick php-intl php-json php-mbstring php-mysql php-redis php-soap php-xml php-yaml php-zip + +echo "----- Add nginx logging conf ------------------------" +read -p 'Install the "tabbed_detailed" nginx log format? [y/N]: ' nginx_log +case $nginx_log in + [Yy]* ) + LOCATION=`dirname "$0"` + mkdir -p "/etc/nginx/conf.d" + sudo cp "${LOCATION}/nginx/logging.conf" "/etc/nginx/conf.d/logging.conf" + ;; + * ) + echo 'Skipping' + ;; +esac + +echo "----- Install redis-server --------------------------" +install_collection 'redis-server' redis-server + +echo "----- Install mariadb-server ------------------------" +install_collection 'mariadb-server' mariadb-server + +echo "----- Install ruby + build-essential ----------------" +install_collection 'ruby, build-essential' ruby-full build-essential zlib1g-dev + diff --git a/one-time-stuff/nginx/logging.conf b/one-time-stuff/nginx/logging.conf new file mode 100644 index 0000000..b8a2dba --- /dev/null +++ b/one-time-stuff/nginx/logging.conf @@ -0,0 +1,5 @@ +# STOP: FILE CONTAINS \t TABS, TURN OFF EXPAND-TAB IN VIM: set noexpandtab + +# New SSL Log Format, tab separated (useful for "cut" command), also includes host ~ ABS +log_format tabbed_detailed '$remote_addr $remote_user [$time_local] ($ssl_protocol/$ssl_cipher) $host "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'; + diff --git a/one-time-stuff/setup-composer.sh b/one-time-stuff/setup-composer.sh new file mode 100755 index 0000000..e00f5fa --- /dev/null +++ b/one-time-stuff/setup-composer.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# return to where we were when we started +STARTED_IN=`pwd` + +cd ~ + +EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)" +php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" +ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" + +if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ] +then + >&2 echo 'ERROR: Invalid installer signature' + rm composer-setup.php + cd "$STARTED_IN" + exit 1 +fi + +php composer-setup.php --quiet +RESULT=$? +rm composer-setup.php + +if [[ -f "composer.phar" ]]; then + sudo mv composer.phar /usr/bin/composer + echo "Composer successfully installed." +fi + +cd "$STARTED_IN" +exit $RESULT + diff --git a/one-time-stuff/vim/colorful256.vim b/one-time-stuff/vim/colorful256.vim new file mode 100644 index 0000000..c588697 --- /dev/null +++ b/one-time-stuff/vim/colorful256.vim @@ -0,0 +1,89 @@ +" Vim color file: colorful256.vim +" Last Change: 03 Oct, 2007 +" License: public domain +" Maintainer:: Jagpreet +" +" for a 256 color capable terminal +" "{{{ +" You must set t_Co=256 before calling this colorscheme +" +" Color numbers (0-255) see: +" http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html +" +" Added gui colors +" + +if &t_Co != 256 && ! has("gui_running") + echomsg "" + echomsg "colors not loaded first please set t_Co=256 in your .vimrc" + echomsg "" + finish +endif + +set background=dark +hi clear +if exists("syntax_on") + syntax reset +endif + +let g:colors_name = "colorful256" + + highlight Normal cterm=none ctermfg=249 ctermbg=16 gui=none guifg=#b2b2b2 guibg=#000000 + highlight Special cterm=none ctermfg=105 ctermbg=16 gui=none guifg=#8787ff guibg=#000000 + highlight Comment cterm=none ctermfg=3 ctermbg=16 gui=none guifg=#808000 guibg=#000000 + highlight Constant cterm=none ctermfg=9 ctermbg=16 gui=none guifg=#ff0000 guibg=#000000 + highlight LineNr cterm=none ctermfg=48 ctermbg=16 gui=none guifg=#00ff87 guibg=#000000 + highlight Number cterm=none ctermfg=209 ctermbg=16 gui=none guifg=#ff875f guibg=#000000 + highlight PreProc cterm=none ctermfg=10 ctermbg=16 gui=none guifg=#ff00ff guibg=#000000 + highlight Statement cterm=none ctermfg=51 ctermbg=16 gui=none guifg=#00ffff guibg=#000000 + highlight Type cterm=none ctermfg=39 ctermbg=16 gui=none guifg=#00afff guibg=#000000 + highlight Error cterm=none ctermfg=9 ctermbg=16 gui=none guifg=#ff0000 guibg=#000000 + highlight Identifier cterm=none ctermfg=207 ctermbg=16 gui=none guifg=#ff5fff guibg=#000000 + highlight SpecialKey cterm=none ctermfg=36 ctermbg=16 gui=none guifg=#00af87 guibg=#000000 + highlight NonText cterm=none ctermfg=164 ctermbg=16 gui=none guifg=#df00df guibg=#000000 + highlight Directory cterm=none ctermfg=34 ctermbg=16 gui=none guifg=#00af00 guibg=#000000 + highlight ErrorMsg cterm=none ctermfg=9 ctermbg=16 gui=none guifg=#ff0000 guibg=#000000 + highlight MoreMsg cterm=none ctermfg=34 ctermbg=16 gui=none guifg=#00af00 guibg=#000000 + highlight Title cterm=none ctermfg=199 ctermbg=16 gui=none guifg=#ff00af guibg=#000000 + highlight WarningMsg cterm=none ctermfg=9 ctermbg=16 gui=none guifg=#ff0000 guibg=#000000 + highlight DiffDelete cterm=none ctermfg=207 ctermbg=16 gui=none guifg=#ff5fff guibg=#000000 + highlight Search cterm=none ctermfg=15 ctermbg=160 gui=none guifg=#ffffff guibg=#df0000 + highlight Visual cterm=none ctermfg=16 ctermbg=50 gui=none guifg=#000000 guibg=#00ffdf + highlight Cursor cterm=none ctermfg=16 ctermbg=33 gui=none guifg=#000000 guibg=#0087ff + highlight StatusLine cterm=reverse ctermfg=58 ctermbg=15 gui=reverse guifg=#5f5f00 guibg=#ffffff + highlight Question cterm=none ctermfg=16 ctermbg=226 gui=none guifg=#000000 guibg=#ffff00 + highlight Todo cterm=none ctermfg=160 ctermbg=184 gui=none guifg=#df0000 guibg=#dfdf00 + highlight Folded cterm=none ctermfg=15 ctermbg=58 gui=none guifg=#ffffff guibg=#5f5f00 + highlight ModeMsg cterm=none ctermfg=16 ctermbg=46 gui=none guifg=#000000 guibg=#00ff00 + highlight VisualNOS cterm=none ctermfg=16 ctermbg=28 gui=none guifg=#000000 guibg=#008700 + highlight WildMenu cterm=none ctermfg=16 ctermbg=226 gui=none guifg=#000000 guibg=#ffff00 + highlight FoldColumn cterm=none ctermfg=15 ctermbg=58 gui=none guifg=#ffffff guibg=#5f5f00 + highlight SignColumn cterm=none ctermfg=16 ctermbg=28 gui=none guifg=#000000 guibg=#008700 + highlight DiffText cterm=none ctermfg=16 ctermbg=34 gui=none guifg=#000000 guibg=#00af00 + highlight StatusLineNC cterm=reverse ctermfg=131 ctermbg=15 gui=reverse guifg=#af5f5f guibg=#ffffff + highlight VertSplit cterm=reverse ctermfg=172 ctermbg=15 gui=reverse guifg=#df8700 guibg=#ffffff + highlight User1 cterm=none ctermbg=20 ctermfg=15 gui=none guibg=#0000df guifg=#ffffff + highlight User2 cterm=none ctermbg=20 ctermfg=46 gui=none guibg=#0000df guifg=#00ff00 + highlight User3 cterm=none ctermbg=20 ctermfg=46 gui=none guibg=#0000df guifg=#00ff00 + highlight User4 cterm=none ctermbg=20 ctermfg=50 gui=none guibg=#0000df guifg=#00ffdf + highlight User5 cterm=none ctermbg=20 ctermfg=46 gui=none guibg=#0000df guifg=#00ff00 + +" for groups introduced in version 7 +if v:version >= 700 + highlight Pmenu cterm=none ctermfg=16 ctermbg=165 gui=none guifg=#000000 guibg=#df00ff + highlight PmenuSel cterm=none ctermfg=16 ctermbg=220 gui=none guifg=#000000 guibg=#ffdf00 + highlight tablinesel cterm=none ctermfg=15 ctermbg=58 gui=none guifg=#ffffff guibg=#5f5f00 + highlight tabline cterm=none ctermfg=7 ctermbg=58 gui=none guifg=#c0c0c0 guibg=#5f5f00 + highlight tablinefill cterm=none ctermfg=58 ctermbg=58 gui=none guifg=#5f5f00 guibg=#5f5f00 +endif + +"for taglist plugin +" +if exists('loaded_taglist') + highlight TagListTagName cterm=none ctermfg=16 ctermbg=28 gui=none guifg=#000000 guibg=#008700 + highlight TagListTagScope cterm=none ctermfg=16 ctermbg=28 gui=none guifg=#000000 guibg=#008700 + highlight TagListTitle cterm=none ctermfg=199 ctermbg=16 gui=none guifg=#ff00af guibg=#000000 + highlight TagListComment cterm=none ctermfg=16 ctermbg=28 gui=none guifg=#000000 guibg=#008700 + highlight TagListFileName cterm=none ctermfg=15 ctermbg=90 gui=none guifg=#ffffff guibg=#870087 +endif + diff --git a/one-time-stuff/vim/vimrc b/one-time-stuff/vim/vimrc new file mode 100644 index 0000000..ee5acaf --- /dev/null +++ b/one-time-stuff/vim/vimrc @@ -0,0 +1,10 @@ +set tabstop=4 +set shiftwidth=4 +set softtabstop=4 +set expandtab +filetype plugin indent on + +set t_Co=256 +syntax enable +colorscheme colorful256 + diff --git a/public-ip.sh b/public-ip.sh new file mode 100755 index 0000000..e2f8e78 --- /dev/null +++ b/public-ip.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +dig +short ANY myip.opendns.com @resolver1.opendns.com + diff --git a/restart-if-needed.sh b/restart-if-needed.sh new file mode 100755 index 0000000..f83cfee --- /dev/null +++ b/restart-if-needed.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ -f "/var/run/reboot-required" ]; then + echo "----- Reboot Needed ---------------------------------" + if [ $(id -u) = 0 ]; then + reboot + else + sudo reboot + fi +else + echo "----- Reboot *Not* Needed ---------------------------" +fi + diff --git a/singleton.sh b/singleton.sh new file mode 100755 index 0000000..ed52a56 --- /dev/null +++ b/singleton.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# run the given command, but only if it's not already running. +# singleton.sh long_running_script.sh --arguments --allowed + +ALL="$@" + +# if the exact script is not running currently, then start it +if [[ "`pgrep -f -x -c \"${ALL[@]}\"`" -eq "0" ]]; then + LOCATION=`dirname "$0"` + echo "[`date`] Restarting Script: $@" >> "$LOCATION/log/singleton.log" + $1 "${@:2}" +fi + diff --git a/speed-test-ttfb.sh b/speed-test-ttfb.sh new file mode 100755 index 0000000..1425a09 --- /dev/null +++ b/speed-test-ttfb.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# speed-test-ttfb https://www.example.com/ + +curl -w "Connect time: %{time_connect} Time to first byte: %{time_starttransfer} Total time: %{time_total} \n" -s -o /dev/null "$@" + diff --git a/upgrade.sh b/upgrade.sh new file mode 100755 index 0000000..6d4bb62 --- /dev/null +++ b/upgrade.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +echo "----- APT Update ------------------------------------" +sudo apt update + +echo "" +echo "----- APT Upgrade -----------------------------------" +sudo apt upgrade + +echo "" +echo "----- APT DistUpgrade -------------------------------" +sudo apt dist-upgrade + +echo "" +echo "----- APT AutoRemove --------------------------------" +sudo apt autoremove + +echo "" +echo "----- APT AutoClean ---------------------------------" +sudo apt autoclean +