Initial Commit.

This commit is contained in:
2019-11-15 19:27:27 +00:00
parent 468ce973b5
commit a2b57b2426
18 changed files with 467 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
/log/singleton.log
+52
View File
@@ -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 "$@"
Executable
+20
View File
@@ -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 "$@"
+8
View File
@@ -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
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
if [ -f "/var/run/reboot-required" ]; then
echo "----- Reboot Needed ---------------------------------"
else
echo "----- Reboot *Not* Needed ---------------------------"
fi
View File
Executable
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
# cat given files prefixed with their filenames.
# named-cat.sh file1.txt file2.txt
tail -n +1 "$@"
+99
View File
@@ -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"
+82
View File
@@ -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
+5
View File
@@ -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"';
+31
View File
@@ -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
+89
View File
@@ -0,0 +1,89 @@
" Vim color file: colorful256.vim
" Last Change: 03 Oct, 2007
" License: public domain
" Maintainer:: Jagpreet<jagpreetc AT gmail DOT com>
"
" 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
+10
View File
@@ -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
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/bin/bash
dig +short ANY myip.opendns.com @resolver1.opendns.com
+13
View File
@@ -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
Executable
+13
View File
@@ -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
+5
View File
@@ -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 "$@"
Executable
+21
View File
@@ -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