Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring for future systemd support - https://phabricator.whonix.o…
- Loading branch information
Patrick Schleizer
committed
Apr 2, 2015
1 parent
19fb2ef
commit cba4e22
Showing
5 changed files
with
256 additions
and
224 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
## This file is part of Whonix. | ||
## Copyright (C) 2012 - 2014 Patrick Schleizer <adrelanos@riseup.net> | ||
## See the file COPYING for copying conditions. | ||
|
||
set -o pipefail | ||
set -o errtrace | ||
|
||
error_handler() { | ||
local exit_code="$?" | ||
#log_end_msg 1 | ||
if [ "$1" = "" ]; then | ||
local msg="\ | ||
############################################################################### | ||
## Swap File Creator ERROR | ||
## | ||
## BASH_COMMAND: $BASH_COMMAND | ||
## exit_code: $exit_code | ||
## | ||
## Experts only: | ||
## bash -x $BASH_SOURCE restart | ||
## for verbose output. Clean the output and | ||
## submit to developers. | ||
###############################################################################\ | ||
" | ||
else | ||
local msg="\ | ||
############################################################################### | ||
## Swap File Creator script ERROR | ||
## | ||
## $1 | ||
## | ||
## Experts only: | ||
## bash -x $BASH_SOURCE restart | ||
## for verbose output. Clean the output and | ||
## submit to developers. | ||
###############################################################################\ | ||
" | ||
fi | ||
echo "$msg" | ||
rm --force "$RUN_FOLDER/progress" | ||
rm --force "$RUN_FOLDER/success" | ||
touch "$RUN_FOLDER/fail" | ||
[ -n "$LOG" ] || LOG="/var/log/$NAME.log" | ||
echo "$msg" >> "$LOG" | ||
[ -n "$SLEEP_SECONDS_ON_ERROR" ] || SLEEP_SECONDS_ON_ERROR="5" | ||
sleep "$SLEEP_SECONDS_ON_ERROR" & | ||
wait "$!" | ||
exit 1 | ||
} | ||
|
||
trap "error_handler" ERR | ||
set +e | ||
|
||
sanity_tests() { | ||
command -v pv >/dev/null 2>&1 | ||
command -v losetup >/dev/null 2>&1 | ||
command -v cryptsetup >/dev/null 2>&1 | ||
command -v mkdir >/dev/null 2>&1 | ||
command -v rm >/dev/null 2>&1 | ||
command -v touch >/dev/null 2>&1 | ||
command -v chown >/dev/null 2>&1 | ||
command -v dd >/dev/null 2>&1 | ||
command -v timeout >/dev/null 2>&1 | ||
command -v mkswap >/dev/null 2>&1 | ||
command -v swapon >/dev/null 2>&1 | ||
command -v swapoff >/dev/null 2>&1 | ||
command -v shred >/dev/null 2>&1 | ||
command -v cat >/dev/null 2>&1 | ||
command -v test >/dev/null 2>&1 | ||
command -v echo >/dev/null 2>&1 | ||
command -v stat >/dev/null 2>&1 | ||
} | ||
|
||
if [ -f "/etc/default/swap-file-creator" ]; then | ||
source "/etc/default/swap-file-creator" | ||
fi | ||
|
||
[ -n "$SLEEP_SECONDS_ON_ERROR" ] || SLEEP_SECONDS_ON_ERROR="5" | ||
[ -n "$DESC" ] || DESC="Encrypted Swap File Creator" | ||
[ -n "$NAME" ] || NAME="swap-file-creator" | ||
[ -n "$SCRIPTNAME" ] || SCRIPTNAME="/etc/init.d/$NAME" | ||
[ -n "$LOG" ] || LOG="/var/log/$NAME.log" | ||
[ -n "$SWAPFILE" ] || SWAPFILE="/var/swapfile" | ||
[ -n "$VERBOSE" ] || VERBOSE="yes" | ||
[ -n "$UUID" ] || UUID="0615ba72-85b0-4183-8d54-300bb0d2e491" | ||
[ -n "$DD_IF" ] || DD_IF="/dev/zero" | ||
[ -n "$DD_BS" ] || DD_BS="1M" | ||
[ -n "$DD_COUNT" ] || DD_COUNT="512" | ||
[ -n "$PV_SIZE" ] || PV_SIZE="${DD_COUNT}M" | ||
[ -n "$MAPPER" ] || MAPPER="swapfile" | ||
[ -n "$MAPPER_FULL" ] || MAPPER_FULL="/dev/mapper/$MAPPER" | ||
[ -n "$RUN_FOLDER" ] || RUN_FOLDER="/var/run/$NAME" | ||
[ -n "$CRYPTSETUP_FORMAT" ] || CRYPTSETUP_FORMAT="cryptsetup --batch-mode --hash sha512 -c aes-xts-plain64 --key-size 512 luksFormat" | ||
[ -n "$SHRED_ON_STOP" ] || SHRED_ON_STOP="no" | ||
[ -n "$SHRED_OPTS" ] || SHRED_OPTS="--verbose --iterations=1" | ||
[ -n "$RANDOM_PASSWORD_TIMEOUT" ] || RANDOM_PASSWORD_TIMEOUT="10" | ||
[ -n "$RANDOM_DEVICE" ] || RANDOM_DEVICE="/dev/random" |
Oops, something went wrong.