Last active
August 29, 2015 14:20
-
-
Save jesperronn/06d5a2855265c8d057c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
BASEDIR=$(dirname $0) | |
. $BASEDIR/functions.sh | |
# step "Remounting / and /boot as read-write:" | |
# try mount -o remount,rw / | |
# try mount -o remount,rw /boot | |
# next | |
# | |
# usecases: | |
# * verify an expression exits exitcode 0 | |
# * verify a certain string occurs (with grep) | |
# * verify a certain string does not occur | |
check_vboxnet() { | |
ifconfig |grep vboxnet 2>&1 > /dev/null | |
} | |
step "nmap installed" | |
try which nmap | |
next | |
step "vboxnet interface must exist" | |
try check_vboxnet | |
next | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this file is based directly on suggesion by John Kugelman in | |
# http://stackoverflow.com/a/5196220/109305 | |
# | |
#. /etc/init.d/functions | |
BASEDIR=$(dirname $0) | |
. $BASEDIR/initd_functions.sh | |
# Use step(), try(), and next() to perform a series of commands and print | |
# [ OK ] or [FAILED] at the end. The step as a whole fails if any individual | |
# command fails. | |
# | |
# Example: | |
# step "Remounting / and /boot as read-write:" | |
# try mount -o remount,rw / | |
# try mount -o remount,rw /boot | |
# next | |
step() { | |
echo -n "$@" | |
STEP_OK=0 | |
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$ | |
} | |
try() { | |
# Check for `-b' argument to run command in the background. | |
local BG= | |
[[ $1 == -b ]] && { BG=1; shift; } | |
[[ $1 == -- ]] && { shift; } | |
# Run the command. | |
if [[ -z $BG ]]; then | |
"$@" | |
else | |
"$@" & | |
fi | |
# Check if command failed and update $STEP_OK if so. | |
local EXIT_CODE=$? | |
if [[ $EXIT_CODE -ne 0 ]]; then | |
STEP_OK=$EXIT_CODE | |
[[ -w /tmp ]] && echo $STEP_OK > /tmp/step.$$ | |
if [[ -n $LOG_STEPS ]]; then | |
local FILE=$(readlink -m "${BASH_SOURCE[1]}") | |
local LINE=${BASH_LINENO[0]} | |
echo "$FILE: line $LINE: Command \`$*' failed with exit code $EXIT_CODE." >> "$LOG_STEPS" | |
fi | |
fi | |
return $EXIT_CODE | |
} | |
next() { | |
[[ -f /tmp/step.$$ ]] && { STEP_OK=$(< /tmp/step.$$); rm -f /tmp/step.$$; } | |
[[ $STEP_OK -eq 0 ]] && echo_success || echo_failure | |
echo | |
return $STEP_OK | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# -*-Shell-script-*- | |
# | |
# functions This file contains functions to be used by most or all | |
# shell scripts in the /etc/init.d directory. | |
# | |
# Get a sane screen width | |
[ -z "${COLUMNS:-}" ] && COLUMNS=80 | |
# Read in our configuration | |
RES_COL=60 | |
MOVE_TO_COL="echo -en \\033[${RES_COL}G" | |
SETCOLOR_SUCCESS="echo -en \\033[1;32m" | |
SETCOLOR_FAILURE="echo -en \\033[1;31m" | |
SETCOLOR_WARNING="echo -en \\033[1;33m" | |
SETCOLOR_NORMAL="echo -en \\033[0;39m" | |
echo_success() { | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_SUCCESS | |
echo -n $" OK " | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 0 | |
} | |
echo_failure() { | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_FAILURE | |
echo -n $"FAILED" | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 1 | |
} | |
echo_passed() { | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_WARNING | |
echo -n $"PASSED" | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 1 | |
} | |
echo_warning() { | |
$MOVE_TO_COL | |
echo -n "[" | |
$SETCOLOR_WARNING | |
echo -n $"WARNING" | |
$SETCOLOR_NORMAL | |
echo -n "]" | |
echo -ne "\r" | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment