~dricottone/my-utils

276445b8cea1f67b788dcfc599f68b2467d40c46 — Dominic Ricottone 3 years ago 598fcd5
Added networking scripts (i.e. vpn*); Updated style of most scripts
M Makefile => Makefile +19 -1
@@ 7,6 7,7 @@ install: clean
	install -m755 src/myparse.bash $(LIB_DIR)/myparse.bash
	install -m755 src/myminiparse.sh $(LIB_DIR)/myminiparse.sh
	install -m755 src/unittest-color.awk $(LIB_DIR)/unittest-color.awk

	install -m755 src/android-emulator $(BIN_DIR)/android-emulator
	install -m755 src/check-x $(BIN_DIR)/check-x
	install -m755 src/ctdir $(BIN_DIR)/ctdir


@@ 16,8 17,8 @@ install: clean
	install -m755 src/docker-get-exited $(BIN_DIR)/docker-get-exited
	install -m755 src/docker-restart $(BIN_DIR)/docker-restart
	install -m755 src/docker-up $(BIN_DIR)/docker-up
	install -m755 src/epub $(BIN_DIR)/epub
	install -m755 src/enumerate $(BIN_DIR)/enumerate
	install -m755 src/epub $(BIN_DIR)/epub
	install -m755 src/fw-status $(BIN_DIR)/fw-status
	install -m755 src/mkbak $(BIN_DIR)/mkbak
	install -m755 src/mktar $(BIN_DIR)/mktar


@@ 26,30 27,39 @@ install: clean
	install -m755 src/pactl-volume-down $(BIN_DIR)/pactl-volume-down
	install -m755 src/pactl-volume-printf $(BIN_DIR)/pactl-volume-printf
	install -m755 src/pactl-volume-up $(BIN_DIR)/pactl-volume-up
	install -m755 src/pingable $(BIN_DIR)/pingable
	install -m755 src/qemu-test $(BIN_DIR)/qemu-test
	install -m755 src/rand $(BIN_DIR)/rand
	install -m755 src/rebom $(BIN_DIR)/rebom
	install -m755 src/rmtar $(BIN_DIR)/rmtar
	install -m755 src/rmzip $(BIN_DIR)/rmzip
	install -m755 src/start-at $(BIN_DIR)/start-at
	install -m755 src/stop-at $(BIN_DIR)/stop-at
	install -m755 src/tarcat $(BIN_DIR)/tarcat
	install -m755 src/tarls $(BIN_DIR)/tarls
	install -m755 src/unittest $(BIN_DIR)/unittest
	install -m755 src/untar $(BIN_DIR)/untar
	install -m755 src/vimsplit $(BIN_DIR)/vimsplit
	install -m755 src/vpn-off $(BIN_DIR)/vpn-off
	install -m755 src/vpn-on $(BIN_DIR)/vpn-on
	install -m755 src/wg-off $(BIN_DIR)/wg-off
	install -m755 src/wg-on $(BIN_DIR)/wg-on
	install -m755 src/wg-status $(BIN_DIR)/wg-status
	install -m755 src/wg-test $(BIN_DIR)/wg-test
	install -m755 src/whichcat $(BIN_DIR)/whichcat
	install -m755 src/whiched $(BIN_DIR)/whiched
	install -m755 src/whichhead $(BIN_DIR)/whichhead
	install -m755 src/whichvi $(BIN_DIR)/whichvi
	install -m755 src/whisper $(BIN_DIR)/whisper
	install -m755 src/wttr $(BIN_DIR)/wttr
	install -m755 src/zipls $(BIN_DIR)/zipls

uninstall:
	rm $(LIB_DIR)/mylib.bash
	rm $(LIB_DIR)/myparse.bash
	rm $(LIB_DIR)/myminiparse.sh
	rm $(LIB_DIR)/unittest-color.awk

	rm $(BIN_DIR)/android-emulator
	rm $(BIN_DIR)/check-x
	rm $(BIN_DIR)/ctdir


@@ 69,24 79,32 @@ uninstall:
	rm $(BIN_DIR)/pactl-volume-down
	rm $(BIN_DIR)/pactl-volume-printf
	rm $(BIN_DIR)/pactl-volume-up
	rm $(BIN_DIR)/pingable
	rm $(BIN_DIR)/qemu-test
	rm $(BIN_DIR)/rand
	rm $(BIN_DIR)/rebom
	rm $(BIN_DIR)/rmtar
	rm $(BIN_DIR)/rmzip
	rm $(BIN_DIR)/start-at
	rm $(BIN_DIR)/stop-at
	rm $(BIN_DIR)/tarcat
	rm $(BIN_DIR)/tarls
	rm $(BIN_DIR)/unittest
	rm $(BIN_DIR)/untar
	rm $(BIN_DIR)/vimsplit
	rm $(BIN_DIR)/vpn-off
	rm $(BIN_DIR)/vpn-on
	rm $(BIN_DIR)/wg-off
	rm $(BIN_DIR)/wg-on
	rm $(BIN_DIR)/wg-status
	rm $(BIN_DIR)/wg-test
	rm $(BIN_DIR)/whichcat
	rm $(BIN_DIR)/whiched
	rm $(BIN_DIR)/whichhead
	rm $(BIN_DIR)/whichvi
	rm $(BIN_DIR)/whisper
	rm $(BIN_DIR)/wttr
	rm $(BIN_DIR)/zipls

test: clean static-test-files
	shellcheck src/*.bash src/*.sh $(LIB_DIR)/mylib.bash $(LIB_DIR)/myparse.bash $(LIB_DIR)/myminiparse.sh

M README.md => README.md +80 -26
@@ 4,32 4,86 @@ A set of scripts that I use frequently. Written in a mix of shell (some POSIX sh



## Scripts

Executable |Description                                                   |Extra Dependencies
:----------|:-------------------------------------------------------------|:------------------------------------------
check-x    |Check if an X11 server is running
ctdir      |Count entries in a target directory(ies)
debom      |Remove BOM from a target file                                 |`bash`
enumerate  |Dumps HTML from an 'epub' e-book archive                      |`bash`, `zipinfo`, `unzip`, `w3m`
epub       |Rename files in current directory into sequential numbers     |`bash`
mkbak      |Create a backup of a target file                              |`bash`
mktar      |Wrapper around `tar` for easier compression                   |`bash` *
rand       |Get a random number within an inclusive range                 |`shuf`
rebom      |Add BOM to a target file                                      |
rmtar      |Delete 'tar' archive files
rmzip      |Delete 'zip' archive files
stop-at    |Re-print until a pattern is matched
tarcat     |Print contents of target archive file(s)                      |*
tarls      |Print listings of target archive file(s)                      |*
unittest   |Wrapper around Python's `unittest` module                     |`python3`, GNU or New (AT&T) `awk`
untar      |Wrapper around `tar` for easier decompression                 |*
whichcat   |Print all lines from a program
whiched    |Open a program with your editor
whichhead  |Print the first 10 lines from a program                       |`bash`
whichvi    |Open a program with your visual editor
whisper    |Wrapper around `espeak` to mirror `say` in macOS              |`espeak`
wttr       |Wrapper around `wttr` to fix double-wide runes for some fonts |`wego`
## General-Use Scripts

Executable|Description                                                   |Extra Dependencies
:---------|:-------------------------------------------------------------|:------------------------------------------
check-x   |Check if an X11 server is running
ctdir     |Count entries in a target directory(ies)
debom     |Remove BOM from a target file                                 |`bash`
enumerate |Dumps HTML from an 'epub' e-book archive                      |`bash`, `zipinfo`, `unzip`, `w3m`
epub      |Rename files in current directory into sequential numbers     |`bash`
fw-status |Print current firewall status                                 |`ufw`
mkbak     |Create a backup of a target file                              |`bash`
mktar     |Wrapper around `tar` for easier compression                   |`bash` *
pingable  |Check if an address/name is ping-able
rand      |Get a random number within an inclusive range                 |`bash`, `shuf`
rebom     |Add BOM to a target file                                      |
rmtar     |Delete 'tar' archive files
rmzip     |Delete 'zip' archive files
start-at  |After a pattern is matched, re-print                          |GNU or New (AT&T) `awk`
stop-at   |Re-print until a pattern is matched                           |GNU or New (AT&T) `awk`
tarcat    |Print contents of `tar` archive file(s)                       |*
tarls     |List files within `tar` archive file(s)                       |*
unittest  |Wrapper around Python's `unittest` module                     |`python3`, GNU or New (AT&T) `awk`
untar     |Wrapper around `tar` for easier decompression                 |*
vimsplit  |Open two files in split windows                               |`nvim`
whichcat  |Print all lines from a program
whiched   |Open a program with your editor
whichhead |Print the first 10 lines from a program                       |`bash`
whichvi   |Open a program with your visual editor
whisper   |Wrapper around `espeak` to mirror `say` in macOS              |`espeak`
wttr      |Wrapper around `wttr` to fix double-wide runes for some fonts |`wego`
zipls     |List files within `zip` archive file(s)                       |`zipinfo`


## Emulator Scripts

Executable       |Description                                            |Extra Dependencies
:----------------|:------------------------------------------------------|:-----------------
android-emulator |Start an Android emulator session                      |`adb`
qemu-test        |Check if hardware and OS are capable of virtualization |


## Docker Scripts

The following all depend on `docker`.

Executable        |Description                                                 |Extra Dependencies
:-----------------|:-----------------------------------------------------------|:-----------------
docker-clean      |Stop all containers, remove all images, and clear the cache |
docker-get-all    |List all Docker containers' IDs                             |
docker-get-exited |List all exited Docker containers' IDs                      |
docker-restart    |Restart all exited Docker containers                        |
docker-up         |Start a Docker container using `./docker-compose.yml`       |`docker-compose`


## Pulseaudio Scripts

The following all depend on `pactl`.

Executable            |Description                                          |Extra Dependencies
:---------------------|:----------------------------------------------------|:-----------------
pactl-get-running-sink|Get the currently running Pulseaudio sink ID         |
pactl-mute            |Toggle mute on the currently running Pulseaudio sink |
pactl-volume-down     |Reduce volume (default: 10%)                         |
pactl-volume-printf   |Print the currently running Pulseaudio sink volume   |
pactl-volume-up       |Increase volume (default: 10%)                       |


## VPN Scripts

Executable|Description                                               |Extra Dependencies
:---------|:---------------------------------------------------------|:-----------------
vpn-off   |Stop all OpenVPN connections                              |`killall`
vpn-on    |Start an OpenVPN connection using `$MYUTILS_OPENVPN_CONF` |`openvpn`
wg-off    |Stop the `wg0` Wireguard connection                       |`wg`, `wg-quick`
wg-on     |Start the `wg0` Wireguard connection                      |`wg`, `wg-quick`
wg-status |Print current Wireguard connection status                 |`wg`
wg-test   |Check if Wireguard connection is on and working           |`wg`


## Notes

\* *While you **technically** won't run into an error, these scripts **do** expect `tar` to support Zstandard, which isn't necessarily POSIX standard.*


M bash-completion/mybashcompletion.bash => bash-completion/mybashcompletion.bash +7 -5
@@ 24,17 24,19 @@ _epub_completion() {
# Complete with function, and fallback to filenames
complete -o default -F _epub_completion epub

# rmzip
# Complete with filenames matching pattern '*.zip', and fallback to filenames
complete -o default -f -X '!*.zip' rmzip
# rmzip, zipls
# Complete with filenames matching pattern '*.@(zip|cbr|epub)', and fallback to
# filenames
complete -o default -f -X '!*.@(zip|cbr|epub)' rmzip

# untar, tarcat, rmtar
# rmtar, tarcat, tarls, untar
# Complete with filenames matching pattern
# '*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)', and fallback to
# filenames
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' rmtar
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' tarcat
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' tarls
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' untar
complete -o default -f -X '!*.@(tar|tar.@(gz|xz|zst|bz2)|tar.@(gz|xz|zst|bz2).gpg)' rmtar

# whichcat, whiched. whichhead, whichvi
# Complete with program names

M src/android-emulator => src/android-emulator +13 -0
@@ 1,5 1,18 @@
#!/bin/sh

name="android-emulator"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Start an Android emulator session
	Usage: android-emulator
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

adb start-server
trap "adb kill-server" EXIT


M src/check-x => src/check-x +3 -0
@@ 6,6 6,9 @@ version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Check if an X11 server is running
	Usage: check-x
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)


M src/docker-clean => src/docker-clean +17 -0
@@ 1,6 1,23 @@
#!/bin/sh

name="docker-clean"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Stop all containers, remove all images, and clear the cache
	Usage: docker-clean
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

# Stop all containers to mark everything as prune-able
for id in $(docker ps --all --quiet); do
  docker rm "$id" --force
done

# Prune
docker system prune --all --force


M src/docker-get-all => src/docker-get-all +14 -0
@@ 1,3 1,17 @@
#!/bin/sh

name="docker-get-all"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	List all Docker containers' IDs
	Usage: docker-get-all
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

docker ps --format "{{.ID}}" --all


M src/docker-get-exited => src/docker-get-exited +14 -0
@@ 1,3 1,17 @@
#!/bin/sh

name="docker-get-exited"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	List all exited Docker containers' IDs
	Usage: docker-get-exited
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

docker ps --format "{{.ID}}" --filter exited=1 --all


M src/docker-restart => src/docker-restart +14 -0
@@ 1,4 1,18 @@
#!/bin/sh

name="docker-restart"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Restart all exited Docker containers
	Usage: docker-restart
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

for container in $(docker-get-exited); do
  docker start "$container"
done

M src/docker-up => src/docker-up +14 -0
@@ 1,3 1,17 @@
#!/bin/sh

name="docker-up"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Start a Docker container using './docker-compose.yml'.
	Usage: docker-up
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

docker-compose up --detach


M src/fw-status => src/fw-status +14 -0
@@ 1,3 1,17 @@
#!/bin/sh

name="fw-status"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Print current firewall status
	Usage: fw-status
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

sudo ufw status


M src/pactl-get-running-sink => src/pactl-get-running-sink +13 -0
@@ 1,4 1,17 @@
#!/bin/sh

name="pactl-get-running-sink"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Get the currently running Pulseaudio sink ID
	Usage: pactl-get-running-sink
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

pactl list sinks short | grep -F 'RUNNING' | cut -f 1


M src/pactl-mute => src/pactl-mute +13 -0
@@ 1,5 1,18 @@
#!/bin/sh

name="pactl-mute"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Toggle mute on the currently running Pulseaudio sink
	Usage: pactl-mute
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

SINK="$(pactl-get-running-sink)"
if [ -z "$SINK" ]; then
  SINK=0

M src/pactl-volume-down => src/pactl-volume-down +13 -0
@@ 1,5 1,18 @@
#!/bin/sh

name="pactl-volume-down"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Reduce volume (default: 10%)
	Usage: pactl-volume-down [PERCENT]
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

SINK="$(pactl-get-running-sink)"
if [ -z "$SINK" ]; then
  SINK=0

M src/pactl-volume-printf => src/pactl-volume-printf +13 -0
@@ 1,5 1,18 @@
#!/bin/sh

name="pactl-volume-printf"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Print the currently running Pulseaudio sink volume
	Usage: pactl-volume-printf [FORMAT]
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

volumes=$(pactl list sinks \
  | grep -F 'Volume:' \
  | grep -o -e '[0-9]\+%' \

M src/pactl-volume-up => src/pactl-volume-up +13 -0
@@ 1,5 1,18 @@
#!/bin/sh

name="pactl-volume-up"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Increase volume (default: 10%)
	Usage: pactl-volume-up [PERCENT]
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

SINK="$(pactl-get-running-sink)"
if [ -z "$SINK" ]; then
  SINK=0

A src/pingable => src/pingable +23 -0
@@ 0,0 1,23 @@
#!/bin/sh

name="pingable"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Check if an address or name is ping-able
	Usage: pingable [ ADDRESS | NAME ]
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

# Note: `ping` will set the return code to...
#  0 on success
#  1 on failure to ping
#  2 on name resolution failure for most (i.e. Linux) platforms
# 68 on name resolution failure for some (i.e. macOS) platforms

. /usr/local/lib/myminiparse.sh

ping -c 1 $1 >/dev/null 2>&1


A src/qemu-test => src/qemu-test +35 -0
@@ 0,0 1,35 @@
#!/bin/sh

name="qemu-test"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Check if hardware and OS are capable of virtualization
	Usage: qemu-test
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

printf_then_exec() {
  printf "%s\n" "$1"
  $1
}

if ! LC_ALL=C lscpu | grep Virtualization >/dev/null 2>&1; then
  printf "Virtualization is not supported by the CPU\n"
  printf_then_exec "LC_ALL=C lscpu | grep Virtualization"
  exit 1
elif ! zgrep CONFIG_KVM /proc/config.gz >/dev/null 2>&1; then
  printf "Virtualization is not supported by the kernel\n"
  printf_then_exec "zgrep CONFIG_KVM /proc/config.gz"
  exit 1
elif ! lsmod | grep kvm >/dev/null 2>&1; then
  printf "Kernel modules for virtualization support are not loaded\n"
  printf_then_exec "lsmod | grep kvm"
  exit 1
fi
exit 0


A src/start-at => src/start-at +23 -0
@@ 0,0 1,23 @@
#!/bin/awk -f

# start-at
# ===========
# Usage: <command> | start-at -v pattern='^-+$'
#
# After a pattern is matched, re-print.

BEGIN {
  if (pattern == "" || inclusive !~ /^[01]?$/) {
    print "Usage: start-at -v pattern=PATTERN -v inclusive=0|1"
    exit 1
  }
  matched=0
}
{
  if (matched==1) print;
  if ($0 ~ pattern) {
    matched=1;
    if (inclusive==1) print;
  }
}


M src/tarls => src/tarls +1 -1
@@ 3,7 3,7 @@
name="tarls"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Wrapper around 'tar' for easier listing
	List files within 'tar' archive file(s)
	Usage: tarls TARGET [..] [OPTIONS]
	Options:
	 -h, --help     print this message and exit

M src/vimsplit => src/vimsplit +0 -0
A src/vpn-off => src/vpn-off +17 -0
@@ 0,0 1,17 @@
#!/bin/sh

name="vpn-off"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Stop the OpenVPN connection
	Usage: vpn-off
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

sudo killall openvpn


A src/vpn-on => src/vpn-on +17 -0
@@ 0,0 1,17 @@
#!/bin/sh

name="vpn-on"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Start an OpenVPN connection using '\$MYUTILS_OPENVPN_CONF'
	Usage: vpn-on
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

sudo openvpn --config "$MYUTILS_OPENVPN_CONF" --daemon


M src/wg-off => src/wg-off +14 -0
@@ 1,4 1,18 @@
#!/bin/sh

name="wg-off"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Stop the 'wg0' Wireguard connection
	Usage: wg-off
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

sudo wg-quick down wg0
sudo wg show


M src/wg-on => src/wg-on +14 -0
@@ 1,4 1,18 @@
#!/bin/sh

name="wg-on"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Start the 'wg0' Wireguard connection
	Usage: wg-on
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

sudo wg-quick up wg0
sudo wg show


M src/wg-status => src/wg-status +14 -0
@@ 1,3 1,17 @@
#!/bin/sh

name="wg-status"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Print current Wireguard connection status
	Usage: wg-status
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

sudo wg show


A src/wg-test => src/wg-test +32 -0
@@ 0,0 1,32 @@
#!/bin/sh

name="wg-test"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	Check if Wireguard connection is on and working
	Usage: wg-test
	Options:
	 -h, --help     print this message and exit
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

if [ $(wg-status | wc -l) -le 1 ]; then
  printf "Wireguard is not running\n"
  exit 1
fi

# NOTE: assume that Wireguard configurations use 10.0.0.0/24, just like pretty
# much all upstream documentation

if ! pingable 10.0.0.1; then
  printf "Wireguard server is not reachable; try checking...\n"
  printf " - if the server is running\n"
  printf " - if the server can ping peers\n"
  printf " - if the server firewall is blocking connections\n"
  exit 1
fi
exit 0


A src/zipls => src/zipls +41 -0
@@ 0,0 1,41 @@
#!/bin/sh

name="zipls"
version="1.0"
help_message=$(/usr/bin/cat <<-EOF
	List files within 'zip' archive file(s)
	Usage: zipls TARGET [..] [OPTIONS]
	Options:
	 -h, --help     print this message and exit
	 -q, --quiet    suppress error messages
	 -v, --version  print version number and exit
EOF
)

. /usr/local/lib/myminiparse.sh

# error if no directory names given
if [ "$#" -eq 0 ]; then
  (>&2 /usr/bin/printf "Usage: zipls TARGET [OPTIONS]\n")
  exit 1
elif [ "$#" -eq 1 ] && [ "$quiet" -eq 1 ]; then
  exit 1
fi

# main routine
code=0
for target; do
  if [ ! -f "$target" ]; then
    if [ "$quiet" -eq 0 ]; then
      (>&2 printf "%s: No such file '%s'\n" "$name" "$target")
    fi
    code=1
  else
    if ! zipinfo -1 "$target"; then
      code=1
    fi
  fi
done

exit "$code"