From 8f29682a896e7c9061681ccb3e875de7acc16a76 Mon Sep 17 00:00:00 2001 From: bt3 Date: Wed, 27 Jun 2018 11:20:48 -0700 Subject: [PATCH] Add some random scripts in my machine --- network/check_port.sh | 23 +++++++ shell_scripts/useful/check_time_zone.sh | 9 +++ ubuntu/post_install_ubuntu.sh | 88 +++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 network/check_port.sh create mode 100644 shell_scripts/useful/check_time_zone.sh create mode 100644 ubuntu/post_install_ubuntu.sh diff --git a/network/check_port.sh b/network/check_port.sh new file mode 100644 index 0000000..83213e4 --- /dev/null +++ b/network/check_port.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# Check a whether a port is open or not +# +# then use the script in your tests like +# check_port 9200 + +function check_port() { + local host=${1} && shift + local port=${1} && shift + local retries=5 + local wait=1 + + until( nc -zv "${host}" "${port}" ); do + ((retries--)) + if [ $retries -lt 0 ]; then + echo "Service ${host}:${port} didn't become ready in time." + exit 1 + fi + sleep "${wait}" + done +} + +check_port "localhost" "$@" \ No newline at end of file diff --git a/shell_scripts/useful/check_time_zone.sh b/shell_scripts/useful/check_time_zone.sh new file mode 100644 index 0000000..de37c26 --- /dev/null +++ b/shell_scripts/useful/check_time_zone.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Set a random timezone +TZ_SIGN=$( echo "+:-" | cut -d: -f "$( shuf -i 1-2 -n 1 )" ) +TZ=UTC${TZ_SIGN}$( shuf -i 0-24 -n1 ) + +export TZ + +echo "Set TZ to: ${TZ}" \ No newline at end of file diff --git a/ubuntu/post_install_ubuntu.sh b/ubuntu/post_install_ubuntu.sh new file mode 100644 index 0000000..b52d5ef --- /dev/null +++ b/ubuntu/post_install_ubuntu.sh @@ -0,0 +1,88 @@ +#!/bin/bash + + +# Post-installation bash script for Ubuntu + + +tabs 4 + + +TITLE="Ubuntu Post-Install Script" + + +function main { + echo_message header "Starting 'main' function" + # Draw window + MAIN=$(eval `resize` && whiptail \ + --notags \ + --title "$TITLE" \ + --menu "\nWhat would you like to do?" \ + --cancel-button "Quit" \ + $LINES $COLUMNS $(( $LINES - 12 )) \ + 'system_update' 'Perform system updates' \ + 'install_favs' 'Install preferred applications' \ + 'install_favs_dev' 'Install preferred development tools' \ + 'install_favs_utils' 'Install preferred utilities' \ + 'install_gnome' 'Install preferred GNOME software' \ + 'install_codecs' 'Install multimedia codecs' \ + 'install_fonts' 'Install additional fonts' \ + 'install_snap_apps' 'Install Snap applications' \ + 'install_flatpak_apps' 'Install Flatpak applications' \ + 'install_thirdparty' 'Install third-party applications' \ + 'setup_dotfiles' 'Configure dotfiles' \ + 'system_configure' 'Configure system' \ + 'system_cleanup' 'Cleanup the system' \ + 3>&1 1>&2 2>&3) + # check exit status + if [ $? = 0 ]; then + echo_message header "Starting '$MAIN' function" + $MAIN + else + # Quit + quit + fi +} + +# Quit +function quit { + echo_message header "Starting 'quit' function" + echo_message title "Exiting $TITLE..." + # Draw window + if (whiptail --title "Quit" --yesno "Are you sure you want quit?" 8 56) then + echo_message welcome 'Thanks for using!' + exit 99 + else + main + fi +} + +# Import Functions +function import_functions { + DIR="functions" + # iterate through the files in the 'functions' folder + for FUNCTION in $(dirname "$0")/$DIR/*; do + # skip directories + if [[ -d $FUNCTION ]]; then + continue + # exclude markdown readmes + elif [[ $FUNCTION == *.md ]]; then + continue + elif [[ -f $FUNCTION ]]; then + # source the function file + . $FUNCTION + fi + done +} + +# Import main functions +import_functions +# Welcome message +echo_message welcome "$TITLE" +# Run system checks +system_checks +# main +while : +do + main +done +