mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-09 21:53:47 -05:00
Reformatting
This commit is contained in:
@@ -42,6 +42,7 @@ hasHomebrew () {
|
||||
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||
brew tap homebrew/dupes
|
||||
brew tap homebrew/versions
|
||||
brew tap argon/mas
|
||||
else
|
||||
die "Without Homebrew installed we won't get very far."
|
||||
fi
|
||||
@@ -130,7 +131,7 @@ function doInstall () {
|
||||
if [[ "${list}" ]]; then
|
||||
seek_confirmation "Confirm each package before installing?"
|
||||
if is_confirmed; then
|
||||
for item in ${list[@]}
|
||||
for item in "${list[@]}"
|
||||
do
|
||||
seek_confirmation "Install ${item}?"
|
||||
if is_confirmed; then
|
||||
@@ -142,12 +143,12 @@ function doInstall () {
|
||||
brew tap tldr-pages/tldr
|
||||
brew install tldr
|
||||
else
|
||||
${INSTALLCOMMAND} ${item}
|
||||
${INSTALLCOMMAND} "${item}"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
else
|
||||
for item in ${list[@]}
|
||||
for item in "${list[@]}"
|
||||
do
|
||||
notice "Installing ${item}"
|
||||
# FFMPEG takes additional flags
|
||||
@@ -157,7 +158,7 @@ function doInstall () {
|
||||
brew tap tldr-pages/tldr
|
||||
brew install tldr
|
||||
else
|
||||
${INSTALLCOMMAND} ${item}
|
||||
${INSTALLCOMMAND} "${item}"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -82,16 +82,17 @@ function convertsecs() {
|
||||
printf "%02d:%02d:%02d\n" $h $m $s
|
||||
}
|
||||
|
||||
# pushover
|
||||
# ------------------------------------------------------
|
||||
# Sends notifications view Pushover
|
||||
# Requires a file named 'pushover.cfg' be placed in '../etc/'
|
||||
#
|
||||
# Usage: pushover "Title Goes Here" "Message Goes Here"
|
||||
#
|
||||
# Credit: http://ryonsherman.blogspot.com/2012/10/shell-script-to-send-pushover.html
|
||||
# ------------------------------------------------------
|
||||
function pushover() {
|
||||
# pushover
|
||||
# ------------------------------------------------------
|
||||
# Sends notifications view Pushover
|
||||
# Requires a file named 'pushover.cfg' be placed in '../etc/'
|
||||
#
|
||||
# Usage: pushover "Title Goes Here" "Message Goes Here"
|
||||
#
|
||||
# Credit: http://ryonsherman.blogspot.com/2012/10/shell-script-to-send-pushover.html
|
||||
# ------------------------------------------------------
|
||||
|
||||
# Check for config file containing API Keys
|
||||
if [ ! -f "${SOURCEPATH}/../etc/pushover.cfg" ]; then
|
||||
error "Please locate the pushover.cfg to send notifications to Pushover."
|
||||
@@ -469,20 +470,20 @@ squeeze_lines() {
|
||||
sed '/^[[:space:]]\+$/s/.*//g' | cat -s | trim_lines
|
||||
}
|
||||
|
||||
# progressBar
|
||||
# -----------------------------------
|
||||
# Prints a progress bar within a for/while loop.
|
||||
# To use this function you must pass the total number of
|
||||
# times the loop will run to the function.
|
||||
#
|
||||
# usage:
|
||||
# for number in $(seq 0 100); do
|
||||
# sleep 1
|
||||
# progressBar 100
|
||||
# done
|
||||
# -----------------------------------
|
||||
|
||||
progressBar() {
|
||||
# progressBar
|
||||
# -----------------------------------
|
||||
# Prints a progress bar within a for/while loop.
|
||||
# To use this function you must pass the total number of
|
||||
# times the loop will run to the function.
|
||||
#
|
||||
# usage:
|
||||
# for number in $(seq 0 100); do
|
||||
# sleep 1
|
||||
# progressBar 100
|
||||
# done
|
||||
# -----------------------------------
|
||||
if [[ "${quiet}" = "true" ]] || [ "${quiet}" == "1" ]; then
|
||||
return
|
||||
fi
|
||||
@@ -565,6 +566,38 @@ urldecode() {
|
||||
printf '%b' "${url_encoded//%/\x}"
|
||||
}
|
||||
|
||||
parse_yaml() {
|
||||
# Function to parse YAML files and add values to variables. Send it to a temp file and source it
|
||||
# https://gist.github.com/epiloque/8cf512c6d64641bde388
|
||||
#
|
||||
# Usage:
|
||||
# $ parse_yaml sample.yml > /some/tempfile
|
||||
#
|
||||
# parse_yaml accepts a prefix argument so that imported settings all have a common prefix
|
||||
# (which will reduce the risk of namespace collisions).
|
||||
#
|
||||
# $ parse_yaml sample.yml "CONF_"
|
||||
|
||||
local prefix=$2
|
||||
local s
|
||||
local w
|
||||
local fs
|
||||
s='[[:space:]]*'
|
||||
w='[a-zA-Z0-9_]*'
|
||||
fs="$(echo @|tr @ '\034')"
|
||||
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
|
||||
-e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
|
||||
awk -F"$fs" '{
|
||||
indent = length($1)/2;
|
||||
vname[indent] = $2;
|
||||
for (i in vname) {if (i > indent) {delete vname[i]}}
|
||||
if (length($3) > 0) {
|
||||
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
||||
printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
|
||||
}
|
||||
}' | sed 's/_=/+=/g'
|
||||
}
|
||||
|
||||
httpStatus() {
|
||||
# -----------------------------------
|
||||
# Shamelessly taken from: https://gist.github.com/rsvp/1171304
|
||||
|
||||
30
lib/utils.sh
30
lib/utils.sh
@@ -36,29 +36,15 @@ function _alert() {
|
||||
if [ "${1}" = "emergency" ]; then
|
||||
local color="${bold}${red}"
|
||||
fi
|
||||
if [ "${1}" = "error" ] || [ "${1}" = "warning" ]; then
|
||||
local color="${red}"
|
||||
fi
|
||||
if [ "${1}" = "success" ]; then
|
||||
local color="${green}"
|
||||
fi
|
||||
if [ "${1}" = "debug" ]; then
|
||||
local color="${purple}"
|
||||
fi
|
||||
if [ "${1}" = "header" ]; then
|
||||
local color="${bold}""${tan}"
|
||||
fi
|
||||
if [ "${1}" = "input" ]; then
|
||||
local color="${bold}"
|
||||
printLog="0"
|
||||
fi
|
||||
if [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then
|
||||
local color="" # Us terminal default color
|
||||
fi
|
||||
if [ "${1}" = "error" ]; then local color="${bold}${red}"; fi
|
||||
if [ "${1}" = "warning" ]; then local color="${red}"; fi
|
||||
if [ "${1}" = "success" ]; then local color="${green}"; fi
|
||||
if [ "${1}" = "debug" ]; then local color="${purple}"; fi
|
||||
if [ "${1}" = "header" ]; then local color="${bold}""${tan}"; fi
|
||||
if [ "${1}" = "input" ]; then local color="${bold}"; printLog="false"; fi
|
||||
if [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then local color=""; fi
|
||||
# Don't use colors on pipes or non-recognized terminals
|
||||
if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then
|
||||
color=""; reset=""
|
||||
fi
|
||||
if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then color=""; reset=""; fi
|
||||
|
||||
# Print to $logFile
|
||||
if [[ ${printLog} = "true" ]] || [ "${printLog}" == "1" ]; then
|
||||
|
||||
Reference in New Issue
Block a user