From 147d3c9cd264b86196f83dbea51b9273dd08d8f0 Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Sat, 6 Dec 2025 13:50:26 -0600 Subject: [PATCH] Initial commit --- LICENSE.md | 21 ++++++++ README.md | 44 +++++++++++++++++ apt_update.sh | 99 ++++++++++++++++++++++++++++++++++++++ bare_install.sh | 119 +++++++++++++++++++++++++++++++++++++++++++++ full_install.sh | 122 +++++++++++++++++++++++++++++++++++++++++++++++ full_template.sh | 105 ++++++++++++++++++++++++++++++++++++++++ template.sh | 91 +++++++++++++++++++++++++++++++++++ 7 files changed, 601 insertions(+) create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 apt_update.sh create mode 100644 bare_install.sh create mode 100644 full_install.sh create mode 100644 full_template.sh create mode 100644 template.sh diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f23b18 --- /dev/null +++ b/README.md @@ -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.
+- [ ] TODO Better Examples.
+- [ ] TODO Better Usage Guide.
+ +## Usage +To make .sh executable just:
+`chmod +x filename.sh` and then execute like this `./filename.sh`
+For ease of use add the folder (such as /sh) to your $PATH.
+ + +## Credits / Resources +[Bash Cheat Sheet](https://devhints.io/bash)
+[Minimal Bash Template](https://betterdev.blog/minimal-safe-bash-script-template/)
+[Awesome Cheatsheets](https://github.com/LeCoupa/awesome-cheatsheets/)
+[Rehan Saeed - Bash Cheat Sheet](https://github.com/RehanSaeed/Bash-Cheat-Sheet/blob/main/README.md)
+[Bash-hackers wiki](https://web.archive.org/web/20230406205817/https://wiki.bash-hackers.org/)
+[Shell vars](https://web.archive.org/web/20230318164746/https://wiki.bash-hackers.org/syntax/shellvars)
+[Learn bash in y minutes](https://learnxinyminutes.com/docs/bash/)
+[Bash Guide](http://mywiki.wooledge.org/BashGuide)
+[ShellCheck](https://www.shellcheck.net/)
+[Command line Refrence](https://ss64.com/)
+[Bash strict mode](https://github.com/guettli/bash-strict-mode)
+ + +## License +This project is licensed under MIT - see the [LICENSE](LICENSE) file for details. diff --git a/apt_update.sh b/apt_update.sh new file mode 100644 index 0000000..4f2ddbe --- /dev/null +++ b/apt_update.sh @@ -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 <&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 diff --git a/bare_install.sh b/bare_install.sh new file mode 100644 index 0000000..2321a74 --- /dev/null +++ b/bare_install.sh @@ -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 <&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 diff --git a/full_install.sh b/full_install.sh new file mode 100644 index 0000000..0fbc956 --- /dev/null +++ b/full_install.sh @@ -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 <&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 diff --git a/full_template.sh b/full_template.sh new file mode 100644 index 0000000..e9be244 --- /dev/null +++ b/full_template.sh @@ -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 <&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 diff --git a/template.sh b/template.sh new file mode 100644 index 0000000..acfe8d7 --- /dev/null +++ b/template.sh @@ -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 <&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