[HOME] [DOWNLOAD] [DOCS] [BLOG] [SUPPORT] [TIPS] [ISSUES] [Priority Support]

Favourite (whonix?) bash script boilerplate template?


#1

Anyone have a favourite bash script boilerplate template?

Includes usage, parameter parsing, whatever else can be thought of?

Or favourite whonix script that exemplifies more of the ‘whonix way’ than others?

Seems every time I write bash I reinvent the wheel.

If I can follow any whonix standard / convention from the get go, things will be smoother / more palatable, so this seemed a prudent question to ask up front.

[No flamewar intended.]


#2

Perhaps get https://github.com/Whonix/Whonix and submodules. Then you’ll have all the packages. Then have a glimpse at various bash scripts.

grep --exclude-dir=.git '#!/bin/bash'

parse cmd example:

usage help:

parse config folder example:

error handler example:

mostly useful conventions:

  • mostly for useful for bigger scripts
  • set -e (to have tight control over exit codes)
  • have an err trap
  • set -o pipefail (when using at least one pipe)

Run scripts through shellcheck and fix whatever makes sense. (Apart from false positives and other non-issues.)

Deepening on task.

  • A very simple script: https://github.com/Whonix/sdwdate/blob/master/usr/lib/sdwdate/suspend-pre
  • a more complex example would be whonixcheck (supports sourceing a config folder, sources the script snippet folder, therefore allows overwriting/extending shell functions, allows to skip shell functions by name (whonixcheck_skip_functions), input detection cli vs gui, and more)

Don’t make it a science. As long as it’s secure, readable and good enough, I don’t think we should to be overly strict.


#3

Only 100. Interesting.

Whonix/buildconfig.d/30_apt_sources.conf
Whonix/buildconfig.d/30_apt_opts.conf
Whonix/debian/gain-root-command
Whonix/debian/whonix.postinst
Whonix/build-steps.d/1150_export-libvirt-xml
Whonix/build-steps.d/2800_create-report
Whonix/build-steps.d/1100_prepare-build-machine
Whonix/build-steps.d/1700_install-packages
Whonix/build-steps.d/2700_export-vbox-vm
Whonix/build-steps.d/2400_convert-raw-to-qcow2
Whonix/build-steps.d/2300_run-chroot-scripts-post-d
Whonix/build-steps.d/2500_convert-raw-to-vdi
Whonix/build-steps.d/1200_create-debian-packages
Whonix/build-steps.d/1300_create-raw-image
Whonix/build-steps.d/2600_create-vbox-vm
Whonix/changelog.upstream
Whonix/whonix_build
Whonix/make-helper-overrides.bsh
Whonix/help-steps/unmount-raw-force
Whonix/help-steps/gain-root-command
Whonix/help-steps/delete-qcow
Whonix/help-steps/unprevent-daemons-from-starting
Whonix/help-steps/chroot-raw
Whonix/help-steps/git_sanity_test
Whonix/help-steps/variables
Whonix/help-steps/prevent-daemons-from-starting
Whonix/help-steps/cleanup-files
Whonix/help-steps/unmount-raw
Whonix/help-steps/delete-vbox-vm
Whonix/help-steps/umount_kill.sh
Whonix/help-steps/analyze_image
Whonix/help-steps/gpg_test_sign
Whonix/help-steps/mount-raw
Whonix/help-steps/create-local-temp-apt-repo
Whonix/help-steps/unchroot-raw
Whonix/help-steps/whonix_build_one
Whonix/help-steps/pre
Whonix/help-steps/colors
Whonix/help-steps/remove-local-temp-apt-repo
Whonix/help-steps/parse-cmd
Whonix/help-steps/package-sign-cmd
anon-meta-packages/debian/gain-root-command
sdwdate/debian/gain-root-command
sdwdate/debian/sdwdate.postrm
sdwdate/debian/sdwdate.postinst
sdwdate/usr/lib/sdwdate/restart_fresh
sdwdate/usr/lib/sdwdate/sclockadj_kill_helper
sdwdate/usr/lib/sdwdate/clock-fix
sdwdate/usr/lib/sdwdate/suspend-post
sdwdate/usr/lib/sdwdate/sclockadj_debug_helper
sdwdate/usr/lib/sdwdate/suspend-pre
whonix-gw-firewall/debian/gain-root-command
whonix-gw-firewall/debian/whonix-gw-firewall.postinst
whonix-gw-firewall/usr/lib/gateway-shortcuts/firewall50user
whonix-gw-firewall/usr/lib/gateway-shortcuts/firewall30default
whonix-gw-firewall/usr/lib/gateway-shortcuts/reloadfirewall
whonix-gw-firewall/usr/bin/whonix_firewall
whonixcheck/debian/whonixcheck.postinst
whonixcheck/debian/gain-root-command
whonixcheck/usr/lib/whonixcheck/check_pvclock.bsh
whonixcheck/usr/lib/whonixcheck/help_cli.bsh
whonixcheck/usr/lib/whonixcheck/check_news.bsh
whonixcheck/usr/lib/whonixcheck/check_control_port_filter.bsh
whonixcheck/usr/lib/whonixcheck/uwt_tool.bsh
whonixcheck/usr/lib/whonixcheck/check_tor_socks_or_trans_port.bsh
whonixcheck/usr/lib/whonixcheck/check_initializer.bsh
whonixcheck/usr/lib/whonixcheck/check_operating_system.bsh
whonixcheck/usr/lib/whonixcheck/root_check.bsh
whonixcheck/usr/lib/whonixcheck/check_whonixsetup_done.bsh
whonixcheck/usr/lib/whonixcheck/check_qubes.bsh
whonixcheck/usr/lib/whonixcheck/process_killer_helper.bsh
whonixcheck/usr/lib/whonixcheck/preparation.bsh
whonixcheck/usr/lib/whonixcheck/check_ip_forwarding_disabled.bsh
whonixcheck/usr/lib/whonixcheck/check_tor_socks_port_reachability.bsh
whonixcheck/usr/lib/whonixcheck/cleanup.bsh
whonixcheck/usr/lib/whonixcheck/check_tor_bootstrap.bsh
whonixcheck/usr/lib/whonixcheck/check_hostname.bsh
whonixcheck/usr/lib/whonixcheck/check_stream_isolation.bsh
whonixcheck/usr/lib/whonixcheck/check_tor_config.bsh
whonixcheck/usr/lib/whonixcheck/check_virtualizer.bsh
whonixcheck/usr/lib/whonixcheck/function_manual_run.bsh
whonixcheck/usr/lib/whonixcheck/check_package_manager_running.bsh
whonixcheck/usr/lib/whonixcheck/check_tor_enabled.bsh
whonixcheck/usr/lib/whonixcheck/pin_ssl_cert.bsh
whonixcheck/usr/lib/whonixcheck/check_systemd_clock.bsh
whonixcheck/usr/lib/whonixcheck/check_tor_pid.bsh
whonixcheck/usr/lib/whonixcheck/check_apt_repository.bsh
whonixcheck/usr/lib/whonixcheck/check_logs.bsh
whonixcheck/usr/lib/whonixcheck/parse_cmd.bsh
whonixcheck/usr/lib/whonixcheck/check_torbrowser.bsh
whonixcheck/usr/lib/whonixcheck/check_entropy.bsh
whonixcheck/usr/lib/whonixcheck/check_timezone.bsh
whonixcheck/usr/lib/whonixcheck/disclaimer.bsh
whonixcheck/usr/lib/whonixcheck/donate.bsh
whonixcheck/usr/lib/whonixcheck/autostart.bsh
whonixcheck/usr/lib/whonixcheck/check_packages.bsh
whonixcheck/usr/lib/apt-get-wrapper
whonixcheck/usr/lib/apt-get-update
whonixcheck/usr/lib/whonixcheckdaemon
whonixcheck/usr/bin/whonixcheck

Oops. Overlooked submodules … (git clone --recursive). WIth (Whonix/Whonix) submodules it goes up to 458.