Format shell scripts with shfmt

This commit is contained in:
2020-05-23 21:36:17 +01:00
parent a34e2d370e
commit cdef65ae53
30 changed files with 219 additions and 211 deletions

View File

@@ -5,7 +5,6 @@ set -e
PACKAGE_LIST_CMD="brew cask list"
PACKAGE_INSTALL_CMD="brew cask install"
#
# Package list
#
@@ -136,7 +135,6 @@ PERSONAL_PKGS=(
yakyak
)
#
# Main
#
@@ -155,7 +153,6 @@ main() {
fi
}
#
# The rest...
#

View File

@@ -5,7 +5,6 @@ set -e
PACKAGE_LIST_CMD="brew list"
PACKAGE_INSTALL_CMD="brew install"
#
# Package list
#
@@ -63,7 +62,6 @@ PERSONAL_PKGS=(
"mkvtoolnix --with-qt"
)
#
# Main
#
@@ -78,7 +76,6 @@ main() {
fi
}
#
# The rest...
#

View File

@@ -15,7 +15,7 @@ icon="$3"
if [ -z "$name" ] || [ -z "$url" ]; then
echo 'usage: create-chrome-ssb "Google Music"' \
'"https://play.google.com/music"'
'"https://play.google.com/music"'
exit 1
fi
@@ -31,11 +31,10 @@ if [ -d "$app_path" ]; then
exit 1
fi
# Various paths used when creating the app.
resource_dir="${app_path}/Contents/Resources"
exec_dir="${app_path}/Contents/MacOS"
exec_file="${exec_dir}/${name//[[:space:]]}"
exec_file="${exec_dir}/${name//[[:space:]]/}"
plist_file="${app_path}/Contents/Info.plist"
app_support="\${HOME}/Library/Application Support"
@@ -46,10 +45,10 @@ bundle_identifier="me.jimeh.chrome-ssb.${name}"
mkdir -p "$resource_dir" "$exec_dir"
# convert the icon and copy into Resources
if [ -f "$icon" ] ; then
if [ -f "$icon" ]; then
sips -s format tiff "$icon" \
--out "${resource_dir}/icon.tiff" \
--resampleWidth 128 >& /dev/null
--out "${resource_dir}/icon.tiff" \
--resampleWidth 128 >&/dev/null
tiff2icns -noLarge "${resource_dir}/icon.tiff" >&/dev/null
if [ -f "${resource_dir}/icon.tiff" ]; then
@@ -58,7 +57,7 @@ if [ -f "$icon" ] ; then
fi
# Create the executable.
cat > "$exec_file" <<EOF
cat > "$exec_file" << EOF
#!/bin/sh
mkdir -p "${profile_dir}"
exec "${chrome_path}" \\
@@ -70,7 +69,7 @@ EOF
chmod +x "$exec_file"
# Create the Info.plist.
cat > "$plist_file" <<EOF
cat > "$plist_file" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>

View File

@@ -1,13 +1,13 @@
#! /usr/bin/env bash
set -e
abs_dirname () {
abs_dirname() {
local path="$1"
local cwd
cwd="$(pwd)"
while [ -n "$path" ]; do
cd "${path%/*}" 2>/dev/null
cd "${path%/*}" 2> /dev/null
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
@@ -16,16 +16,16 @@ abs_dirname () {
cd "$cwd"
}
abs_path () {
abs_path() {
local path="$1"
echo "$(cd "$(abs_dirname "$path")" && pwd)/$(basename "$path")"
}
resolve_link () {
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
resolve_dest () {
resolve_dest() {
local dest="$1"
if [ -z "$dest" ]; then
@@ -42,7 +42,7 @@ resolve_dest () {
echo "$dest"
}
resolve_dest_dir () {
resolve_dest_dir() {
local dest="$1"
local dir
@@ -55,7 +55,7 @@ resolve_dest_dir () {
echo "$dir"
}
help () {
help() {
echo "usage: docker-volume-backup <volume> [<output-filename>]"
echo ""
echo "Backs up contents of a Docker volume to a gzipped tar archive."
@@ -66,7 +66,7 @@ help () {
echo " Defaults to: ./<volume>_<date>_<time>.tar.gz"
}
main () {
main() {
local volname="$1"
local dest="$2"
local dest_dir
@@ -76,7 +76,7 @@ main () {
exit 1
fi
if ! docker volume inspect "$volname" &>/dev/null; then
if ! docker volume inspect "$volname" &> /dev/null; then
echo "ERROR: Volume \"${volname}\" does not exist." 1>&2
exit 1
fi
@@ -87,10 +87,10 @@ main () {
echo "Starting volume backup to: ${dest}"
docker run --rm \
--volume "${volname}:/source/${volname}" \
--volume "${dest_dir}:/target" \
alpine:latest \
sh -c "cd /source && tar -cvzf \"/target/${dest_file}\" \"${volname}\""
--volume "${volname}:/source/${volname}" \
--volume "${dest_dir}:/target" \
alpine:latest \
sh -c "cd /source && tar -cvzf \"/target/${dest_file}\" \"${volname}\""
echo "Volume \"${volname}\" was backed up to: ${dest}"
}

View File

@@ -1,13 +1,13 @@
#! /usr/bin/env bash
set -e
abs_dirname () {
abs_dirname() {
local path="$1"
local cwd
cwd="$(pwd)"
while [ -n "$path" ]; do
cd "${path%/*}" 2>/dev/null
cd "${path%/*}" 2> /dev/null
local name="${path##*/}"
path="$(resolve_link "$name" || true)"
done
@@ -16,12 +16,12 @@ abs_dirname () {
cd "$cwd"
}
abs_path () {
abs_path() {
local path="$1"
echo "$(cd "$(abs_dirname "$path")" && pwd)/$(basename "$path")"
}
resolve_link () {
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
@@ -38,7 +38,7 @@ resolve_archive() {
echo "$archive"
}
resolve_volname () {
resolve_volname() {
local archive="$1"
local file
local dir
@@ -47,13 +47,13 @@ resolve_volname () {
dir="$(dirname "$archive")"
docker run --rm \
--volume "${dir}:/source" \
alpine:latest \
sh -c "tar --exclude=\"*/*/*\" -tzf \"/source/${file}\" \
| grep -v '^[^/]\+/[^/]\+$' | sed s'/.$//'" 2>/dev/null
--volume "${dir}:/source" \
alpine:latest \
sh -c "tar --exclude=\"*/*/*\" -tzf \"/source/${file}\" \
| grep -v '^[^/]\+/[^/]\+$' | sed s'/.$//'" 2> /dev/null
}
help () {
help() {
echo "usage: docker-volume-restore <archive> [<volume-name>]"
echo ""
echo "Restores contents from a *.tar.gz archive to a Docker volume."
@@ -66,7 +66,7 @@ help () {
echo " top-level directory in the archive."
}
main () {
main() {
local archive="$1"
local volname="$2"
local archive_volname
@@ -92,19 +92,19 @@ main () {
volname="$archive_volname"
fi
if docker volume inspect "$volname" &>/dev/null; then
if docker volume inspect "$volname" &> /dev/null; then
echo "ERROR: Volume \"${volname}\" already exists." 1>&2
exit 1
fi
echo "Restoring volume ${volume} from: ${archive_file}"
docker volume create "$volname"
echo "Restoring volume ${volname} from: ${archive_file}"
docker volume create "${volname}"
docker run --rm \
--volume "${volname}:/target" \
--volume "${archive_dir}:/source" \
alpine:latest \
sh -c "cd /target && tar --strip-components=1 \
-xvzf \"/source/${archive_file}\""
--volume "${volname}:/target" \
--volume "${archive_dir}:/source" \
alpine:latest \
sh -c "cd /target && tar --strip-components=1 \
-xvzf \"/source/${archive_file}\""
echo "Volume \"${volname}\" was restored from: ${archive_file}"
}

View File

@@ -15,20 +15,19 @@ if [ -f "/Applications/Emacs.app/Contents/MacOS/bin/emacsclient" ]; then
EMACSCLIENT="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
fi
# Functions
start () {
EMACS_GUI_SERVER=1 env $EMACS \
start() {
EMACS_GUI_SERVER=1 env "$EMACS" \
--eval "(setq server-socket-dir \"$SOCKET_DIR\")" --daemon
}
stop () {
stop() {
env $EMACSCLIENT -s "$SOCKET_FILE" --eval "(kill-emacs)"
}
status () {
status() {
echo -n 'Emacs GUI Server... '
! result="$(eval $EMACSCLIENT -s "$SOCKET_FILE" --eval \"\(print \'OK\)\" 2>/dev/null)"
! result="$(eval $EMACSCLIENT -s "$SOCKET_FILE" --eval \"\(print \'OK\)\" 2> /dev/null)"
if [[ $result == "OK" ]]; then
echo 'RUNNING'
else

View File

@@ -11,4 +11,4 @@ fi
# Execute emacsclient
exec env TERM=screen-24bit \
$EMACSCLIENT --alternate-editor=$ALTERNATE_EDITOR "$@"
$EMACSCLIENT --alternate-editor=$ALTERNATE_EDITOR "$@"

View File

@@ -7,9 +7,8 @@
# content, at your own risk of course :) --jimeh
#
padlen=13
ipaddress=$1
ipaddress="$1"
if [[ "$1" == "--raw" ]] || [[ "$1" == "-r" ]]; then
padlen=0
@@ -19,7 +18,7 @@ elif [[ "$2" == "--raw" ]] || [[ "$2" == "-r" ]]; then
fi
case "$1" in
"-h" | "--help" )
"-h" | "--help")
echo "usage: geoiptool [<ipaddress>]"
echo ""
echo "Options:"
@@ -28,8 +27,8 @@ case "$1" in
echo "Look up details for given IP address via http://www.geoiptool.com/. If no IP"
echo "address is given, your own public IP will be used instead."
;;
* )
curl -s "http://www.geoiptool.com/en/?IP=${ipaddress}" -H "User-Agent: " | \
*)
curl -s "http://www.geoiptool.com/en/?IP=${ipaddress}" -H "User-Agent: " |
awk -F '(</?[^>]+>)+' \
"/Host Name/,/Latitude/ {
if (/:/) {

View File

@@ -10,7 +10,7 @@ main() {
commits="$(git rev-list "$ref")"
for commit in $commits; do
files="$(git diff-tree --no-commit-id --name-only -r $commit)"
files="$(git diff-tree --no-commit-id --name-only -r "$commit")"
for file in $files; do
echo "${commit}: $file"
done

52
bin/hr
View File

@@ -4,43 +4,39 @@
#
# Copyright (c) 2013 Gil Gonçalves
#
# 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:
# 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.
# 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.
function hr() {
for i in $(seq 1 "$(tput cols)"); do
echo -n "$1"
done
function hr {
for i in $(seq 1 $(tput cols));
do
echo -n "$1";
done
echo ""
echo ""
}
if [[ -n "$1" ]]; then
space_string="$1"
string_size="${#space_string}"
if [[ -n $1 ]]; then
space_string=$1
string_size=${#space_string};
for char_index in $(seq 0 $(expr ${string_size} - 1));
do
hr ${space_string:char_index:1}
done
for char_index in $(seq 0 "$(expr "${string_size}" - 1)"); do
hr "${space_string:char_index:1}"
done
else
hr "="
hr "="
fi

View File

@@ -46,25 +46,25 @@ OPT_ALL=""
parse-arguments() {
while getopts ":p:e:w:bah" opt; do
case ${opt} in
p )
p)
OPT_PROC="$OPTARG"
;;
e )
e)
OPT_BIN="$OPTARG"
;;
w )
w)
OPT_WIN="$OPTARG"
;;
b )
b)
OPT_BRING="1"
;;
a )
a)
OPT_ALL="1"
;;
h )
h)
show-help
;;
\? )
\?)
error-help "Invalid option: -${OPTARG}\n" 1>&2
exit 1
;;
@@ -81,7 +81,7 @@ parse-arguments() {
OPT_BIN="$OPT_PROC"
fi
if ! command -v "$OPT_BIN" &>/dev/null; then
if ! command -v "$OPT_BIN" &> /dev/null; then
error "\"${OPT_BIN}\" does not seem to be a valid executable."
exit 2
fi

View File

@@ -3,7 +3,7 @@
# Parse confx files and generate the conf files.
for file in $HOME/.logrotate.d/*.confx; do
content="$(eval "echo \"$(cat "$file")\"")"
echo "$content" > ${file/%.confx/.conf}
echo "$content" > "${file/%.confx/.conf}"
done
# Run logrorate like normal against conf files.

View File

@@ -1,6 +1,6 @@
#! /usr/bin/env bash
if bundle check &>/dev/null && (bundle list | grep rubocop &>/dev/null); then
if bundle check &> /dev/null && (bundle list | grep rubocop &> /dev/null); then
exec bundle exec rubocop "$@"
else
exec rubocop "$@"

View File

@@ -1,24 +1,28 @@
#! /usr/bin/env bash
if [ -z $1 ]; then
if [ -z "$1" ]; then
echo "usage: smart-health-check <device>"
exit 1
fi
trim() {
local string="$@"
local string="$*"
string="${string#"${string%%[![:space:]]*}"}"
string="${string%"${string##*[![:space:]]}"}"
echo -n "$string"
}
check-status() {
local raw_status="$(smartctl -H $1)"
local status="$(echo "$raw_status" | grep "^SMART overall-health")"
local device="$1"
local raw_status
local status
raw_status="$(smartctl -H "$device")"
status="$(echo "$raw_status" | grep "^SMART overall-health")"
if [[ "$(trim "$status")" != *"PASSED" ]]; then
echo "$(tput setaf 1)SMART Status: FAIL:$(tput sgr0)" \
"smartctl -H $1:"
"smartctl -H ${device}:"
echo ""
echo "$raw_status"
exit 3
@@ -26,23 +30,27 @@ check-status() {
}
check-attributes() {
local device="$1"
local attr
local fail=0
local raw_status="$(smartctl -A $1)"
local report="$(echo "$raw_status" | grep "^ID# ")"
local raw_status
local report
raw_status="$(smartctl -A "$device")"
report="$(echo "$raw_status" | grep "^ID# ")"
for id in 1 5 10 196 197 198; do
attr="$(echo "$raw_status" | grep "^\s*${id}\s")"
if [ -n "$(trim "$attr")" ] && [[ "$(trim "$attr")" != *" 0" ]]; then
fail=1
report="$report\n$attr"
report="${report}\n${attr}"
fi
done
if [ $fail != 0 ]; then
echo "$(tput setaf 2)SMART Status: PASSED:$(tput sgr0)" \
"$(tput setaf 1)- may FAIL soon:$(tput sgr0)" \
"smartctl -A $1:"
"$(tput setaf 1)- may FAIL soon:$(tput sgr0)" \
"smartctl -A ${device}:"
echo ""
echo -e "$report"
exit 2
@@ -50,10 +58,11 @@ check-attributes() {
}
main() {
check-status $1
check-attributes $1
local device="$1"
check-status "$device"
check-attributes "$device"
echo "SMART Status: $(tput setaf 2)PASSED$(tput sgr0)"
}
main $@

View File

@@ -3,6 +3,6 @@
count=1
echo "====> Attempt $count"
while "$@"; do
(( count++ ))
((count++))
echo "====> Attempt $count"
done