Initial commit

This commit is contained in:
2025-12-06 13:50:26 -06:00
commit 147d3c9cd2
7 changed files with 601 additions and 0 deletions

21
LICENSE.md Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

44
README.md Normal file
View File

@@ -0,0 +1,44 @@
# SH
## Description
Bash scripts and files related to them.
## Table of Contents
- [Description](#description)
- [Features](#features)
- [Usage](#usage)
- [Credits / Resources](#credits--resources)
- [Cheatsheets](#cheatsheets)
- [License](#license)
## Features / TODOS
+ Easy automation
+ Template with flags and params.
+ Bare template with simple logic.
- [ ] TODO Cheat Sheets.<br>
- [ ] TODO Better Examples.<br>
- [ ] TODO Better Usage Guide.<br>
## Usage
To make .sh executable just:<br>
`chmod +x filename.sh` and then execute like this `./filename.sh`<br>
For ease of use add the folder (such as /sh) to your $PATH.<br>
## Credits / Resources
[Bash Cheat Sheet](https://devhints.io/bash)<br>
[Minimal Bash Template](https://betterdev.blog/minimal-safe-bash-script-template/)<br>
[Awesome Cheatsheets](https://github.com/LeCoupa/awesome-cheatsheets/)<br>
[Rehan Saeed - Bash Cheat Sheet](https://github.com/RehanSaeed/Bash-Cheat-Sheet/blob/main/README.md)<br>
[Bash-hackers wiki](https://web.archive.org/web/20230406205817/https://wiki.bash-hackers.org/)<br>
[Shell vars](https://web.archive.org/web/20230318164746/https://wiki.bash-hackers.org/syntax/shellvars)<br>
[Learn bash in y minutes](https://learnxinyminutes.com/docs/bash/)<br>
[Bash Guide](http://mywiki.wooledge.org/BashGuide)<br>
[ShellCheck](https://www.shellcheck.net/)<br>
[Command line Refrence](https://ss64.com/)<br>
[Bash strict mode](https://github.com/guettli/bash-strict-mode)<br>
## License
This project is licensed under MIT - see the [LICENSE](LICENSE) file for details.

99
apt_update.sh Normal file
View File

@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# ERR Trap Inheritance by shell functions, command substitutions, and subshells.
set -E
# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error.
set -e
# Treats the use of undefined variables as an error, causing the script to exit.
set -u
# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails.
set -o pipefail
# Cleaup script.
trap cleanup SIGINT SIGTERM ERR EXIT
# Get the script location and cd to it.
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
# Usage error message.
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
Script description here.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
EOF
exit
}
# Cleaup up script iplementation.
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
# Color setup implementation.
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
# Message helper function implementation.
msg() {
echo >&2 -e "${1-}"
}
# Script exit implementation.
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "\033[0;31m$msg\033[0m"
exit "$code"
}
# Parameter parsing implementation.
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
return 0
}
# ----- Script Start -----
# Parse parameters and setup colors for script.
parse_params "$@"
setup_colors
# ----- Sudo Check -----
sudo -n true
test $? -eq 0 || exit 1 "you should have sudo privilege to run this script"
apt update
apt dist-upgrade -y
apt autoremove
apt clean
exit 0

119
bare_install.sh Normal file
View File

@@ -0,0 +1,119 @@
#!/usr/bin/env bash
# ERR Trap Inheritance by shell functions, command substitutions, and subshells.
set -E
# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error.
set -e
# Treats the use of undefined variables as an error, causing the script to exit.
set -u
# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails.
set -o pipefail
# Cleaup script.
trap cleanup SIGINT SIGTERM ERR EXIT
# Get the script location and cd to it.
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
# Usage error message.
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
Script description here.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
EOF
exit
}
# Cleaup up script iplementation.
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
# Color setup implementation.
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
# Message helper function implementation.
msg() {
echo >&2 -e "${1-}"
}
# Script exit implementation.
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "\033[0;31m$msg\033[0m"
exit "$code"
}
# Parameter parsing implementation.
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
return 0
}
# ----- Script Start -----
# Parse parameters and setup colors for script.
parse_params "$@"
setup_colors
# ----- Sudo Check -----
sudo -n true
test $? -eq 0 || exit 1 "you should have sudo privilege to run this script"
apt update
apt install sudo -y
apt install gpg -y
apt install zsh -y
apt install tmux -y
apt install vim-gtk3 -y
apt install git -y
apt install fzf -y
apt install universal-ctags -y
apt install curl -y
apt install wget -y
apt install zip -y
apt install unzip -y
apt install dpkg -y
apt install tar -y
apt install gzip -y
apt install coreutils -y
apt install build-essential -y
exit 0

122
full_install.sh Normal file
View File

@@ -0,0 +1,122 @@
#!/usr/bin/env bash
# ERR Trap Inheritance by shell functions, command substitutions, and subshells.
set -E
# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error.
set -e
# Treats the use of undefined variables as an error, causing the script to exit.
set -u
# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails.
set -o pipefail
# Cleaup script.
trap cleanup SIGINT SIGTERM ERR EXIT
# Get the script location and cd to it.
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
# Usage error message.
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
Script description here.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
EOF
exit
}
# Cleaup up script iplementation.
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
# Color setup implementation.
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
# Message helper function implementation.
msg() {
echo >&2 -e "${1-}"
}
# Script exit implementation.
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "\033[0;31m$msg\033[0m"
exit "$code"
}
# Parameter parsing implementation.
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
return 0
}
# ----- Script Start -----
# Parse parameters and setup colors for script.
parse_params "$@"
setup_colors
# ----- Sudo Check -----
sudo -n true
test $? -eq 0 || exit 1 "you should have sudo privilege to run this script"
apt update
apt install sudo -y
apt install gpg -y
apt install zsh -y
apt install tmux -y
apt install vim-gtk3 -y
apt install git -y
apt install fzf -y
apt install universal-ctags -y
apt install curl -y
apt install wget -y
apt install zip -y
apt install unzip -y
apt install dpkg -y
apt install tar -y
apt install gzip -y
apt install coreutils -y
apt install build-essential -y
apt install freecad -y
apt install kicad -y
exit 0

105
full_template.sh Normal file
View File

@@ -0,0 +1,105 @@
#!/usr/bin/env bash
# ERR Trap Inheritance by shell functions, command substitutions, and subshells.
set -E
# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error.
set -e
# Treats the use of undefined variables as an error, causing the script to exit.
set -u
# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails.
set -o pipefail
# Cleaup script.
trap cleanup SIGINT SIGTERM ERR EXIT
# Get the script location and cd to it.
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
# Usage error message.
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
Script description here.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
-f, --flag Some flag value
-p, --param Some param description
EOF
exit
}
# Cleaup up script iplementation.
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
# Color setup implementation.
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
# Message helper function implementation.
msg() {
echo >&2 -e "${1-}"
}
# Script exit implementation.
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "\033[0;31m$msg\033[0m"
exit "$code"
}
# Parameter parsing implementation.
parse_params() {
flag=0
param=''
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-f | --flag) flag=1 ;; # example flag
-p | --param) # example named parameter
param="${2-}"
shift
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
# check required params and arguments
[[ -z "${param-}" ]] && die "Missing required parameter: param"
[[ ${#args[@]} -eq 0 ]] && die "Missing script arguments"
return 0
}
# ----- Script Start -----
# Parse parameters and setup colors for script.
parse_params "$@"
setup_colors
# Script logic example here.
msg "${GREEN}Read parameters:${NOFORMAT}"
msg "- flag: ${flag}"
msg "- param: ${param}"
msg "- arguments: ${args[*]-}"
exit 0

91
template.sh Normal file
View File

@@ -0,0 +1,91 @@
#!/usr/bin/env bash
# ERR Trap Inheritance by shell functions, command substitutions, and subshells.
set -E
# Exit on Error Causes the script to immediately exit if any command returns a non-zero exit status unless that command is followed by || to explicitly handle the error.
set -e
# Treats the use of undefined variables as an error, causing the script to exit.
set -u
# Ensures that a pipeline (a series of commands connected by |) fails if any command within it fails, rather than only failing if the last command fails.
set -o pipefail
# Cleaup script.
trap cleanup SIGINT SIGTERM ERR EXIT
# Get the script location and cd to it.
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
# Usage error message.
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
Script description here.
Available options:
-h, --help Print this help and exit
-v, --verbose Print script debug info
EOF
exit
}
# Cleaup up script iplementation.
cleanup() {
trap - SIGINT SIGTERM ERR EXIT
# script cleanup here
}
# Color setup implementation.
setup_colors() {
if [[ -t 2 ]] && [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]; then
NOFORMAT='\033[0m' RED='\033[0;31m' GREEN='\033[0;32m' ORANGE='\033[0;33m' BLUE='\033[0;34m' PURPLE='\033[0;35m' CYAN='\033[0;36m' YELLOW='\033[1;33m'
else
NOFORMAT='' RED='' GREEN='' ORANGE='' BLUE='' PURPLE='' CYAN='' YELLOW=''
fi
}
# Message helper function implementation.
msg() {
echo >&2 -e "${1-}"
}
# Script exit implementation.
die() {
local msg=$1
local code=${2-1} # default exit status 1
msg "\033[0;31m$msg\033[0m"
exit "$code"
}
# Parameter parsing implementation.
parse_params() {
while :; do
case "${1-}" in
-h | --help) usage ;;
-v | --verbose) set -x ;;
--no-color) NO_COLOR=1 ;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
return 0
}
# ----- Script Start -----
# Parse parameters and setup colors for script.
parse_params "$@"
setup_colors
# Script logic example here.
msg "${GREEN}Read parameters:${NOFORMAT}"
exit 0