mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 13:13: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)"
|
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||||
brew tap homebrew/dupes
|
brew tap homebrew/dupes
|
||||||
brew tap homebrew/versions
|
brew tap homebrew/versions
|
||||||
|
brew tap argon/mas
|
||||||
else
|
else
|
||||||
die "Without Homebrew installed we won't get very far."
|
die "Without Homebrew installed we won't get very far."
|
||||||
fi
|
fi
|
||||||
@@ -130,7 +131,7 @@ function doInstall () {
|
|||||||
if [[ "${list}" ]]; then
|
if [[ "${list}" ]]; then
|
||||||
seek_confirmation "Confirm each package before installing?"
|
seek_confirmation "Confirm each package before installing?"
|
||||||
if is_confirmed; then
|
if is_confirmed; then
|
||||||
for item in ${list[@]}
|
for item in "${list[@]}"
|
||||||
do
|
do
|
||||||
seek_confirmation "Install ${item}?"
|
seek_confirmation "Install ${item}?"
|
||||||
if is_confirmed; then
|
if is_confirmed; then
|
||||||
@@ -142,12 +143,12 @@ function doInstall () {
|
|||||||
brew tap tldr-pages/tldr
|
brew tap tldr-pages/tldr
|
||||||
brew install tldr
|
brew install tldr
|
||||||
else
|
else
|
||||||
${INSTALLCOMMAND} ${item}
|
${INSTALLCOMMAND} "${item}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
for item in ${list[@]}
|
for item in "${list[@]}"
|
||||||
do
|
do
|
||||||
notice "Installing ${item}"
|
notice "Installing ${item}"
|
||||||
# FFMPEG takes additional flags
|
# FFMPEG takes additional flags
|
||||||
@@ -157,7 +158,7 @@ function doInstall () {
|
|||||||
brew tap tldr-pages/tldr
|
brew tap tldr-pages/tldr
|
||||||
brew install tldr
|
brew install tldr
|
||||||
else
|
else
|
||||||
${INSTALLCOMMAND} ${item}
|
${INSTALLCOMMAND} "${item}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -82,16 +82,17 @@ function convertsecs() {
|
|||||||
printf "%02d:%02d:%02d\n" $h $m $s
|
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() {
|
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
|
# Check for config file containing API Keys
|
||||||
if [ ! -f "${SOURCEPATH}/../etc/pushover.cfg" ]; then
|
if [ ! -f "${SOURCEPATH}/../etc/pushover.cfg" ]; then
|
||||||
error "Please locate the pushover.cfg to send notifications to Pushover."
|
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
|
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() {
|
||||||
|
# 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
|
if [[ "${quiet}" = "true" ]] || [ "${quiet}" == "1" ]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -565,6 +566,38 @@ urldecode() {
|
|||||||
printf '%b' "${url_encoded//%/\x}"
|
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() {
|
httpStatus() {
|
||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
# Shamelessly taken from: https://gist.github.com/rsvp/1171304
|
# 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
|
if [ "${1}" = "emergency" ]; then
|
||||||
local color="${bold}${red}"
|
local color="${bold}${red}"
|
||||||
fi
|
fi
|
||||||
if [ "${1}" = "error" ] || [ "${1}" = "warning" ]; then
|
if [ "${1}" = "error" ]; then local color="${bold}${red}"; fi
|
||||||
local color="${red}"
|
if [ "${1}" = "warning" ]; then local color="${red}"; fi
|
||||||
fi
|
if [ "${1}" = "success" ]; then local color="${green}"; fi
|
||||||
if [ "${1}" = "success" ]; then
|
if [ "${1}" = "debug" ]; then local color="${purple}"; fi
|
||||||
local color="${green}"
|
if [ "${1}" = "header" ]; then local color="${bold}""${tan}"; fi
|
||||||
fi
|
if [ "${1}" = "input" ]; then local color="${bold}"; printLog="false"; fi
|
||||||
if [ "${1}" = "debug" ]; then
|
if [ "${1}" = "info" ] || [ "${1}" = "notice" ]; then local color=""; fi
|
||||||
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
|
|
||||||
# Don't use colors on pipes or non-recognized terminals
|
# Don't use colors on pipes or non-recognized terminals
|
||||||
if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then
|
if [[ "${TERM}" != "xterm"* ]] || [ -t 1 ]; then color=""; reset=""; fi
|
||||||
color=""; reset=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Print to $logFile
|
# Print to $logFile
|
||||||
if [[ ${printLog} = "true" ]] || [ "${printLog}" == "1" ]; then
|
if [[ ${printLog} = "true" ]] || [ "${printLog}" == "1" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user