diff --git a/.gitignore b/.gitignore index 573534c..a2269fc 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ cache_* mnt_* *.iso *.fs +install-templates.sh diff --git a/Makefile b/Makefile index f69810e..f9f3e50 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,19 @@ export DIST dist_ver := $(shell DIST=$(DIST) ./builder_setup) DISTRIBUTION := $(word 1,$(dist_ver)) DIST_VERSION := $(word 2,$(dist_ver)) +TEMPLATE_NAME := $(word 3,$(dist_ver)) + +ifeq (,$(TEMPLATE_NAME)) TEMPLATE_NAME := $(DISTRIBUTION)-$(DIST_VERSION)-x64 ifdef TEMPLATE_FLAVOR TEMPLATE_NAME := $(TEMPLATE_NAME)-$(TEMPLATE_FLAVOR) endif +endif + +# Make sure names are < 32 characters +fix_up := $(shell TEMPLATE_NAME=$(TEMPLATE_NAME) ./builder_fix_filenames) +TEMPLATE_NAME := $(word 1,$(fix_up)) + VERSION := $(shell cat version) TIMESTAMP := $(shell date -u +%Y%m%d%H%M) @@ -25,6 +34,7 @@ rpms: sudo -E ./prepare_image prepared_images/$(TEMPLATE_NAME).img && \ sudo -E ./qubeize_image prepared_images/$(TEMPLATE_NAME).img $(TEMPLATE_NAME) && \ ./build_template_rpm $(TEMPLATE_NAME) || exit 1; \ + ./create_template_list.sh || : \ update-repo-installer: [ -z "$$UPDATE_REPO" ] && UPDATE_REPO=../installer/yum/qubes-dom0;\ diff --git a/appmenus_jessie/vm-whitelisted-appmenus.list b/appmenus_jessie/vm-whitelisted-appmenus.list index 4b744f7..31d9cad 100644 --- a/appmenus_jessie/vm-whitelisted-appmenus.list +++ b/appmenus_jessie/vm-whitelisted-appmenus.list @@ -1 +1,3 @@ gnome-terminal.desktop +nautilus.desktop +yelp.desktop diff --git a/appmenus_jessie/whitelisted-appmenus.list b/appmenus_jessie/whitelisted-appmenus.list index 4b744f7..84a4b50 100644 --- a/appmenus_jessie/whitelisted-appmenus.list +++ b/appmenus_jessie/whitelisted-appmenus.list @@ -1 +1,6 @@ gnome-terminal.desktop +gpk-application.desktop +gpk-update-viewer.desktop +gpk-prefs.desktop +gpk-log.desktop +yelp.desktop diff --git a/appmenus_jessie_gnome/netvm-whitelisted-appmenus.list b/appmenus_jessie_gnome/netvm-whitelisted-appmenus.list new file mode 100644 index 0000000..4b744f7 --- /dev/null +++ b/appmenus_jessie_gnome/netvm-whitelisted-appmenus.list @@ -0,0 +1 @@ +gnome-terminal.desktop diff --git a/appmenus_jessie_gnome/vm-whitelisted-appmenus.list b/appmenus_jessie_gnome/vm-whitelisted-appmenus.list new file mode 100644 index 0000000..0f893ba --- /dev/null +++ b/appmenus_jessie_gnome/vm-whitelisted-appmenus.list @@ -0,0 +1,16 @@ +evolution.desktop +gimp.desktop +yelp.desktop +iceweasel.desktop +eog.desktop +rhythmbox.desktop +gnome-system-log.desktop +gnome-terminal.desktop +gnome-calculator.desktop +org.gnome.Cheese.desktop +org.gnome.Nautilus.desktop +org.gnome.gedit.desktop +shotwell.desktop +org.gnome.Totem.desktop +libreoffice-startcenter.desktop +session-properties.desktop diff --git a/appmenus_jessie_gnome/whitelisted-appmenus.list b/appmenus_jessie_gnome/whitelisted-appmenus.list new file mode 100644 index 0000000..a325bd9 --- /dev/null +++ b/appmenus_jessie_gnome/whitelisted-appmenus.list @@ -0,0 +1,10 @@ +gdebi.desktop +yelp.desktop +gpk-log.desktop +gpk-prefs.desktop +gpk-update-viewer.desktop +gpk-application.desktop +gnome-printers-panel.desktop +tracker-preferences.desktop +gnome-system-log.desktop +gnome-terminal.desktop diff --git a/appmenus_wheezy/netvm-whitelisted-appmenus.list b/appmenus_wheezy/netvm-whitelisted-appmenus.list new file mode 100644 index 0000000..4b744f7 --- /dev/null +++ b/appmenus_wheezy/netvm-whitelisted-appmenus.list @@ -0,0 +1 @@ +gnome-terminal.desktop diff --git a/appmenus_wheezy/vm-whitelisted-appmenus.list b/appmenus_wheezy/vm-whitelisted-appmenus.list new file mode 100644 index 0000000..31d9cad --- /dev/null +++ b/appmenus_wheezy/vm-whitelisted-appmenus.list @@ -0,0 +1,3 @@ +gnome-terminal.desktop +nautilus.desktop +yelp.desktop diff --git a/appmenus_wheezy/whitelisted-appmenus.list b/appmenus_wheezy/whitelisted-appmenus.list new file mode 100644 index 0000000..84a4b50 --- /dev/null +++ b/appmenus_wheezy/whitelisted-appmenus.list @@ -0,0 +1,6 @@ +gnome-terminal.desktop +gpk-application.desktop +gpk-update-viewer.desktop +gpk-prefs.desktop +gpk-log.desktop +yelp.desktop diff --git a/appmenus_wheezy_gnome/netvm-whitelisted-appmenus.list b/appmenus_wheezy_gnome/netvm-whitelisted-appmenus.list new file mode 100644 index 0000000..4b744f7 --- /dev/null +++ b/appmenus_wheezy_gnome/netvm-whitelisted-appmenus.list @@ -0,0 +1 @@ +gnome-terminal.desktop diff --git a/appmenus_wheezy_gnome/vm-whitelisted-appmenus.list b/appmenus_wheezy_gnome/vm-whitelisted-appmenus.list new file mode 100644 index 0000000..33843f3 --- /dev/null +++ b/appmenus_wheezy_gnome/vm-whitelisted-appmenus.list @@ -0,0 +1,15 @@ +gnome-terminal.desktop +gcalctool.desktop +evolution.desktop +nautilus.desktop +iceweasel.desktop +libreoffice-startcenter.desktop +gedit.desktop +gimp.desktop +eog.desktop +totem.desktop +rhythmbox.desktop +gnome-system-log.desktop +cheese.desktop +session-properties.desktop +yelp.desktop diff --git a/appmenus_wheezy_gnome/whitelisted-appmenus.list b/appmenus_wheezy_gnome/whitelisted-appmenus.list new file mode 100644 index 0000000..89d9525 --- /dev/null +++ b/appmenus_wheezy_gnome/whitelisted-appmenus.list @@ -0,0 +1,11 @@ +gnome-terminal.desktop +gpk-application.desktop +gpk-update-viewer.desktop +gpk-prefs.desktop +gpk-log.desktop +gnome-panel.desktop +gnome-printers-panel.desktop +gnome-system-log.desktop +gdebi.desktop +tracker-preferences.desktop +yelp.desktop diff --git a/appmenus_wheezy_whonix-gateway/netvm-whitelisted-appmenus.list b/appmenus_wheezy_whonix-gateway/netvm-whitelisted-appmenus.list new file mode 100644 index 0000000..68ed628 --- /dev/null +++ b/appmenus_wheezy_whonix-gateway/netvm-whitelisted-appmenus.list @@ -0,0 +1,21 @@ +gnome-terminal.desktop +nautilus.desktop +yelp.desktop +gateway-arm.desktop +gateway-firewall30default.desktop +gateway-firewall50user.desktop +gateway-firsttimesetup.desktop +gateway-reloadfirewall.desktop +gateway-reloadtor.desktop +gateway-restarttor.desktop +gateway-stoptor.desktop +gateway-torrc.desktop +gateway-torrcexamples.desktop +timesync.desktop +whonixcheck.desktop +whonix_repository.desktop +dolphin.desktop +Help.desktop +ksystemlog.desktop +kwrite.desktop + diff --git a/appmenus_wheezy_whonix-gateway/vm-whitelisted-appmenus.list b/appmenus_wheezy_whonix-gateway/vm-whitelisted-appmenus.list new file mode 100644 index 0000000..68ed628 --- /dev/null +++ b/appmenus_wheezy_whonix-gateway/vm-whitelisted-appmenus.list @@ -0,0 +1,21 @@ +gnome-terminal.desktop +nautilus.desktop +yelp.desktop +gateway-arm.desktop +gateway-firewall30default.desktop +gateway-firewall50user.desktop +gateway-firsttimesetup.desktop +gateway-reloadfirewall.desktop +gateway-reloadtor.desktop +gateway-restarttor.desktop +gateway-stoptor.desktop +gateway-torrc.desktop +gateway-torrcexamples.desktop +timesync.desktop +whonixcheck.desktop +whonix_repository.desktop +dolphin.desktop +Help.desktop +ksystemlog.desktop +kwrite.desktop + diff --git a/appmenus_wheezy_whonix-gateway/whitelisted-appmenus.list b/appmenus_wheezy_whonix-gateway/whitelisted-appmenus.list new file mode 100644 index 0000000..25df4f2 --- /dev/null +++ b/appmenus_wheezy_whonix-gateway/whitelisted-appmenus.list @@ -0,0 +1,11 @@ +gnome-terminal.desktop +gpk-application.desktop +gpk-update-viewer.desktop +gpk-prefs.desktop +gpk-log.desktop +yelp.desktop +gateway-firewall30default.desktop +gateway-firewall50user.desktop +gateway-torrc.desktop +gateway-torrcexamples.desktop +kwrite.desktop diff --git a/appmenus_wheezy_whonix-workstation/netvm-whitelisted-appmenus.list b/appmenus_wheezy_whonix-workstation/netvm-whitelisted-appmenus.list new file mode 100644 index 0000000..4b744f7 --- /dev/null +++ b/appmenus_wheezy_whonix-workstation/netvm-whitelisted-appmenus.list @@ -0,0 +1 @@ +gnome-terminal.desktop diff --git a/appmenus_wheezy_whonix-workstation/vm-whitelisted-appmenus.list b/appmenus_wheezy_whonix-workstation/vm-whitelisted-appmenus.list new file mode 100644 index 0000000..4371561 --- /dev/null +++ b/appmenus_wheezy_whonix-workstation/vm-whitelisted-appmenus.list @@ -0,0 +1,27 @@ +gnome-terminal.desktop +nautilus.desktop +yelp.desktop + +anondist-torbrowser.desktop +anondist-torbrowser_update.desktop +gateway-firsttimesetup.desktop +timesync.desktop +vlc.desktop +whonixcheck.desktop +whonix-contribute.desktop +whonix-documentation.desktop +whonix-donate.desktop +whonix-featureblog.desktop +whonix-forum.desktop +whonix-importantblog.desktop +whonix-irc-chat-support.desktop +whonix-mailinglist.desktop +whonix_repository.desktop +xchat.desktop +x-www-browser.desktop +dolphin.desktop +Help.desktop +kcalc.desktop +kgpg.desktop +kwrite.desktop + diff --git a/appmenus_wheezy_whonix-workstation/whitelisted-appmenus.list b/appmenus_wheezy_whonix-workstation/whitelisted-appmenus.list new file mode 100644 index 0000000..c9b6f00 --- /dev/null +++ b/appmenus_wheezy_whonix-workstation/whitelisted-appmenus.list @@ -0,0 +1,96 @@ +gnome-terminal.desktop +gpk-application.desktop +gpk-update-viewer.desktop +gpk-prefs.desktop +gpk-log.desktop +yelp.desktop + + +anondist-torbrowser.desktop +anondist-torbrowser_update.desktop +bluetooth-sendto.desktop +bluetooth-wizard.desktop +brasero.desktop +brasero-nautilus.desktop +display.im6.desktop +fpm2.desktop +gateway-firsttimesetup.desktop +gcr-prompter.desktop +gcr-viewer.desktop +gnome-terminal.desktop +gpk-application.desktop +gpk-dbus-service.desktop +gpk-install-catalog.desktop +gpk-install-local-file.desktop +gpk-log.desktop +gpk-prefs.desktop +gpk-service-pack.desktop +gpk-update-viewer.desktop +iceweasel.desktop +kde4 +mat.desktop +mimeinfo.cache +nact.desktop +nautilus-autorun-software.desktop +nautilus.desktop +nm-applet.desktop +nm-connection-editor.desktop +python2.7.desktop +timesync.desktop +vlc.desktop +whonixcheck.desktop +whonix-contribute.desktop +whonix-documentation.desktop +whonix-donate.desktop +whonix-featureblog.desktop +whonix-forum.desktop +whonix-importantblog.desktop +whonix-irc-chat-support.desktop +whonix-mailinglist.desktop +whonix_repository.desktop +xchat.desktop +x-www-browser.desktop +yelp.desktop + + +akonaditray.desktop +-rw-r--r-- 1 root root 5000 Jun 22 2012 ark.desktop +dolphin.desktop +gwenview.desktop +Help.desktop +jovieapp.desktop +kcalc.desktop +kdepasswd.desktop +kdesystemsettings.desktop +keditbookmarks.desktop +kfind.desktop +kfontview.desktop +kgpg.desktop +klipper.desktop +kmag.desktop +kmailservice.desktop +kmix.desktop +kmousetool.desktop +kmouth.desktop +konsole.desktop +krandrtray.desktop +ksysguard.desktop +ksystemlog.desktop +-rw-r--r-- 1 root root 1766 Jun 6 2012 ktelnetservice.desktop +kvkbd.desktop +kwrite.desktop +nepomukbackup.desktop +nepomukcontroller.desktop +okularApplication_comicbook.desktop +okularApplication_dvi.desktop +okularApplication_fax.desktop +okularApplication_fb.desktop +okularApplication_ghostview.desktop +okularApplication_kimgio.desktop +okularApplication_ooo.desktop +okularApplication_pdf.desktop +okularApplication_plucker.desktop +okularApplication_xps.desktop +okular.desktop +systemsettings.desktop + diff --git a/builder_fix_filenames b/builder_fix_filenames new file mode 100755 index 0000000..6d3848f --- /dev/null +++ b/builder_fix_filenames @@ -0,0 +1,9 @@ +#!/bin/bash + +# Check template name length and fix if not under 32 characters +# Return the result + +. ./functions.sh > /dev/null + +# Check for custom template name +templateNameDist "${TEMPLATE_NAME}" diff --git a/builder_setup b/builder_setup index ba265b9..b1cefb2 100755 --- a/builder_setup +++ b/builder_setup @@ -2,6 +2,8 @@ # Setup env variables +. ./functions.sh > /dev/null + case "$DIST" in fc*) DISTRIBUTION=fedora diff --git a/cleanup_image b/cleanup_image index 3716593..195f1ac 100755 --- a/cleanup_image +++ b/cleanup_image @@ -20,6 +20,7 @@ ls -als $IMG mount -o loop $IMG mnt || exit 1 export INSTALLDIR=`pwd`/mnt/ +echo "--> Cleaning up image file..." $SCRIPTSDIR/09_cleanup.sh echo "--> Compacting image file..." diff --git a/create_template_list.sh b/create_template_list.sh new file mode 100755 index 0000000..5c0fbca --- /dev/null +++ b/create_template_list.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : + +# +# Creates a small script to copy to dom0 to retrieve the generated template rpm's +# + +template_dir="$(readlink -m ./rpm/install-templates.sh)" +files=( $(ls rpm/noarch) ) +name=$(xenstore-read name) + +# ----------------------------------------------------------------------------- +# Write $vars +# ----------------------------------------------------------------------------- +cat << EOF > "${template_dir}" +#!/bin/bash + +# Use the following command in DOM0 to retreive this file: +# qvm-run --pass-io ${name} 'cat ${template_dir}' > install-templates.sh + +files=" +$(printf "%s \n" ${files[@]}) +" + +path="$(readlink -m .)/rpm/noarch" +version="-$(cat ./version)" +name="${name}" +EOF + +# ----------------------------------------------------------------------------- +# Write installation function +# ----------------------------------------------------------------------------- +cat << 'EOF' >> "${template_dir}" + +for file in ${files[@]}; do + if [ ! -e ${file} ]; then + echo "Copying ${file} from ${name} to ${PWD}/${file}..." + qvm-run --pass-io ${name} "cat ${path}/${file}" > ${file} + fi + + sudo yum erase $(echo "${file}" | sed -r "s/(${version}).+$//") && { + sudo yum install ${file} && { + rm -f ${file} + } + } +done +EOF + +# ----------------------------------------------------------------------------- +# Display instructions +# ----------------------------------------------------------------------------- +echo "Use the following command in DOM0 to retreive this file:" +echo "qvm-run --pass-io ${name} 'cat ${template_dir}' > install-templates.sh" + + diff --git a/functions.sh b/functions.sh new file mode 100755 index 0000000..52ae51c --- /dev/null +++ b/functions.sh @@ -0,0 +1,430 @@ +#!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : + +set -e + +VERBOSE=${VERBOSE:-1} +DEBUG=${DEBUG:-0} + +################################################################################ +# Global functions +################################################################################ + +# ------------------------------------------------------------------------------ +# Define colors +# ------------------------------------------------------------------------------ +colors() { + ## Thanks to: + ## http://mywiki.wooledge.org/BashFAQ/037 + ## Variables for terminal requests. + [[ -t 2 ]] && { + export alt=$( tput smcup || tput ti ) # Start alt display + export ealt=$( tput rmcup || tput te ) # End alt display + export hide=$( tput civis || tput vi ) # Hide cursor + export show=$( tput cnorm || tput ve ) # Show cursor + export save=$( tput sc ) # Save cursor + export load=$( tput rc ) # Load cursor + export bold=$( tput bold || tput md ) # Start bold + export stout=$( tput smso || tput so ) # Start stand-out + export estout=$( tput rmso || tput se ) # End stand-out + export under=$( tput smul || tput us ) # Start underline + export eunder=$( tput rmul || tput ue ) # End underline + export reset=$( tput sgr0 || tput me ) # Reset cursor + export blink=$( tput blink || tput mb ) # Start blinking + export italic=$( tput sitm || tput ZH ) # Start italic + export eitalic=$( tput ritm || tput ZR ) # End italic + [[ ${TERM} != *-m ]] && { + export red=$( tput setaf 1|| tput AF 1 ) + export green=$( tput setaf 2|| tput AF 2 ) + export yellow=$( tput setaf 3|| tput AF 3 ) + export blue=$( tput setaf 4|| tput AF 4 ) + export magenta=$( tput setaf 5|| tput AF 5 ) + export cyan=$( tput setaf 6|| tput AF 6 ) + } + export white=$( tput setaf 7|| tput AF 7 ) + export default=$( tput op ) + export eed=$( tput ed || tput cd ) # Erase to end of display + export eel=$( tput el || tput ce ) # Erase to end of line + export ebl=$( tput el1 || tput cb ) # Erase to beginning of line + export ewl=$eel$ebl # Erase whole line + export draw=$( tput -S <<< ' enacs + smacs + acsc + rmacs' || { \ + tput eA; tput as; + tput ac; tput ae; } ) # Drawing characters + export back=$'\b' + } 2>/dev/null ||: + + export build_already_defined_colors="true" +} + +if [ ! "$build_already_defined_colors" = "true" ]; then + colors +fi + +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + chroot() { + local retval + true ${blue} + /usr/sbin/chroot "$@" && { retval=$?; true; } || { retval=$?; true; } + true ${reset} + return $retval + } +fi + +# ------------------------------------------------------------------------------ +# Display messages in color +# ------------------------------------------------------------------------------ +# Only output text under certain conditions +output() { + if [ "${VERBOSE}" -ge 1 ]; then + # Don't echo if -x is set since it will already be displayed via true + [[ ${-/x} != $- ]] || echo -e "${1}" + fi +} + +info() { + output "${bold}${blue}INFO: ${1}${reset}" || : +} + +debug() { + output "${bold}${green}DEBUG: ${1}${reset}" || : +} + +warn() { + output "${stout}${yellow}WARNING: ${1}${reset}" || : +} + +error() { + output "${bold}${red}ERROR: ${1}${reset}" || : +} + +# ------------------------------------------------------------------------------ +# Takes an array and exports it a global variable +# +# $1: Array to export +# $2: Global variable name to use for export +# +# http://ihaveabackup.net/2012/01/29/a-workaround-for-passing-arrays-in-bash/ +# +# ------------------------------------------------------------------------------ +setArrayAsGlobal() { + local array="$1" + local export_as="$2" + local code=$(declare -p "$array") + local replaced="${code/$array/$export_as}" + eval ${replaced/declare -/declare -g} +} + + +# ------------------------------------------------------------------------------ +# Spilts the path and returns an array of parts +# +# $1: Full path of file to split +# $2: Global variable name to use for export +# Returns: +# ([full]='original name' [dir]='directory' [base]='filename' [ext]='extension') +# +# Original concept path split from: +# https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash +# +# ------------------------------------------------------------------------------ +splitPath() { + + local return_global_var=$2 + local filename="${1##*/}" # Strip longest match of */ from start + local dir="${1:0:${#1} - ${#filename}}" # Substring from 0 thru pos of filename + local base="${filename%.[^.]*}" # Strip shortest match of . plus at least one non-dot char from end + local ext="${filename:${#base} + 1}" # Substring from len of base thru end + if [ "$ext" ]; then + local dotext=".$ext" + else + local dotext="" + fi + if [[ -z "$base" && -n "$ext" ]]; then # If we have an extension and no base, it's really the base + base=".$ext" + ext="" + dotext="" + fi + + declare -A PARTS=([full]="$1" [dir]="$dir" [base]="$base" [ext]="$ext" [dotext]="$dotext") + setArrayAsGlobal PARTS $return_global_var +} + +templateFlavor() { + echo ${TEMPLATE_FLAVOR} +} + +templateFlavorPrefix() { + local template_flavor=${1-$(templateFlavor)} + + # If TEMPLATE_FLAVOR_PREFIX is not already an array, make it one + if ! [[ "$(declare -p TEMPLATE_FLAVOR_PREFIX 2>/dev/null)" =~ ^declare\ -a.* ]] ; then + TEMPLATE_FLAVOR_PREFIX=( ${TEMPLATE_FLAVOR_PREFIX} ) + fi + + for element in "${TEMPLATE_FLAVOR_PREFIX[@]}" + do + if [ "${element%:*}" == "${DIST}+${template_flavor}" ]; then + echo ${element#*:} + return + fi + done + + echo "${DIST}${template_flavor:++}" +} + +templateNameDist() { + local dist_name="${1}" + template_name="$(templateName)" && dist_name="${template_name}" + + # XXX: Temp hack to shorten name + if [ ${#dist_name} -ge 32 ]; then + if [ ${#template_name} -lt 32 ]; then + dist_name="${template_name}" + else + dist_name="${dist_name:0:31}" + fi + fi + + # Remove and '+' characters from name since they are invalid for name + dist_name="${dist_name//+/-}" + echo ${dist_name} +} + +templateName() { + local template_flavor=${1-$(templateFlavor)} + retval=1 # Default is 1; mean no replace happened + + # Only apply options if $1 was not passed + if [ -n "${1}" ]; then + local template_options= + else + local template_options="${TEMPLATE_OPTIONS// /+}" + fi + + local template_name="$(templateFlavorPrefix ${template_flavor})${template_flavor}${template_options:++}${template_options}" + + # If TEMPLATE_LABEL is not already an array, make it one + if ! [[ "$(declare -p TEMPLATE_LABEL 2>/dev/null)" =~ ^declare\ -a.* ]] ; then + TEMPLATE_LABEL=( ${TEMPLATE_LABEL} ) + fi + + for element in "${TEMPLATE_LABEL[@]}"; do + if [ "${element%:*}" == "${template_name}" ]; then + template_name="${element#*:}" + retval=0 + break + fi + done + + if [ ${#template_name} -ge 32 ]; then + error "Template name is greater than 31 characters: ${template_name}" + error "Please set an alias" + error "Exiting!!!" + exit 1 + fi + + echo ${template_name} + return $retval +} + +templateDir() { + local template_flavor=${1-$(templateFlavor)} + + # If TEMPLATE_FLAVOR_DIR is not already an array, make it one + if ! [[ "$(declare -p TEMPLATE_FLAVOR_DIR 2>/dev/null)" =~ ^declare\ -a.* ]] ; then + TEMPLATE_FLAVOR_DIR=( ${TEMPLATE_FLAVOR_DIR} ) + fi + + for element in "${TEMPLATE_FLAVOR_DIR[@]}" + do + # (wheezy+whonix-gateway / wheezy+whonix-gateway+gnome[+++] / wheezy+gnome ) + if [ "${element%:*}" == "$(templateName ${template_flavor})" ]; then + eval echo -e ${element#*:} + return + # Very short name compare (+proxy) + elif [ "${element:0:1}" == "+" -a "${element%:*}" == "+${template_flavor}" ]; then + eval echo -e ${element#*:} + return + fi + done + + if [ -n "${template_flavor}" ]; then + local template_flavor_prefix="$(templateFlavorPrefix ${template_flavor})" + local dir="${SCRIPTSDIR}/${template_flavor_prefix}${template_flavor}" + else + local dir="${SCRIPTSDIR}" + fi + + echo "${dir}" +} + +templateFile() { + local file="$1" + local suffix="$2" + local template_flavor="$3" + local template_dir="$(templateDir "${template_flavor}")" + + splitPath "${file}" path_parts + + # Append suffix to filename (before extension) + if [ "${suffix}" ]; then + file="${template_dir}/${path_parts[base]}_${suffix}${path_parts[dotext]}" + else + file="${template_dir}/${path_parts[base]}${path_parts[dotext]}" + fi + + if [ -f "${file}" ]; then + echo "${file}" + fi +} + +buildStepExec() { + local filename="$1" + local suffix="$2" + local template_flavor="$3" + + script="$(templateFile "${filename}" "${suffix}" "${template_flavor}")" + + if [ -f "${script}" ] && [ ! ${GLOBAL_CACHE[$script]+_} ]; then + + # Test module expects raw output back only used to asser test results + if [[ -n ${TEST} ]]; then + echo "${script}" + else + output "${bold}${under}INFO: Currently running script: ${script}${reset}" + fi + + # Cache $script + GLOBAL_CACHE[$script]=1 + # Execute $script + "${script}" + fi +} + +copyTreeExec() { + local source_dir="$1" + local dir="$2" + local template_flavor="$3" + local target_dir="$4" + + local template_dir="$(templateDir ${template_flavor})" + local source_dir="$(readlink -m ${source_dir:-${template_dir}}/${dir})" + local target_dir="$(readlink -m ${target_dir:-${INSTALLDIR}})" + + if ! [ -d "${source_dir}" ]; then + debug "No extra files to copy for ${dir}" + return 0 + fi + + debug "Copying ${source_dir}/* ${target_dir}" + cp -rp "${source_dir}/." "${target_dir}" + + if [ -f "${source_dir}/.facl" ]; then + debug "Restoring file permissions..." + pushd "${target_dir}" + { + setfacl --restore="${source_dir}/.facl" 2>/dev/null ||: + rm -f .facl + } + popd + fi +} + +callTemplateFunction() { + # Reset Cache + unset GLOBAL_CACHE + declare -A -g GLOBAL_CACHE + + local calling_script="$1" + local calling_arg="$2" + local functionExec="$3" + local template_flavor="$(templateFlavor)" + + ${functionExec} "${calling_script}" \ + "${calling_arg}" \ + "${template_flavor}" + + for option in ${TEMPLATE_OPTIONS[@]} + do + # Long name (wheezy+whonix-gateway+proxy) + ${functionExec} "${calling_script}" \ + "${calling_arg}" \ + "$(templateFlavor)+${option}" + + # Short name (wheezy+proxy) + ${functionExec} "${calling_script}" \ + "${calling_arg}" \ + "${option}" + done + + # If template_flavor exists, also check on base distro + if [ -n "${template_flavor}" ]; then + ${functionExec} "${calling_script}" \ + "${calling_arg}" + fi +} + +# ------------------------------------------------------------------------------ +# ------------------------------------------------------------------------------ +getFileLocations() { + local return_global_var=$1 + local filename="$2" + local suffix="$3" + local function="templateFile" + + files="$(callTemplateFunction "${filename}" "${suffix}" "${function}")" + + IFS_orig="${IFS}}"; IFS=$'\n' + files=( "${files}" ) + setArrayAsGlobal files $return_global_var + + IFS="${IFS_orig}" +} + +# ------------------------------------------------------------------------------ +# Executes any additional optional configuration steps if the configuration +# scripts exist +# ------------------------------------------------------------------------------ +buildStep() { + local filename="$1" + local suffix="$2" + local function="buildStepExec" + + callTemplateFunction "${filename}" "${suffix}" "${function}" +} + +# ------------------------------------------------------------------------------ +# Copy extra file tree to ${INSTALLDIR} +# TODO: Allow copy per step (04_install_qubes.sh-files) +# +# To set file permissions is a PITA since git won't save them and will +# complain heavily if they are set to root only read, so this is the procdure: +# +# 1. Change to the directory that you want to have file permissions retained +# 2. Change all the file permissions / ownership as you want +# 3. Change back to the root of the exta directory (IE: extra-qubes-files) +# 4. Manually restore facl's: setfacl --restore=.facl +# 5. Manually create facl backup used after copying: getfacl -R . > .facl +# 6. If git complains; reset file ownership back to user. The .facl file stored +# the file permissions and will be used to reset the file permissions after +# they get copied over to ${INSTALLDIR} +# NOTE: Don't forget to redo this process if you add -OR- remove files +# ------------------------------------------------------------------------------ +copyTree() { + local dir="$1" + local source_dir="$2" + local target_dir="$3" + local function="copyTreeExec" + + if [ "x${source_dir}" == "x" ]; then + callTemplateFunction "" "${dir}" "${function}" + else + copyTreeExec "${source_dir}" "${dir}" "" "${target_dir}" + fi +} + +# $0 is module that sourced vars.sh +output "${bold}${under}INFO: Currently running script: ${0}${reset}" diff --git a/prepare_image b/prepare_image index c6b7a62..f5a3fef 100755 --- a/prepare_image +++ b/prepare_image @@ -1,6 +1,9 @@ -#!/bin/sh +#!/bin/bash -export IMG=$1 +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +export IMG="$1" export LC_ALL=POSIX RETCODE=0 @@ -8,49 +11,61 @@ RETCODE=0 : ${DIST=fc14} . ./builder_setup >/dev/null +. ./umount_kill.sh >/dev/null -set -e +if [ "$VERBOSE" -ge 2 -o "$DEBUG" == "1" ]; then + set -x +else + set -e +fi if ! [ $# -eq 1 ]; then -echo "usage $0 " -exit + echo "usage $0 " + exit fi if [ "$VERBOSE" == "1" ]; then - export YUM_OPTS="$YUM_OPTS -q" + export YUM_OPTS="$YUM_OPTS -q" fi +# ------------------------------------------------------------------------------ +# Prepare for mount +# ------------------------------------------------------------------------------ echo "-> Preparing instalation of $DIST template..." -$SCRIPTSDIR/00_prepare.sh - -if [ -f $IMG ]; then - echo "-> Image file already exists, assuming *update*..." - mount -o loop $IMG mnt || exit 1 - export INSTALLDIR=`pwd`/mnt/ - trap "umount $INSTALLDIR" EXIT -else - - echo "-> Initializing empty image..." - truncate -s 10G $IMG || exit 1 +export INSTALLDIR="$(readlink -m mnt)" +mkdir -p "$INSTALLDIR" +"$SCRIPTSDIR/00_prepare.sh" - echo "-> Creating filesystem..." - mkfs.ext4 -q -F $IMG || exit 1 +# ------------------------------------------------------------------------------ +# Mount image and install core OS +# ------------------------------------------------------------------------------ - mkdir -p mnt - mount -o loop $IMG mnt || exit 1 - - export INSTALLDIR=`pwd`/mnt/ - - trap "umount $INSTALLDIR" EXIT +if [ -f "$IMG" ]; then + echo "-> Image file already exists, assuming *update*..." +else + echo "-> Initializing empty image..." + truncate -s 10G "$IMG" || exit 1 - $SCRIPTSDIR/01_install_core.sh + echo "-> Creating filesystem..." + mkfs.ext4 -q -F "$IMG" || exit 1 fi +mount -o loop "$IMG" "$INSTALLDIR" || exit 1 +trap "umount_kill $(readlink -m $INSTALLDIR)" EXIT +"$SCRIPTSDIR/01_install_core.sh" + +# ------------------------------------------------------------------------------ +# Install package groups +# ------------------------------------------------------------------------------ echo "-> Installing package groups..." -$SCRIPTSDIR/02_install_groups.sh +"$SCRIPTSDIR/02_install_groups.sh" +# ------------------------------------------------------------------------------ +# Cleanup +# ------------------------------------------------------------------------------ trap - EXIT + echo "-> Unmounting prepared_image..." -sudo umount $INSTALLDIR +umount_kill "$(readlink -m $INSTALLDIR)" || : exit $RETCODE diff --git a/qubeize_image b/qubeize_image index 6f0e563..0333754 100755 --- a/qubeize_image +++ b/qubeize_image @@ -1,81 +1,98 @@ #!/bin/sh -export CLEANIMG=$1 -export NAME=$2 +# ------------------------------------------------------------------------------ +# Configurations and Conditionals +# ------------------------------------------------------------------------------ +export CLEANIMG="$1" +export NAME="$2" export LC_ALL=POSIX . ./builder_setup >/dev/null +. ./umount_kill.sh >/dev/null -set -e +if [ "$VERBOSE" -ge 2 -o "$DEBUG" == "1" ]; then + set -x +else + set -e +fi if [ $# -eq 0 ]; then -echo "usage $0 " -exit + echo "usage $0 " + exit fi -if [ x$CLEANIMG = x ]; then -echo "Image file not specified!" -exit 1 +if [ "x$CLEANIMG" = x ]; then + echo "Image file not specified!" + exit 1 fi -if [ x$NAME = x ]; then -echo "Name not given!" -exit 1 +if [ "x$NAME" = x ]; then + echo "Name not given!" + exit 1 fi ID=$(id -ur) if [ $ID != 0 ] ; then - echo "This script should be run as root user." - exit 1 + echo "This script should be run as root user." + exit 1 fi if [ "$VERBOSE" == "1" ]; then - export YUM_OPTS="$YUM_OPTS -q" + export YUM_OPTS="$YUM_OPTS -q" fi +# ------------------------------------------------------------------------------ +# Cleanup function +# ------------------------------------------------------------------------------ function cleanup() { - if grep -q " $PWD/mnt/proc " /proc/mounts; then - umount mnt/proc - fi - if grep -q " $PWD/mnt " /proc/mounts; then - umount mnt - fi + umount_kill "$PWD/mnt" || : } - trap cleanup ERR -export IMG=qubeized_images/$NAME-root.img +# ------------------------------------------------------------------------------ +# Mount qubeized_image +# ------------------------------------------------------------------------------ +export IMG="qubeized_images/$NAME-root.img" + echo "--> Copying $CLEANIMG to $IMG..." -cp $CLEANIMG $IMG || exit 1 +cp "$CLEANIMG" "$IMG" || exit 1 echo "--> Mounting $IMG" - mkdir -p mnt -mount -o loop $IMG mnt || exit 1 +mount -o loop "$IMG" mnt || exit 1 export INSTALLDIR=mnt -$SCRIPTSDIR/04_install_qubes.sh || { umount $INSTALLDIR; exit 1; } +# ------------------------------------------------------------------------------ +# Run qubeize script +# ------------------------------------------------------------------------------ +"$SCRIPTSDIR/04_install_qubes.sh" || { umount "$INSTALLDIR"; exit 1; } +# ------------------------------------------------------------------------------ +# Create App Menus +# ------------------------------------------------------------------------------ echo "--> Copying the Apps Menu shortcuts..." -export APPSORIG=qubeized_images/$NAME-apps.orig -export APPSTEMPL=qubeized_images/$NAME-apps.templates -mkdir -p $APPSORIG -cp -r $(pwd)/mnt/usr/share/applications/* $APPSORIG +export APPSORIG="qubeized_images/$NAME-apps.orig" +export APPSTEMPL="qubeized_images/$NAME-apps.templates" +mkdir -p "$APPSORIG" +cp -r "$(pwd)"/mnt/usr/share/applications/* "$APPSORIG" echo "--> Creating the Apps Menu templates..." -./create_apps_templates.sh $APPSORIG $APPSTEMPL +"./create_apps_templates.sh" "$APPSORIG" "$APPSTEMPL" echo "--> Choosing appmenus whitelists..." rm -f appmenus if [ -d "appmenus_${DIST}_${TEMPLATE_FLAVOR}" ]; then - ln -s "appmenus_${DIST}_${TEMPLATE_FLAVOR}" appmenus + ln -s "appmenus_${DIST}_${TEMPLATE_FLAVOR}" appmenus elif [ -d "appmenus_$DIST" ]; then - ln -s "appmenus_$DIST" appmenus + ln -s "appmenus_$DIST" appmenus else - ln -s "appmenus_generic" appmenus + ln -s "appmenus_generic" appmenus fi +# ------------------------------------------------------------------------------ +# Link directories so they can be mounted +# ------------------------------------------------------------------------------ echo "--> Linking /home to /rw/home..." mv mnt/home mnt/home.orig ln -sf /rw/home mnt/home @@ -85,14 +102,17 @@ mv mnt/usr/local mnt/usr/local.orig ln -sf /rw/usrlocal mnt/usr/local if [ -e mnt/etc/sysconfig/i18n ]; then - echo "--> Setting up default locale..." - echo LC_CTYPE=en_US.UTF-8 > mnt/etc/sysconfig/i18n + echo "--> Setting up default locale..." + echo LC_CTYPE=en_US.UTF-8 > mnt/etc/sysconfig/i18n fi +# ------------------------------------------------------------------------------ +# Finsh - unmount image +# ------------------------------------------------------------------------------ echo "--> Unmounting $IMG" -umount mnt +cleanup echo "Qubeized image stored at: $IMG" echo "Reducing image size (calling cleanup_image)..." -./cleanup_image $IMG +./cleanup_image "$IMG" diff --git a/scripts_debian/00_prepare.sh b/scripts_debian/00_prepare.sh index c530c0f..897bc0a 100755 --- a/scripts_debian/00_prepare.sh +++ b/scripts_debian/00_prepare.sh @@ -1,5 +1,45 @@ -#!/bin/sh -x +#!/bin/bash -x # vim: set ts=4 sw=4 sts=4 et : -# This script does nothing now. +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi +INSTALLDIR="$(readlink -m mnt)" +umount_kill "${INSTALLDIR}" || : + +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'pre' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "pre" + +# ------------------------------------------------------------------------------ +# Force overwrite of an existing image for now if debootstrap did not seem to complete... +# ------------------------------------------------------------------------------ +debug "Determine if ${IMG} should be reused or deleted..." +if [ -f "${IMG}" ]; then + # Assume a failed debootstrap installation if .prepare_debootstrap does not exist + mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1 + if ! [ -f "${INSTALLDIR}/tmp/.prepared_debootstrap" ]; then + warn "Last build failed. Deleting ${IMG}" + rm -f "${IMG}" + fi + + # Umount image; don't fail if its already umounted + umount_kill "${INSTALLDIR}" || : +fi + +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'post' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "post" diff --git a/scripts_debian/01_install_core.sh b/scripts_debian/01_install_core.sh index a384d23..0c99295 100755 --- a/scripts_debian/01_install_core.sh +++ b/scripts_debian/01_install_core.sh @@ -1,11 +1,38 @@ #!/bin/sh # vim: set ts=4 sw=4 sts=4 et : -. $SCRIPTSDIR/vars.sh +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh -echo "-> Installing base debian system" +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi -COMPONENTS="" debootstrap --arch=amd64 --include=ncurses-term \ - --components=main --keyring=${SCRIPTSDIR}/debian-archive-keyring.gpg \ - $DEBIANVERSION "$INSTALLDIR" http://http.debian.net/debian || { echo "Debootstrap failed!"; exit 1; } +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'pre' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "pre" +# ------------------------------------------------------------------------------ +# Install base debian system +# ------------------------------------------------------------------------------ +if ! [ -f "${INSTALLDIR}/tmp/.prepared_debootstrap" ]; then + debug "Installing base ${DEBIANVERSION} system" + COMPONENTS="" debootstrap --arch=amd64 --include=ncurses-term \ + --components=main --keyring="${SCRIPTSDIR}/keys/${DEBIANVERSION}-debian-archive-keyring.gpg" \ + "${DEBIANVERSION}" "${INSTALLDIR}" "${DEBIAN_MIRROR}" || { error "Debootstrap failed!"; exit 1; } + chroot "${INSTALLDIR}" chmod 0666 "/dev/null" + touch "${INSTALLDIR}/tmp/.prepared_debootstrap" +fi + +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'post' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "post" diff --git a/scripts_debian/02_install_groups.sh b/scripts_debian/02_install_groups.sh index f8ef9c2..7c1d4ca 100755 --- a/scripts_debian/02_install_groups.sh +++ b/scripts_debian/02_install_groups.sh @@ -1,57 +1,201 @@ #!/bin/sh # vim: set ts=4 sw=4 sts=4 et : -. $SCRIPTSDIR/vars.sh +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null -# Set up a temporary policy-rc.d to prevent apt from starting services -# on package installation -cat > $BUILDCHROOT/usr/sbin/policy-rc.d < "${INSTALLDIR}/usr/sbin/policy-rc.d" < Adding debian-security repository." - # security.debian.org only makes sense for stable/wheezy - echo "deb http://security.debian.org/ ${DEBIANVERSION}/updates main" \ - >> "$INSTALLDIR/etc/apt/sources.list" - echo "deb-src http://security.debian.org/ ${DEBIANVERSION}/updates main" \ - >> "$INSTALLDIR/etc/apt/sources.list" - - echo "--> Installing systemd" - # sysvinit gives problems with qubes initramfs, we depend on systemd - # for now. Apt *really* doesn't want to replace sysvinit in wheezy. - # For jessie and newer, sysvinit is provided by sysvinit-core which - # is not an essential package. - echo 'Yes, do as I say!' | chroot $INSTALLDIR apt-get -y \ - --force-yes install systemd-sysv -else # testing/unstable - echo "--> Installing systemd" - chroot $INSTALLDIR apt-get -y install systemd-sysv -fi + chmod 755 "${INSTALLDIR}/usr/sbin/policy-rc.d" -chroot $INSTALLDIR systemctl set-default multi-user.target + # ------------------------------------------------------------------------------ + # Ensure umask set in /etc/login.defs is used (022) + # ------------------------------------------------------------------------------ + echo "session optional pam_umask.so" >> "${INSTALLDIR}/etc/pam.d/common-session" -echo "--> Upgrading system" -chroot $INSTALLDIR apt-get update -chroot $INSTALLDIR apt-get -y upgrade + # ------------------------------------------------------------------------------ + # Add debian security repository + # ------------------------------------------------------------------------------ + debug "Adding debian-security repository." + source="deb http://security.debian.org ${DEBIANVERSION}/updates main" + if ! grep -r -q "$source" "${INSTALLDIR}/etc/apt/sources.list"*; then + touch "${INSTALLDIR}/etc/apt/sources.list" + echo "$source" >> "${INSTALLDIR}/etc/apt/sources.list" + fi + source="deb-src http://security.debian.org ${DEBIANVERSION}/updates main" + if ! grep -r -q "$source" "${INSTALLDIR}/etc/apt/sources.list"*; then + touch "${INSTALLDIR}/etc/apt/sources.list" + echo "$source" >> "${INSTALLDIR}/etc/apt/sources.list" + fi -echo "--> Setting keyboard layout" -chroot $INSTALLDIR debconf-set-selections < Installing extra packages" -xargs chroot $INSTALLDIR apt-get -y install < $SCRIPTSDIR/packages.list + # ------------------------------------------------------------------------------ + # Install extra packages in script_${DEBIANVERSION}/packages.list file + # -and / or- TEMPLATE_FLAVOR directories + # ------------------------------------------------------------------------------ + getFileLocations packages_list "packages.list" "${DIST}" + if [ -z "${packages_list}" ]; then + error "Can not locate a package.list file!" + umount_kill "${INSTALLDIR}" || : + exit 1 + fi + + for package_list in ${packages_list[@]}; do + debug "Installing extra packages from: ${package_list}" + DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + xargs chroot ${INSTALLDIR} apt-get ${APT_GET_OPTIONS} install < "${package_list}" + done -# Remove temporary policy layer so services can start normally in the -# deployed template. -rm -f $BUILDCHROOT/usr/sbin/policy-rc.d + # ------------------------------------------------------------------------------ + # Execute any template flavor or sub flavor scripts after packages are installed + # (Whonix needs dependancies installed before installation) + # ------------------------------------------------------------------------------ + buildStep "$0" "packages_installed" + + # ------------------------------------------------------------------------------ + # Install systemd + # ------------------------------------------------------------------------------ + # - sysvinit gives problems with qubes initramfs, we depend on systemd + # for now. Apt *really* doesn't want to replace sysvinit in wheezy. + # For jessie and newer, sysvinit is provided by sysvinit-core which + # is not an essential package. + # ------------------------------------------------------------------------------ + debug "Installing systemd for debian (${DEBIANVERSION})" + if [ "${DEBIANVERSION}" == "wheezy" ]; then + echo 'Yes, do as I say!' | DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + chroot "${INSTALLDIR}" apt-get ${APT_GET_OPTIONS} remove sysvinit + else + DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + chroot "${INSTALLDIR}" apt-get ${APT_GET_OPTIONS} remove sysvinit + fi + + # Prevent sysvinit from being re-installed + debug "Preventing sysvinit re-installation" + chroot "${INSTALLDIR}" apt-mark hold sysvinit + + # Pin sysvinit to prevent being re-installed + cat > "${INSTALLDIR}/etc/apt/preferences.d/qubes_sysvinit" <> "${INSTALLDIR}/etc/apt/sources.list" + fi + chroot ${INSTALLDIR} apt-get update + DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + chroot ${INSTALLDIR} apt-get ${APT_GET_OPTIONS} -t wheezy-backports install init-system-helpers + fi + + # ------------------------------------------------------------------------------ + # Cleanup + # ------------------------------------------------------------------------------ + # Remove temporary policy layer so services can start normally in the + # deployed template. + rm -f "${INSTALLDIR}/usr/sbin/policy-rc.d" + touch "${INSTALLDIR}/tmp/.prepared_groups" + trap - ERR EXIT + trap + + # Kill all processes and umount all mounts within ${INSTALLDIR}, + # but not ${INSTALLDIR} itself (extra '/' prevents ${INSTALLDIR} from being + # umounted itself) + umount_kill "${INSTALLDIR}/" || : +fi +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'post' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "post" diff --git a/scripts_debian/04_install_qubes.sh b/scripts_debian/04_install_qubes.sh index 8f05f57..6f0d020 100755 --- a/scripts_debian/04_install_qubes.sh +++ b/scripts_debian/04_install_qubes.sh @@ -1,86 +1,154 @@ #!/bin/sh # vim: set ts=4 sw=4 sts=4 et : -. $SCRIPTSDIR/vars.sh +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +# ------------------------------------------------------------------------------ +# If .prepared_groups has not been completed, don't continue +# ------------------------------------------------------------------------------ +if ! [ -f "${INSTALLDIR}/tmp/.prepared_groups" ]; then + error "prepared_groups installataion has not completed!... Exiting" + exit 1 +fi -# Set up a temporary policy-rc.d to prevent apt from starting services -# on package installation -cat > $INSTALLCHROOT/usr/sbin/policy-rc.d < "${INSTALLCHROOT}/usr/sbin/policy-rc.d" < Generate locales" -echo "en_US.UTF-8 UTF-8" >> $INSTALLDIR/etc/locale.gen -chroot $INSTALLDIR locale-gen -chroot $INSTALLDIR update-locale LANG=en_US.UTF-8 - -echo "--> Updating template fstab file..." -cat >> $INSTALLDIR/etc/fstab < Installing qubes packages" -export CUSTOMREPO="$PWD/yum_repo_qubes/$DIST" - -if ! [ -e $CACHEDIR/repo-secring.gpg ]; then - mkdir -p $CACHEDIR - gpg --gen-key --batch <> "${INSTALLDIR}/etc/locale.gen" + chroot "${INSTALLDIR}" locale-gen + chroot "${INSTALLDIR}" update-locale LANG=en_US.UTF-8 + + # -------------------------------------------------------------------------- + # Link mtab + # -------------------------------------------------------------------------- + rm -f "${INSTALLDIR}/etc/mtab" + ln -s "../proc/self/mounts" "${INSTALLDIR}/etc/mtab" + + # -------------------------------------------------------------------------- + # Start of Qubes package installation + # -------------------------------------------------------------------------- + debug "Installing qubes packages" + export CUSTOMREPO="${PWD}/yum_repo_qubes/${DIST}" + + # -------------------------------------------------------------------------- + # Install keyrings + # -------------------------------------------------------------------------- + if ! [ -e "${CACHEDIR}/repo-secring.gpg" ]; then + mkdir -p "${CACHEDIR}" + gpg --gen-key --batch < $INSTALLDIR/etc/apt/sources.list.d/qubes-builder.list < "${INSTALLDIR}/etc/apt/sources.list.d/qubes-builder.list" <> $INSTALLDIR/etc/modules - -sed -i -e '/^mesg n/d' $INSTALLDIR/root/.profile + # -------------------------------------------------------------------------- + # Update system; exit is not successful + # -------------------------------------------------------------------------- + chroot "${INSTALLDIR}" apt-get update || { umount_kill "${INSTALLDIR}"; exit 1; } + + # -------------------------------------------------------------------------- + # Install Qubes packages + # -------------------------------------------------------------------------- + DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + chroot "${INSTALLDIR}" apt-get ${APT_GET_OPTIONS} install $(cat ${SCRIPTSDIR}/packages_qubes.list) || \ + { umount_kill "${INSTALLDIR}"; exit 1; } + + # -------------------------------------------------------------------------- + # Remove Qubes Builder repo from sources.list.d + # -------------------------------------------------------------------------- + umount_kill "${INSTALLDIR}/tmp/qubes_repo" + rm -f "${INSTALLDIR}/etc/apt/sources.list.d/qubes-builder.list" + chroot "${INSTALLDIR}" apt-get update || exit 1 + + # -------------------------------------------------------------------------- + # Remove temporary policy layer so services can start normally in the + # deployed template. + # -------------------------------------------------------------------------- + rm -f "${INSTALLDIR}/usr/sbin/policy-rc.d" + + # -------------------------------------------------------------------------- + # Copy extra files to installation directory. Contains: + # - font fixes for display issues + # -------------------------------------------------------------------------- + copyTree "qubes-files" "${SCRIPTSDIR}" "${INSTALLDIR}" + + touch "${INSTALLDIR}/tmp/.prepared_qubes" +fi -# Kill any processes that might have been started by apt before unmounting -lsof $INSTALLDIR | tail -n +2 | awk '{print $2}' | xargs --no-run-if-empty kill +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'post' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "post" +# ------------------------------------------------------------------------------ +# Kill all processes and umount all mounts within ${INSTALLDIR}, but not +# ${INSTALLDIR} itself (extra '/' prevents ${INSTALLDIR} from being umounted itself) +# ------------------------------------------------------------------------------ +umount_kill "${INSTALLDIR}/" || : diff --git a/scripts_debian/09_cleanup.sh b/scripts_debian/09_cleanup.sh index 6e55efa..b99ae43 100755 --- a/scripts_debian/09_cleanup.sh +++ b/scripts_debian/09_cleanup.sh @@ -1,10 +1,33 @@ #!/bin/sh # vim: set ts=4 sw=4 sts=4 et : -rm -f $INSTALLDIR/var/cache/apt/archives/* +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh -rm -f $INSTALLDIR/etc/apt/sources.list.d/qubes-builder.list -rm -f $INSTALLDIR/etc/apt/trusted.gpg.d/qubes-builder.gpg +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi -rm -rf buildchroot +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'pre' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "pre" +# ------------------------------------------------------------------------------ +# Cleanup any left over files from installation +# ------------------------------------------------------------------------------ +rm -rf "${INSTALLDIR}/var/cache/apt/archives/*" +rm -f "${INSTALLDIR}/etc/apt/sources.list.d/qubes-builder.list" +rm -f "${INSTALLDIR}/etc/apt/trusted.gpg.d/qubes-builder.gpg" + +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor 'post' scripts +# ------------------------------------------------------------------------------ +buildStep "$0" "post" diff --git a/scripts_debian/gnome/packages_jessie.list b/scripts_debian/gnome/packages_jessie.list new file mode 100644 index 0000000..116619d --- /dev/null +++ b/scripts_debian/gnome/packages_jessie.list @@ -0,0 +1,2 @@ +gnome-desktop-environment +gnome-accessibility-themes diff --git a/scripts_debian/gnome/packages_wheezy.list b/scripts_debian/gnome/packages_wheezy.list new file mode 100644 index 0000000..116619d --- /dev/null +++ b/scripts_debian/gnome/packages_wheezy.list @@ -0,0 +1,2 @@ +gnome-desktop-environment +gnome-accessibility-themes diff --git a/scripts_debian/debian-archive-keyring.gpg b/scripts_debian/keys/jessie-debian-archive-keyring.gpg similarity index 100% rename from scripts_debian/debian-archive-keyring.gpg rename to scripts_debian/keys/jessie-debian-archive-keyring.gpg diff --git a/scripts_debian/keys/wheezy-debian-archive-keyring.gpg b/scripts_debian/keys/wheezy-debian-archive-keyring.gpg new file mode 100644 index 0000000..6db1f3a Binary files /dev/null and b/scripts_debian/keys/wheezy-debian-archive-keyring.gpg differ diff --git a/scripts_debian/packages.list b/scripts_debian/packages_jessie.list similarity index 94% rename from scripts_debian/packages.list rename to scripts_debian/packages_jessie.list index 7747fcf..fddb0a6 100644 --- a/scripts_debian/packages.list +++ b/scripts_debian/packages_jessie.list @@ -7,3 +7,4 @@ ncurses-term xserver-xorg-core x11-xserver-utils xinit +acpid diff --git a/scripts_debian/packages_qubes.list b/scripts_debian/packages_qubes.list index d14a42b..6bea80d 100644 --- a/scripts_debian/packages_qubes.list +++ b/scripts_debian/packages_qubes.list @@ -1,2 +1,8 @@ qubes-core-agent qubes-gui-agent +xdg-user-dirs +gnome-themes-standard +xsettingsd +gnome-packagekit +chrony +ntpdate diff --git a/scripts_debian/packages_wheezy.list b/scripts_debian/packages_wheezy.list new file mode 100644 index 0000000..fddb0a6 --- /dev/null +++ b/scripts_debian/packages_wheezy.list @@ -0,0 +1,10 @@ +gnome-terminal +locales +sudo +dmsetup +psmisc +ncurses-term +xserver-xorg-core +x11-xserver-utils +xinit +acpid diff --git a/scripts_debian/qubes-files/.facl b/scripts_debian/qubes-files/.facl new file mode 100644 index 0000000..641da9f --- /dev/null +++ b/scripts_debian/qubes-files/.facl @@ -0,0 +1,70 @@ +# file: . +# owner: user +# group: user +user::rwx +group::r-x +other::r-x + +# file: etc +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/xdg +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/xdg/Xresources +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/xdg/fonts.conf +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/xdg/xsettingsd +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/X11 +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/X11/Xsession.d +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/X11/Xsession.d/25xdg-qubes-settings +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: .facl +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + diff --git a/scripts_debian/vars.sh b/scripts_debian/vars.sh index efc7b5f..ef66a30 100755 --- a/scripts_debian/vars.sh +++ b/scripts_debian/vars.sh @@ -1,13 +1,18 @@ -# The codename of the debian version to install. -# jessie = testing, wheezy = stable -DEBIANVERSION=$DIST +#!/bin/bash + +# ------------------------------------------------------------------------------ +# Global variables and functions +# ------------------------------------------------------------------------------ -EXTRAPKGS="openssh-clients,screen,vim-nox,less" +. ./functions.sh -QUBESDEBIANGIT="http://dsg.is/qubes/" +# The codename of the debian version to install. +# jessie = testing, wheezy = stable +DEBIANVERSION=${DIST} -# make runs the scripts with sudo -E, so HOME is set to /home/user during -# build, which does not exist. We need to write to $HOME/.gnupg so set it -# to something valid. -HOME=/root +# Location to grab debian packages +DEBIAN_MIRROR=http://ftp.us.debian.org/debian +#DEBIAN_MIRROR=http://http.debian.net/debian +#DEBIAN_MIRROR=http://ftp.ca.debian.org/debian +APT_GET_OPTIONS="-o Dpkg::Options::="--force-confnew" --force-yes -y" diff --git a/scripts_debian/wheezy+whonix-gateway/00_prepare_pre.sh b/scripts_debian/wheezy+whonix-gateway/00_prepare_pre.sh new file mode 120000 index 0000000..d1f0dd6 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/00_prepare_pre.sh @@ -0,0 +1 @@ +../wheezy+whonix/00_prepare_pre.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-gateway/01_install_core_post.sh b/scripts_debian/wheezy+whonix-gateway/01_install_core_post.sh new file mode 120000 index 0000000..3524b69 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/01_install_core_post.sh @@ -0,0 +1 @@ +../wheezy+whonix/01_install_core_post.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-gateway/02_install_groups_packages_installed.sh b/scripts_debian/wheezy+whonix-gateway/02_install_groups_packages_installed.sh new file mode 120000 index 0000000..4b74627 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/02_install_groups_packages_installed.sh @@ -0,0 +1 @@ +../wheezy+whonix/02_install_groups_packages_installed.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-gateway/04_install_qubes_post.sh b/scripts_debian/wheezy+whonix-gateway/04_install_qubes_post.sh new file mode 120000 index 0000000..db7d12f --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/04_install_qubes_post.sh @@ -0,0 +1 @@ +../wheezy+whonix/04_install_qubes_post.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-gateway/09_cleanup_post.sh b/scripts_debian/wheezy+whonix-gateway/09_cleanup_post.sh new file mode 120000 index 0000000..9728555 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/09_cleanup_post.sh @@ -0,0 +1 @@ +../wheezy+whonix/09_cleanup_post.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-gateway/99_custom_configuration.sh b/scripts_debian/wheezy+whonix-gateway/99_custom_configuration.sh new file mode 100755 index 0000000..4531e88 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/99_custom_configuration.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : + +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +# ------------------------------------------------------------------------------ +# whonix-netvm-gateway contains last known IP used to search and replace +# ------------------------------------------------------------------------------ +if [ -f "${INSTALLDIR}/tmp/.whonix_post" -a ! -f "${INSTALLDIR}/tmp/.whonix_custom_configurations" ]; then + # -------------------------------------------------------------------------- + # Install Custom Configurations + # -------------------------------------------------------------------------- + echo "10.152.152.10" > "${INSTALLDIR}/etc/whonix-netvm-gateway" + touch "${INSTALLDIR}/tmp/.whonix_custom_configurations" +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/.facl b/scripts_debian/wheezy+whonix-gateway/files/.facl new file mode 100644 index 0000000..56e79de --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/.facl @@ -0,0 +1,252 @@ +# file: . +# owner: user +# group: user +user::rwx +group::r-x +other::r-x + +# file: lib +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib/systemd +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib/systemd/system +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib/systemd/system/qubes-whonix-firewall.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: lib/systemd/system/qubes-whonix-network.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: lib/systemd/system/qubes-whonix-init.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/hosts +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/uwt.d +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/uwt.d/50_uwt_default +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/xdg +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/xdg/autostart +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/xdg/autostart/qubes-whonixsetup.desktop +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/apt +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/hostname +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/sudoers.d +# owner: root +# group: root +user::rwx +group::r-x +other::--- + +# file: etc/sudoers.d/whonix-build +# owner: root +# group: root +user::r-- +group::r-- +other::--- + +# file: .facl +# owner: user +# group: user +user::rw- +group::r-- +other::r-- + +# file: usr +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/utility_functions +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/bind-dirs.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/qubes-whonix-firewall.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/qubes-whonix-bind.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: usr/lib/whonix/init/replace-ips +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/init.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/whonixcheck.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: usr/lib/whonix/init/network-proxy-setup.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/qubes-whonix-tor.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: usr/lib/whonix/messages.yaml +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: usr/lib/whonix/alert +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/qubes-whonixsetup +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/enable-iptables-logging.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + diff --git a/scripts_debian/wheezy+whonix-gateway/files/etc/hostname b/scripts_debian/wheezy+whonix-gateway/files/etc/hostname new file mode 100644 index 0000000..c70dc2d --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/etc/hostname @@ -0,0 +1 @@ +host diff --git a/scripts_debian/wheezy+whonix-gateway/files/etc/hosts b/scripts_debian/wheezy+whonix-gateway/files/etc/hosts new file mode 100644 index 0000000..cc0e30d --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/etc/hosts @@ -0,0 +1,7 @@ +## Anonymity Distribution /etc/hosts + +## Anonymity Distribution specific +127.0.0.1 host.localdomain host +## End of Anonymity Distribution specific + +## End of Anonymity Distribution /etc/hosts diff --git a/scripts_debian/wheezy+whonix-gateway/files/etc/sudoers.d/whonix-build b/scripts_debian/wheezy+whonix-gateway/files/etc/sudoers.d/whonix-build new file mode 100644 index 0000000..5841129 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/etc/sudoers.d/whonix-build @@ -0,0 +1 @@ +user ALL=(ALL) NOPASSWD: ALL diff --git a/scripts_debian/wheezy+whonix-gateway/files/etc/uwt.d/50_uwt_default b/scripts_debian/wheezy+whonix-gateway/files/etc/uwt.d/50_uwt_default new file mode 100644 index 0000000..bac9ef3 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/etc/uwt.d/50_uwt_default @@ -0,0 +1,6 @@ + +. /usr/lib/whonix/utility_functions + +if [ "${WHONIX}" == "template" -a "${PROXY_SECURE}" == "1" ]; then + uwtwrapper["/usr/bin/apt-get"]="0" +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/etc/xdg/autostart/qubes-whonixsetup.desktop b/scripts_debian/wheezy+whonix-gateway/files/etc/xdg/autostart/qubes-whonixsetup.desktop new file mode 100644 index 0000000..260635d --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/etc/xdg/autostart/qubes-whonixsetup.desktop @@ -0,0 +1,8 @@ +## This file is part of Whonix. +## Copyright (C) 2012 - 2014 Patrick Schleizer +## See the file COPYING for copying conditions. + +[Desktop Entry] +Type=Application +Terminal=false +Exec=/usr/lib/whonix/qubes-whonixsetup diff --git a/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-firewall.service b/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-firewall.service new file mode 100644 index 0000000..89a5229 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-firewall.service @@ -0,0 +1,12 @@ +[Unit] +Description=Qubes Whonix firewall updater +After=qubes-whonix-network.service +Before=network.target + +[Service] +ExecStart=/usr/lib/whonix/init/qubes-whonix-firewall.sh +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target +Alias=qubes-firewall.service diff --git a/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-init.service b/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-init.service new file mode 100644 index 0000000..6215c2c --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-init.service @@ -0,0 +1,13 @@ +[Unit] +Description=Qubes Whonix initialization script +After=qubes-whonix-network.service +Before=qubes-whonix-firewall.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/whonix/init/init.sh +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target diff --git a/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-network.service b/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-network.service new file mode 100644 index 0000000..4e71280 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/lib/systemd/system/qubes-whonix-network.service @@ -0,0 +1,15 @@ +[Unit] +Description=Qubes Whonix network proxy setup +ConditionPathExists=/var/run/qubes-service/qubes-network +Before=network.target +After=iptables.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/whonix/init/network-proxy-setup.sh +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target +Alias=qubes-network.service diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/alert b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/alert new file mode 100755 index 0000000..e585475 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/alert @@ -0,0 +1,90 @@ +#!/usr/bin/python + +# +# Copyright 2014 Jason Mehring (nrgaway@gmail.com) +# + +from PyQt4 import QtGui +import locale +import yaml + +DEFAULT_LANG = 'en' + +class Messages(): + filename = None + data = None + language = DEFAULT_LANG + title = None + icon = None + message = None + + def __init__(self, section, filename): + self.filename = filename + + language = locale.getdefaultlocale()[0].split('_')[0] + if language: + self.language = language + + try: + stream = file(filename, 'r') + data = yaml.load(stream) + + if section in data.keys(): + section = data[section] + + self.icon = section.get('icon', None) + + language = section.get(self.language, DEFAULT_LANG) + + self.title = language.get('title', None) + self.message = language.get('message', None) + + except (IOError): + pass + except (yaml.scanner.ScannerError, yaml.parser.ParserError): + pass + +class WhonixMessageBox(QtGui.QMessageBox): + def __init__(self, message): + super(WhonixMessageBox, self).__init__() + self.message = message + self.initUI() + + def initUI(self): + message = self.message + + if message.title: + self.setWindowTitle(message.title) + + if message.icon: + self.setIcon(getattr(QtGui.QMessageBox, message.icon)) + + if message.message: + self.setText(message.message) + self.exec_() + +import argparse +import sys + + + +def main(): + parser = argparse.ArgumentParser(description='Display a QT Message Box') + + parser.add_argument('section', help="Message section") + parser.add_argument('filename', help="File including full path") + + args = parser.parse_args() + + if not args.filename and args.section: + print parser.usage() + sys.exit(1) + + app = QtGui.QApplication(sys.argv) + + message = Messages(args.section, args.filename) + dialog = WhonixMessageBox(message) + sys.exit() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/bind-dirs.sh b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/bind-dirs.sh new file mode 100755 index 0000000..ab2b0be --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/bind-dirs.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# +# To umount all binds, just pass any arg in $1 +# + +. /usr/lib/whonix/utility_functions + +# Don't run if started as a template +if ! [ "${WHONIX}" == "template" ]; then + # Array of directories to bind + BINDS=( + '/rw/srv/whonix/root/.whonix:/root/.whonix' + '/rw/srv/whonix/root/.whonix.d:/root/.whonix.d' + '/rw/srv/whonix/var/lib/whonix:/var/lib/whonix' + '/rw/srv/whonix/var/lib/whonixcheck:/var/lib/whonixcheck' + '/rw/srv/whonix/etc/tor:/etc/tor' + ) + + for bind in ${BINDS[@]}; do + rw_dir="${bind%%:*}" + ro_dir="${bind##*:}" + + # Make sure ro directory is not mounted + umount "${ro_dir}" 2> /dev/null || true + + if [ -n "${1}" ]; then + echo "Umounting only..." + exit 0 + fi + + # Make sure ro directory exists + if ! [ -d "${ro_dir}" ]; then + mkdir -p "${ro_dir}" + fi + + # Initially copy over data directories to /rw if rw directory does not exist + if ! [ -d "${rw_dir}" ]; then + mkdir -p "${rw_dir}" + rsync -hax "${ro_dir}/." "${rw_dir}" + fi + + # Bind the directory + sync + mount --bind "${rw_dir}" "${ro_dir}" + done + sync +fi + +if [ "${WHONIX}" == "gateway" ]; then + # Make sure we remove whonixsetup.done if Tor is not enabled + # to allow choice of repo and prevent whonixcheck errors + grep "^DisableNetwork 0$" /etc/tor/torrc || { + sudo rm -f /var/lib/whonix/do_once/whonixsetup.done + } +fi + +exit 0 diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/enable-iptables-logging.sh b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/enable-iptables-logging.sh new file mode 100755 index 0000000..a8e1653 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/enable-iptables-logging.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Check /var/log/kern.log for logging results + +LOG_IP4=1 +LOG_IP6=0 + +# for IPv4 +if [ "$LOG_IP4" == "1" ]; then + iptables -t raw -A OUTPUT -p icmp -j TRACE + iptables -t raw -A PREROUTING -p icmp -j TRACE + modprobe ipt_LOG +fi + +# for IPv6 +if [ "$LOG_IP6" == "1" ]; then + ip6tables -t raw -A OUTPUT -p icmpv6 --icmpv6-type echo-request -j TRACE + ip6tables -t raw -A OUTPUT -p icmpv6 --icmpv6-type echo-reply -j TRACE + ip6tables -t raw -A PREROUTING -p icmpv6 --icmpv6-type echo-request -j TRACE + ip6tables -t raw -A PREROUTING -p icmpv6 --icmpv6-type echo-reply -j TRACE + modprobe ip6t_LOG +fi + +# Redirect local port to remote via socat +#apt-get install socat +#socat TCP4-LISTEN:8082,fork,mode=0666,user=root,group=root TCP4:10.137.255.254:8082 +# +# Works +# localhost/loopback maps localhost port 8082 to localhost port 8888 +#iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 8082 -j REDIRECT --to-ports 8888 diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/init.sh b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/init.sh new file mode 100755 index 0000000..1839152 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/init.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +if [ "${WHONIX}" != "template" ]; then + # Files that will have the immutable bit set + # since we don't want them modified by other programs + IMMUTABLE_FILES=( + '/etc/resolv.conf' + '/etc/hostname' + '/etc/hosts' + ) + + # Make sure all .anondist files in list are immutable + immutableFilesEnable "${IMMUTABLE_FILES}" + immutableFilesEnable "${IMMUTABLE_FILES}" ".anondist" + + # Make sure we are using a copy of the annondist file and if not + # copy the annondist file and set it immutable + copyAnondist "/etc/resolv.conf" + copyAnondist "/etc/hosts" + copyAnondist "/etc/hostname" + + # Replace IP addresses in known configuration files / scripts to + # currently discovered one + /usr/lib/whonix/init/replace-ips + + # Make sure hostname is correct + /bin/hostname host +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/network-proxy-setup.sh b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/network-proxy-setup.sh new file mode 100755 index 0000000..71a43cf --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/network-proxy-setup.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +INTERFACE="eth1" + +if [ "${WHONIX}" == "gateway" ]; then + + if [ -x /usr/sbin/xenstore-read ]; then + XENSTORE_READ="/usr/sbin/xenstore-read" + else + XENSTORE_READ="/usr/bin/xenstore-read" + fi + + # Setup Xen / Qubes proxy + network=$(xenstore-read qubes-netvm-network 2>/dev/null) + if [ "x$network" != "x" ]; then + gateway=$(xenstore-read qubes-netvm-gateway) + netmask=$(xenstore-read qubes-netvm-netmask) + secondary_dns=$(xenstore-read qubes-netvm-secondary-dns) + modprobe netbk 2> /dev/null || modprobe xen-netback + echo "NS1=$gateway" > /var/run/qubes/qubes-ns + echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns + #/usr/lib/qubes/qubes-setup-dnat-to-ns + echo "0" > /proc/sys/net/ipv4/ip_forward + /sbin/ethtool -K eth0 sg off || : + fi + + # Now, assign it the netvm-gateway IP address + ip=$(${XENSTORE_READ} qubes-netvm-gateway 2> /dev/null) + if [ x${ip} != x ]; then + # Create a dummy eth1 interface so tor can bind to it if there + # are no DOMU virtual machines connected at the moment + /sbin/ip link add ${INTERFACE} type dummy + + netmask=$(${XENSTORE_READ} qubes-netvm-netmask) + gateway=$(${XENSTORE_READ} qubes-netvm-gateway) + /sbin/ifconfig ${INTERFACE} ${ip} netmask 255.255.255.255 + /sbin/ifconfig ${INTERFACE} up + /sbin/ethtool -K ${INTERFACE} sg off || true + /sbin/ethtool -K ${INTERFACE} tx off || true + + ip link set ${INTERFACE} up + fi + + echo "0" > /proc/sys/net/ipv4/ip_forward + + # Allow whonix-gateway to act as an update-proxy + touch /var/run/qubes-service/qubes-updates-proxy + + # Search and replace tinyproxy error files so we can inject code that + # we can use to identify that its a tor proxy so updates are secure + error_file="/usr/share/tinyproxy/default.html" + grep -q "${PROXY_META}" "${error_file}" || { + sed -i "s/<\/head>/${PROXY_META}\n<\/head>/" "${error_file}" + } +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/qubes-whonix-firewall.sh b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/qubes-whonix-firewall.sh new file mode 100755 index 0000000..50c5cbc --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/qubes-whonix-firewall.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +if [ -x /usr/sbin/xenstore-read ]; then + XENSTORE_READ="/usr/sbin/xenstore-read" +else + XENSTORE_READ="/usr/bin/xenstore-read" +fi + +# Make sure IP forwarding is disabled +echo "0" > /proc/sys/net/ipv4/ip_forward + +if [ "${WHONIX}" != "template" ]; then + ip=$(${XENSTORE_READ} qubes-netvm-gateway 2> /dev/null) + + # Start Whonix Firewall + if [ "${WHONIX}" == "gateway" ]; then + export INT_IF="vif+" + export INT_TIF="vif+" + + # Inject custom firewall rules into whonix_firewall + sed -i -f - /usr/bin/whonix_firewall <<-EOF +/^## IPv4 DROP INVALID INCOMING PACKAGES/,/######################################/c \\ +## IPv4 DROP INVALID INCOMING PACKAGES \\ +## \\ +## --- THE FOLLOWING WS INJECTED --- \\ +## Qubes Tiny Proxy Updater \\ +iptables -t nat -N PR-QBS-SERVICES \\ +iptables -A INPUT -i vif+ -p tcp -m tcp --dport 8082 -j ACCEPT \\ +iptables -A OUTPUT -o vif+ -p tcp -m tcp --sport 8082 -j ACCEPT \\ +iptables -t nat -A PREROUTING -j PR-QBS-SERVICES \\ +iptables -t nat -A PR-QBS-SERVICES -d 10.137.255.254/32 -i vif+ -p tcp -m tcp --dport 8082 -j REDIRECT \\ +iptables -t nat -A OUTPUT -p udp -m owner --uid-owner tinyproxy -m conntrack --ctstate NEW -j DNAT --to ${ip}:53 \\ +iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner tinyproxy -m conntrack --ctstate NEW -j DNAT --to ${ip}:9040 \\ +\\ +# Route any traffic FROM netvm TO netvm BACK-TO localhost \\ +# Allows localhost access to tor network \\ +#iptables -t nat -A OUTPUT -s ${ip} -d ${ip} -j DNAT --to-destination 127.0.0.1 \\ +###################################### +EOF + fi + + # Load the firewall + # XXX: TODO: Take down all network accesss if firewall fails + /usr/bin/whonix_firewall + + systemctl restart qubes-updates-proxy.service +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/qubes-whonix-tor.service b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/qubes-whonix-tor.service new file mode 100644 index 0000000..0a83e1b --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/qubes-whonix-tor.service @@ -0,0 +1,16 @@ +[Unit] +Description = Anonymizing overlay network for TCP +After = syslog.target network.target nss-lookup.target + +[Service] +Type = simple +ExecStart = /usr/bin/tor --runasdaemon 0 --defaults-torrc /usr/share/tor/tor-service-defaults-torrc -f /etc/tor/torrc --quiet +ExecReload = /bin/kill -HUP ${MAINPID} +ExecStop = /bin/kill -INT ${MAINPID} +TimeoutSec = 60 +Restart = on-failure +LimitNOFILE = 32768 + +[Install] +WantedBy = multi-user.target +Alias=tor.service diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/replace-ips b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/replace-ips new file mode 100755 index 0000000..900a584 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/replace-ips @@ -0,0 +1,118 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +# Search though files and updates IP address to the current +# IP address(es) + +FILES=( + '/usr/lib/leaktest-workstation/simple_ping.py' + '/usr/lib/whonixcheck/preparation' + '/usr/share/anon-kde-streamiso/share/config/kioslaverc' + '/usr/bin/whonix_firewall' + '/etc/whonix_firewall.d/30_default' + '/usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh' + '/usr/bin/uwt' + '/etc/uwt.d/30_uwt_default' + '/usr/share/tor/tor-service-defaults-torrc.anondist' + '/usr/bin/update-torbrowser' + '/etc/network/interfaces.whonix' + '/etc/resolv.conf.anondist' + '/etc/sdwdate.d/31_anon_dist_stream_isolation_plugin' + '/etc/rinetd.conf.anondist' + '/etc/network/interfaces.whonix' + '/usr/share/anon-torchat/.torchat/torchat.ini' +) + +# sed search and replace. return 0 if replace happened, otherwise 1 +search_replace() { + local search="${1}" + local replace="${2}" + local file="${3}" + local retval=1 + + if ! [ -L "${file}" ]; then + ls_attrs="$(lsattr "${file}")" + ls_attrs=${ls_attrs:4:1} + if [ "${ls_attrs}" == "i" ]; then + chattr -i "${file}" + fi + fi + + sed -i.bak '/'"${search}"'/,${s//'"${replace}"'/;b};$q1' "${file}" + retval=$? + + if [ "${ls_attrs}" = "i" ]; then + chattr +i "${file}" + fi + + return $retval +} + +function replace_ips() +{ + local search_ip="${1}" + local replace_ip="${2}" + local files=("${!3}") + local retval=1 + + # If IP is 10.152.152.10, network is 10.152.152.0 + search_network="${search_ip%[.]*}.0" + replace_network="${replace_ip%[.]*}.0" + + if ! [ "${search_ip}" = "${replace_ip}" ]; then + for file in "${files[@]}"; do + if [ -f "$file" ]; then + search_replace "${search_ip}" "${replace_ip}" "${file}" && retval=0 + search_replace "${search_network}" "${replace_network}" "${file}" && retval=0 + fi + done + fi + + return $retval +} + +update_ip() { + ip=${1} + + echo "${ip}" > /etc/whonix-netvm-gateway + grep '^DisableNetwork 0$' /etc/tor/torrc && { + service tor status && { + service tor reload || true; + } + } +} + +if [ "${WHONIX}" == "gateway" ]; then + ip="$(xenstore-read qubes-netvm-gateway)" + if [ x${ip} != x ]; then + # Compare to current IP address assiged by Qubes + replace_ips "$(cat /etc/whonix-netvm-gateway)" "${ip}" FILES[@] && update_ip "${ip}" + + # Do again; checking for original 10.152.152.10 incase of update + replace_ips "10.152.152.10" "${ip}" FILES[@] && update_ip "${ip}" + + # Do again; checking for original 10.152.152.11 incase of update + replace_ips "10.152.152.11" "${ip}" FILES[@] && update_ip "${ip}" + fi + +elif [ "${WHONIX}" == "workstation" ]; then + ip="$(xenstore-read qubes-ip)" + gateway="$(xenstore-read qubes-gateway)" + + if [ x${ip} != x ]; then + # Compare to current IP address assiged by Qubes + replace_ips "$(cat /etc/whonix-ip)" "${ip}" FILES[@] && echo "${ip}" > /etc/whonix-ip + + # Do again; checking for original 10.152.152.11 incase of update + replace_ips "10.152.152.11" "${ip}" FILES[@] && echo "${ip}" > /etc/whonix-ip + fi + + if [ x${gateway} != x ]; then + # Compare to current gateway IP address assiged by Qubes + replace_ips "$(cat /etc/whonix-netvm-gateway)" "${gateway}" FILES[@] && echo "${gateway}" > /etc/whonix-netvm-gateway + + # Do again; checking for original 10.152.152.10 incase of update + replace_ips "10.152.152.10" "${gateway}" FILES[@] && echo "${gateway}" > /etc/whonix-netvm-gateway + fi +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/whonixcheck.service b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/whonixcheck.service new file mode 100644 index 0000000..5f883d2 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/init/whonixcheck.service @@ -0,0 +1,18 @@ +[Unit] +Description=Checks many important aspects of Whonix. +After=syslog.target network.target + +[Service] +Type=forking +ExecStartPre=/usr/bin/install -m 0775 -d --owner user --group user /var/run/whonixcheck +ExecStartPre=/usr/bin/install -m 0775 -d --owner user --group user /var/lib/whonixcheck +ExecStartPre=/usr/bin/install -m 0775 -d --owner user --group user /var/lib/whonix/whonixblog +ExecStart=/usr/lib/whonixcheckdaemon +PIDFile=/var/run/whonixcheck.pid +User=user +Group=user +UMask=0007 +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/messages.yaml b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/messages.yaml new file mode 100644 index 0000000..075ab09 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/messages.yaml @@ -0,0 +1,9 @@ + +update: + icon: Critical + en: + title: Tor netvm required for updates + message: | +

Tor netvm required for updates!

+

Please ensure your template vm has a Whonix gateway as it's VM.

+

No updates are possible without an active (running) Whonix gateway VM.

diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/qubes-whonixsetup b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/qubes-whonixsetup new file mode 100755 index 0000000..f90d15b --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/qubes-whonixsetup @@ -0,0 +1,41 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +if ! [ "${WHONIX}" == "template" ]; then + sudo /usr/lib/whonix/bind-dirs.sh +fi + +if [ "${WHONIX}" == "gateway" ]; then + if grep "^DisableNetwork 0$" /etc/tor/torrc ;then + sudo service sdwdate restart + sudo service tor restart + else + sudo service sdwdate restart + sudo service tor stop + sudo /usr/bin/whonixsetup + fi + +elif [ "${WHONIX}" == "workstation" ]; then + sudo service sdwdate restart + if ! [ -f "/var/lib/whonix/do_once/whonixsetup.done" ]; then + sudo /usr/bin/whonixsetup + fi + +elif [ "${WHONIX}" == "template" -a "${PROXY_SECURE}" == "0" ]; then + # Set secure defaults. + sudo iptables -P INPUT DROP + sudo iptables -P FORWARD DROP + sudo iptables -P OUTPUT DROP + + # Flush old rules. + sudo iptables -F + sudo iptables -X + sudo iptables -t nat -F + sudo iptables -t nat -X + sudo iptables -t mangle -F + sudo iptables -t mangle -X + + # Display warning that netvm is not connected to a torvm + /usr/lib/whonix/alert update /usr/lib/whonix/messages.yaml +fi diff --git a/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/utility_functions b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/utility_functions new file mode 100755 index 0000000..8a3b4e7 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/files/usr/lib/whonix/utility_functions @@ -0,0 +1,94 @@ +#!/bin/bash + +# /etc/uwt.d/50_uwt_default relies on this in order to allow connection +# to proxy for template +PROXY_SERVER="http://10.137.255.254:8082/" +PROXY_META='' + +if [ -f "/var/run/qubes-service/updates-proxy-setup" ]; then + WHONIX="template" +elif [ -f "/usr/share/anon-gw-base-files/gateway" ]; then + WHONIX="gateway" +elif [ -f "/usr/share/anon-ws-base-files/workstation" ]; then + WHONIX="workstation" +else + WHONIX="unknown" +fi + +if [ "${WHONIX}" == "template" ]; then + curl.anondist-orig "${PROXY_SERVER}" | grep -q "${PROXY_META}" && { + PROXY_SECURE=1 + } || { + PROXY_SECURE=0 + } +fi + +immutableFilesEnable() { + files="${1}" + suffix="${2}" + + for file in "${files[@]}"; do + if [ -f "${file}" ] && ! [ -L "${file}" ]; then + sudo chattr +i "${file}${suffix}" + fi + done +} + +immutableFilesDisable() { + files="${1}" + suffix="${2}" + + for file in "${files[@]}"; do + if [ -f "${file}" ] && ! [ -L "${file}" ]; then + sudo chattr -i "${file}${suffix}" + fi + done +} + +copyAnondist() { + file="${1}" + suffix="${2-.anondist}" + + # Remove any softlinks first + if [ -L "${file}" ]; then + sudo rm -f "${file}" + fi + + if [ -f "${file}" ] && [ -n "$(diff ${file} ${file}${suffix})" ]; then + sudo chattr -i "${file}" + sudo rm -f "${file}" + sudo cp -p "${file}${suffix}" "${file}" + sudo chattr +i "${file}" + elif ! [ -f "${file}" ]; then + sudo cp -p "${file}${suffix}" "${file}" + sudo chattr +i "${file}" + fi +} + +# Will only enable / disable if service is not already in that state +enable_sysv() { + servicename=${1} + disable=${2-0} + + # Check to see if the service is already enabled and if not, enable it + string="/etc/rc$(runlevel | awk '{ print $2 }').d/S[0-9][0-9]${servicename}" + + if [ $(find $string 2>/dev/null | wc -l) -eq ${disable} ] ; then + case ${disable} in + 0) + echo "${1} is currently disabled; enabling it" + sudo systemctl --quiet enable ${servicename} + ;; + 1) + echo "${1} is currently enabled; disabling it" + sudo service ${servicename} stop + sudo systemctl --quiet disable ${servicename} + ;; + esac + fi +} + +disable_sysv() { + enable_sysv ${1} 1 +} + diff --git a/scripts_debian/wheezy+whonix-gateway/packages_wheezy.list b/scripts_debian/wheezy+whonix-gateway/packages_wheezy.list new file mode 120000 index 0000000..d5dfb50 --- /dev/null +++ b/scripts_debian/wheezy+whonix-gateway/packages_wheezy.list @@ -0,0 +1 @@ +../wheezy+whonix/packages_wheezy.list \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/00_prepare_pre.sh b/scripts_debian/wheezy+whonix-workstation/00_prepare_pre.sh new file mode 120000 index 0000000..d1f0dd6 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/00_prepare_pre.sh @@ -0,0 +1 @@ +../wheezy+whonix/00_prepare_pre.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/01_install_core_post.sh b/scripts_debian/wheezy+whonix-workstation/01_install_core_post.sh new file mode 120000 index 0000000..3524b69 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/01_install_core_post.sh @@ -0,0 +1 @@ +../wheezy+whonix/01_install_core_post.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/02_install_groups_packages_installed.sh b/scripts_debian/wheezy+whonix-workstation/02_install_groups_packages_installed.sh new file mode 120000 index 0000000..4b74627 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/02_install_groups_packages_installed.sh @@ -0,0 +1 @@ +../wheezy+whonix/02_install_groups_packages_installed.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/04_install_qubes_post.sh b/scripts_debian/wheezy+whonix-workstation/04_install_qubes_post.sh new file mode 120000 index 0000000..db7d12f --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/04_install_qubes_post.sh @@ -0,0 +1 @@ +../wheezy+whonix/04_install_qubes_post.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/09_cleanup_post.sh b/scripts_debian/wheezy+whonix-workstation/09_cleanup_post.sh new file mode 120000 index 0000000..9728555 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/09_cleanup_post.sh @@ -0,0 +1 @@ +../wheezy+whonix/09_cleanup_post.sh \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/99_custom_configuration.sh b/scripts_debian/wheezy+whonix-workstation/99_custom_configuration.sh new file mode 100755 index 0000000..e36dc97 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/99_custom_configuration.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : + +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +# ------------------------------------------------------------------------------ +# whonix-netvm-gateway contains last known IP used to search and replace +# ------------------------------------------------------------------------------ +if [ -f "${INSTALLDIR}/tmp/.whonix_prepared" -a ! -f "${INSTALLDIR}/tmp/.whonix_custom_configurations" ]; then + # -------------------------------------------------------------------------- + # Install Custom Configurations + # -------------------------------------------------------------------------- + echo "10.152.152.11" > "${INSTALLDIR}/etc/whonix-ip" + echo "10.152.152.10" > "${INSTALLDIR}/etc/whonix-netvm-gateway" + + touch "${INSTALLDIR}/tmp/.whonix_custom_configurations" +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/.facl b/scripts_debian/wheezy+whonix-workstation/files/.facl new file mode 100644 index 0000000..9056544 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/.facl @@ -0,0 +1,224 @@ +# file: . +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib/systemd +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib/systemd/system +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: lib/systemd/system/qubes-whonix-firewall.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: lib/systemd/system/qubes-whonix-network.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: lib/systemd/system/qubes-whonix-init.service +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/hosts +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/uwt.d +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/uwt.d/50_uwt_default +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/xdg +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/xdg/autostart +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: etc/xdg/autostart/qubes-whonixsetup.desktop +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/hostname +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: etc/sudoers.d +# owner: root +# group: root +user::rwx +group::r-x +other::--- + +# file: etc/sudoers.d/whonix-build +# owner: root +# group: root +user::r-- +group::r-- +other::--- + +# file: .facl +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: usr +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/utility_functions +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/bind-dirs.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/qubes-whonix-firewall.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/replace-ips +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/init.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/init/network-proxy-setup.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/messages.yaml +# owner: root +# group: root +user::rw- +group::r-- +other::r-- + +# file: usr/lib/whonix/alert +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/qubes-whonixsetup +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + +# file: usr/lib/whonix/enable-iptables-logging.sh +# owner: root +# group: root +user::rwx +group::r-x +other::r-x + diff --git a/scripts_debian/wheezy+whonix-workstation/files/etc/hostname b/scripts_debian/wheezy+whonix-workstation/files/etc/hostname new file mode 100644 index 0000000..c70dc2d --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/etc/hostname @@ -0,0 +1 @@ +host diff --git a/scripts_debian/wheezy+whonix-workstation/files/etc/hosts b/scripts_debian/wheezy+whonix-workstation/files/etc/hosts new file mode 100644 index 0000000..cc0e30d --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/etc/hosts @@ -0,0 +1,7 @@ +## Anonymity Distribution /etc/hosts + +## Anonymity Distribution specific +127.0.0.1 host.localdomain host +## End of Anonymity Distribution specific + +## End of Anonymity Distribution /etc/hosts diff --git a/scripts_debian/wheezy+whonix-workstation/files/etc/sudoers.d/whonix-build b/scripts_debian/wheezy+whonix-workstation/files/etc/sudoers.d/whonix-build new file mode 100644 index 0000000..5841129 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/etc/sudoers.d/whonix-build @@ -0,0 +1 @@ +user ALL=(ALL) NOPASSWD: ALL diff --git a/scripts_debian/wheezy+whonix-workstation/files/etc/uwt.d/50_uwt_default b/scripts_debian/wheezy+whonix-workstation/files/etc/uwt.d/50_uwt_default new file mode 100644 index 0000000..bac9ef3 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/etc/uwt.d/50_uwt_default @@ -0,0 +1,6 @@ + +. /usr/lib/whonix/utility_functions + +if [ "${WHONIX}" == "template" -a "${PROXY_SECURE}" == "1" ]; then + uwtwrapper["/usr/bin/apt-get"]="0" +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/etc/xdg/autostart/qubes-whonixsetup.desktop b/scripts_debian/wheezy+whonix-workstation/files/etc/xdg/autostart/qubes-whonixsetup.desktop new file mode 100644 index 0000000..260635d --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/etc/xdg/autostart/qubes-whonixsetup.desktop @@ -0,0 +1,8 @@ +## This file is part of Whonix. +## Copyright (C) 2012 - 2014 Patrick Schleizer +## See the file COPYING for copying conditions. + +[Desktop Entry] +Type=Application +Terminal=false +Exec=/usr/lib/whonix/qubes-whonixsetup diff --git a/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-firewall.service b/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-firewall.service new file mode 100644 index 0000000..89a5229 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-firewall.service @@ -0,0 +1,12 @@ +[Unit] +Description=Qubes Whonix firewall updater +After=qubes-whonix-network.service +Before=network.target + +[Service] +ExecStart=/usr/lib/whonix/init/qubes-whonix-firewall.sh +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target +Alias=qubes-firewall.service diff --git a/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-init.service b/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-init.service new file mode 100644 index 0000000..6215c2c --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-init.service @@ -0,0 +1,13 @@ +[Unit] +Description=Qubes Whonix initialization script +After=qubes-whonix-network.service +Before=qubes-whonix-firewall.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/whonix/init/init.sh +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target diff --git a/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-network.service b/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-network.service new file mode 100644 index 0000000..4e71280 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/lib/systemd/system/qubes-whonix-network.service @@ -0,0 +1,15 @@ +[Unit] +Description=Qubes Whonix network proxy setup +ConditionPathExists=/var/run/qubes-service/qubes-network +Before=network.target +After=iptables.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/whonix/init/network-proxy-setup.sh +StandardOutput=syslog + +[Install] +WantedBy=multi-user.target +Alias=qubes-network.service diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/alert b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/alert new file mode 100755 index 0000000..e585475 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/alert @@ -0,0 +1,90 @@ +#!/usr/bin/python + +# +# Copyright 2014 Jason Mehring (nrgaway@gmail.com) +# + +from PyQt4 import QtGui +import locale +import yaml + +DEFAULT_LANG = 'en' + +class Messages(): + filename = None + data = None + language = DEFAULT_LANG + title = None + icon = None + message = None + + def __init__(self, section, filename): + self.filename = filename + + language = locale.getdefaultlocale()[0].split('_')[0] + if language: + self.language = language + + try: + stream = file(filename, 'r') + data = yaml.load(stream) + + if section in data.keys(): + section = data[section] + + self.icon = section.get('icon', None) + + language = section.get(self.language, DEFAULT_LANG) + + self.title = language.get('title', None) + self.message = language.get('message', None) + + except (IOError): + pass + except (yaml.scanner.ScannerError, yaml.parser.ParserError): + pass + +class WhonixMessageBox(QtGui.QMessageBox): + def __init__(self, message): + super(WhonixMessageBox, self).__init__() + self.message = message + self.initUI() + + def initUI(self): + message = self.message + + if message.title: + self.setWindowTitle(message.title) + + if message.icon: + self.setIcon(getattr(QtGui.QMessageBox, message.icon)) + + if message.message: + self.setText(message.message) + self.exec_() + +import argparse +import sys + + + +def main(): + parser = argparse.ArgumentParser(description='Display a QT Message Box') + + parser.add_argument('section', help="Message section") + parser.add_argument('filename', help="File including full path") + + args = parser.parse_args() + + if not args.filename and args.section: + print parser.usage() + sys.exit(1) + + app = QtGui.QApplication(sys.argv) + + message = Messages(args.section, args.filename) + dialog = WhonixMessageBox(message) + sys.exit() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/bind-dirs.sh b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/bind-dirs.sh new file mode 100755 index 0000000..ab2b0be --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/bind-dirs.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# +# To umount all binds, just pass any arg in $1 +# + +. /usr/lib/whonix/utility_functions + +# Don't run if started as a template +if ! [ "${WHONIX}" == "template" ]; then + # Array of directories to bind + BINDS=( + '/rw/srv/whonix/root/.whonix:/root/.whonix' + '/rw/srv/whonix/root/.whonix.d:/root/.whonix.d' + '/rw/srv/whonix/var/lib/whonix:/var/lib/whonix' + '/rw/srv/whonix/var/lib/whonixcheck:/var/lib/whonixcheck' + '/rw/srv/whonix/etc/tor:/etc/tor' + ) + + for bind in ${BINDS[@]}; do + rw_dir="${bind%%:*}" + ro_dir="${bind##*:}" + + # Make sure ro directory is not mounted + umount "${ro_dir}" 2> /dev/null || true + + if [ -n "${1}" ]; then + echo "Umounting only..." + exit 0 + fi + + # Make sure ro directory exists + if ! [ -d "${ro_dir}" ]; then + mkdir -p "${ro_dir}" + fi + + # Initially copy over data directories to /rw if rw directory does not exist + if ! [ -d "${rw_dir}" ]; then + mkdir -p "${rw_dir}" + rsync -hax "${ro_dir}/." "${rw_dir}" + fi + + # Bind the directory + sync + mount --bind "${rw_dir}" "${ro_dir}" + done + sync +fi + +if [ "${WHONIX}" == "gateway" ]; then + # Make sure we remove whonixsetup.done if Tor is not enabled + # to allow choice of repo and prevent whonixcheck errors + grep "^DisableNetwork 0$" /etc/tor/torrc || { + sudo rm -f /var/lib/whonix/do_once/whonixsetup.done + } +fi + +exit 0 diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/enable-iptables-logging.sh b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/enable-iptables-logging.sh new file mode 100755 index 0000000..a8e1653 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/enable-iptables-logging.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Check /var/log/kern.log for logging results + +LOG_IP4=1 +LOG_IP6=0 + +# for IPv4 +if [ "$LOG_IP4" == "1" ]; then + iptables -t raw -A OUTPUT -p icmp -j TRACE + iptables -t raw -A PREROUTING -p icmp -j TRACE + modprobe ipt_LOG +fi + +# for IPv6 +if [ "$LOG_IP6" == "1" ]; then + ip6tables -t raw -A OUTPUT -p icmpv6 --icmpv6-type echo-request -j TRACE + ip6tables -t raw -A OUTPUT -p icmpv6 --icmpv6-type echo-reply -j TRACE + ip6tables -t raw -A PREROUTING -p icmpv6 --icmpv6-type echo-request -j TRACE + ip6tables -t raw -A PREROUTING -p icmpv6 --icmpv6-type echo-reply -j TRACE + modprobe ip6t_LOG +fi + +# Redirect local port to remote via socat +#apt-get install socat +#socat TCP4-LISTEN:8082,fork,mode=0666,user=root,group=root TCP4:10.137.255.254:8082 +# +# Works +# localhost/loopback maps localhost port 8082 to localhost port 8888 +#iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 8082 -j REDIRECT --to-ports 8888 diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/init.sh b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/init.sh new file mode 100755 index 0000000..1839152 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/init.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +if [ "${WHONIX}" != "template" ]; then + # Files that will have the immutable bit set + # since we don't want them modified by other programs + IMMUTABLE_FILES=( + '/etc/resolv.conf' + '/etc/hostname' + '/etc/hosts' + ) + + # Make sure all .anondist files in list are immutable + immutableFilesEnable "${IMMUTABLE_FILES}" + immutableFilesEnable "${IMMUTABLE_FILES}" ".anondist" + + # Make sure we are using a copy of the annondist file and if not + # copy the annondist file and set it immutable + copyAnondist "/etc/resolv.conf" + copyAnondist "/etc/hosts" + copyAnondist "/etc/hostname" + + # Replace IP addresses in known configuration files / scripts to + # currently discovered one + /usr/lib/whonix/init/replace-ips + + # Make sure hostname is correct + /bin/hostname host +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/network-proxy-setup.sh b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/network-proxy-setup.sh new file mode 100755 index 0000000..71a43cf --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/network-proxy-setup.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +INTERFACE="eth1" + +if [ "${WHONIX}" == "gateway" ]; then + + if [ -x /usr/sbin/xenstore-read ]; then + XENSTORE_READ="/usr/sbin/xenstore-read" + else + XENSTORE_READ="/usr/bin/xenstore-read" + fi + + # Setup Xen / Qubes proxy + network=$(xenstore-read qubes-netvm-network 2>/dev/null) + if [ "x$network" != "x" ]; then + gateway=$(xenstore-read qubes-netvm-gateway) + netmask=$(xenstore-read qubes-netvm-netmask) + secondary_dns=$(xenstore-read qubes-netvm-secondary-dns) + modprobe netbk 2> /dev/null || modprobe xen-netback + echo "NS1=$gateway" > /var/run/qubes/qubes-ns + echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns + #/usr/lib/qubes/qubes-setup-dnat-to-ns + echo "0" > /proc/sys/net/ipv4/ip_forward + /sbin/ethtool -K eth0 sg off || : + fi + + # Now, assign it the netvm-gateway IP address + ip=$(${XENSTORE_READ} qubes-netvm-gateway 2> /dev/null) + if [ x${ip} != x ]; then + # Create a dummy eth1 interface so tor can bind to it if there + # are no DOMU virtual machines connected at the moment + /sbin/ip link add ${INTERFACE} type dummy + + netmask=$(${XENSTORE_READ} qubes-netvm-netmask) + gateway=$(${XENSTORE_READ} qubes-netvm-gateway) + /sbin/ifconfig ${INTERFACE} ${ip} netmask 255.255.255.255 + /sbin/ifconfig ${INTERFACE} up + /sbin/ethtool -K ${INTERFACE} sg off || true + /sbin/ethtool -K ${INTERFACE} tx off || true + + ip link set ${INTERFACE} up + fi + + echo "0" > /proc/sys/net/ipv4/ip_forward + + # Allow whonix-gateway to act as an update-proxy + touch /var/run/qubes-service/qubes-updates-proxy + + # Search and replace tinyproxy error files so we can inject code that + # we can use to identify that its a tor proxy so updates are secure + error_file="/usr/share/tinyproxy/default.html" + grep -q "${PROXY_META}" "${error_file}" || { + sed -i "s/<\/head>/${PROXY_META}\n<\/head>/" "${error_file}" + } +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/qubes-whonix-firewall.sh b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/qubes-whonix-firewall.sh new file mode 100755 index 0000000..50c5cbc --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/qubes-whonix-firewall.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +if [ -x /usr/sbin/xenstore-read ]; then + XENSTORE_READ="/usr/sbin/xenstore-read" +else + XENSTORE_READ="/usr/bin/xenstore-read" +fi + +# Make sure IP forwarding is disabled +echo "0" > /proc/sys/net/ipv4/ip_forward + +if [ "${WHONIX}" != "template" ]; then + ip=$(${XENSTORE_READ} qubes-netvm-gateway 2> /dev/null) + + # Start Whonix Firewall + if [ "${WHONIX}" == "gateway" ]; then + export INT_IF="vif+" + export INT_TIF="vif+" + + # Inject custom firewall rules into whonix_firewall + sed -i -f - /usr/bin/whonix_firewall <<-EOF +/^## IPv4 DROP INVALID INCOMING PACKAGES/,/######################################/c \\ +## IPv4 DROP INVALID INCOMING PACKAGES \\ +## \\ +## --- THE FOLLOWING WS INJECTED --- \\ +## Qubes Tiny Proxy Updater \\ +iptables -t nat -N PR-QBS-SERVICES \\ +iptables -A INPUT -i vif+ -p tcp -m tcp --dport 8082 -j ACCEPT \\ +iptables -A OUTPUT -o vif+ -p tcp -m tcp --sport 8082 -j ACCEPT \\ +iptables -t nat -A PREROUTING -j PR-QBS-SERVICES \\ +iptables -t nat -A PR-QBS-SERVICES -d 10.137.255.254/32 -i vif+ -p tcp -m tcp --dport 8082 -j REDIRECT \\ +iptables -t nat -A OUTPUT -p udp -m owner --uid-owner tinyproxy -m conntrack --ctstate NEW -j DNAT --to ${ip}:53 \\ +iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner tinyproxy -m conntrack --ctstate NEW -j DNAT --to ${ip}:9040 \\ +\\ +# Route any traffic FROM netvm TO netvm BACK-TO localhost \\ +# Allows localhost access to tor network \\ +#iptables -t nat -A OUTPUT -s ${ip} -d ${ip} -j DNAT --to-destination 127.0.0.1 \\ +###################################### +EOF + fi + + # Load the firewall + # XXX: TODO: Take down all network accesss if firewall fails + /usr/bin/whonix_firewall + + systemctl restart qubes-updates-proxy.service +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/replace-ips b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/replace-ips new file mode 100755 index 0000000..900a584 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/init/replace-ips @@ -0,0 +1,118 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +# Search though files and updates IP address to the current +# IP address(es) + +FILES=( + '/usr/lib/leaktest-workstation/simple_ping.py' + '/usr/lib/whonixcheck/preparation' + '/usr/share/anon-kde-streamiso/share/config/kioslaverc' + '/usr/bin/whonix_firewall' + '/etc/whonix_firewall.d/30_default' + '/usr/lib/anon-shared-helper-scripts/tor_bootstrap_check.bsh' + '/usr/bin/uwt' + '/etc/uwt.d/30_uwt_default' + '/usr/share/tor/tor-service-defaults-torrc.anondist' + '/usr/bin/update-torbrowser' + '/etc/network/interfaces.whonix' + '/etc/resolv.conf.anondist' + '/etc/sdwdate.d/31_anon_dist_stream_isolation_plugin' + '/etc/rinetd.conf.anondist' + '/etc/network/interfaces.whonix' + '/usr/share/anon-torchat/.torchat/torchat.ini' +) + +# sed search and replace. return 0 if replace happened, otherwise 1 +search_replace() { + local search="${1}" + local replace="${2}" + local file="${3}" + local retval=1 + + if ! [ -L "${file}" ]; then + ls_attrs="$(lsattr "${file}")" + ls_attrs=${ls_attrs:4:1} + if [ "${ls_attrs}" == "i" ]; then + chattr -i "${file}" + fi + fi + + sed -i.bak '/'"${search}"'/,${s//'"${replace}"'/;b};$q1' "${file}" + retval=$? + + if [ "${ls_attrs}" = "i" ]; then + chattr +i "${file}" + fi + + return $retval +} + +function replace_ips() +{ + local search_ip="${1}" + local replace_ip="${2}" + local files=("${!3}") + local retval=1 + + # If IP is 10.152.152.10, network is 10.152.152.0 + search_network="${search_ip%[.]*}.0" + replace_network="${replace_ip%[.]*}.0" + + if ! [ "${search_ip}" = "${replace_ip}" ]; then + for file in "${files[@]}"; do + if [ -f "$file" ]; then + search_replace "${search_ip}" "${replace_ip}" "${file}" && retval=0 + search_replace "${search_network}" "${replace_network}" "${file}" && retval=0 + fi + done + fi + + return $retval +} + +update_ip() { + ip=${1} + + echo "${ip}" > /etc/whonix-netvm-gateway + grep '^DisableNetwork 0$' /etc/tor/torrc && { + service tor status && { + service tor reload || true; + } + } +} + +if [ "${WHONIX}" == "gateway" ]; then + ip="$(xenstore-read qubes-netvm-gateway)" + if [ x${ip} != x ]; then + # Compare to current IP address assiged by Qubes + replace_ips "$(cat /etc/whonix-netvm-gateway)" "${ip}" FILES[@] && update_ip "${ip}" + + # Do again; checking for original 10.152.152.10 incase of update + replace_ips "10.152.152.10" "${ip}" FILES[@] && update_ip "${ip}" + + # Do again; checking for original 10.152.152.11 incase of update + replace_ips "10.152.152.11" "${ip}" FILES[@] && update_ip "${ip}" + fi + +elif [ "${WHONIX}" == "workstation" ]; then + ip="$(xenstore-read qubes-ip)" + gateway="$(xenstore-read qubes-gateway)" + + if [ x${ip} != x ]; then + # Compare to current IP address assiged by Qubes + replace_ips "$(cat /etc/whonix-ip)" "${ip}" FILES[@] && echo "${ip}" > /etc/whonix-ip + + # Do again; checking for original 10.152.152.11 incase of update + replace_ips "10.152.152.11" "${ip}" FILES[@] && echo "${ip}" > /etc/whonix-ip + fi + + if [ x${gateway} != x ]; then + # Compare to current gateway IP address assiged by Qubes + replace_ips "$(cat /etc/whonix-netvm-gateway)" "${gateway}" FILES[@] && echo "${gateway}" > /etc/whonix-netvm-gateway + + # Do again; checking for original 10.152.152.10 incase of update + replace_ips "10.152.152.10" "${gateway}" FILES[@] && echo "${gateway}" > /etc/whonix-netvm-gateway + fi +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/messages.yaml b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/messages.yaml new file mode 100644 index 0000000..075ab09 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/messages.yaml @@ -0,0 +1,9 @@ + +update: + icon: Critical + en: + title: Tor netvm required for updates + message: | +

Tor netvm required for updates!

+

Please ensure your template vm has a Whonix gateway as it's VM.

+

No updates are possible without an active (running) Whonix gateway VM.

diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/qubes-whonixsetup b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/qubes-whonixsetup new file mode 100755 index 0000000..f90d15b --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/qubes-whonixsetup @@ -0,0 +1,41 @@ +#!/bin/bash + +. /usr/lib/whonix/utility_functions + +if ! [ "${WHONIX}" == "template" ]; then + sudo /usr/lib/whonix/bind-dirs.sh +fi + +if [ "${WHONIX}" == "gateway" ]; then + if grep "^DisableNetwork 0$" /etc/tor/torrc ;then + sudo service sdwdate restart + sudo service tor restart + else + sudo service sdwdate restart + sudo service tor stop + sudo /usr/bin/whonixsetup + fi + +elif [ "${WHONIX}" == "workstation" ]; then + sudo service sdwdate restart + if ! [ -f "/var/lib/whonix/do_once/whonixsetup.done" ]; then + sudo /usr/bin/whonixsetup + fi + +elif [ "${WHONIX}" == "template" -a "${PROXY_SECURE}" == "0" ]; then + # Set secure defaults. + sudo iptables -P INPUT DROP + sudo iptables -P FORWARD DROP + sudo iptables -P OUTPUT DROP + + # Flush old rules. + sudo iptables -F + sudo iptables -X + sudo iptables -t nat -F + sudo iptables -t nat -X + sudo iptables -t mangle -F + sudo iptables -t mangle -X + + # Display warning that netvm is not connected to a torvm + /usr/lib/whonix/alert update /usr/lib/whonix/messages.yaml +fi diff --git a/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/utility_functions b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/utility_functions new file mode 100755 index 0000000..8a3b4e7 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/files/usr/lib/whonix/utility_functions @@ -0,0 +1,94 @@ +#!/bin/bash + +# /etc/uwt.d/50_uwt_default relies on this in order to allow connection +# to proxy for template +PROXY_SERVER="http://10.137.255.254:8082/" +PROXY_META='' + +if [ -f "/var/run/qubes-service/updates-proxy-setup" ]; then + WHONIX="template" +elif [ -f "/usr/share/anon-gw-base-files/gateway" ]; then + WHONIX="gateway" +elif [ -f "/usr/share/anon-ws-base-files/workstation" ]; then + WHONIX="workstation" +else + WHONIX="unknown" +fi + +if [ "${WHONIX}" == "template" ]; then + curl.anondist-orig "${PROXY_SERVER}" | grep -q "${PROXY_META}" && { + PROXY_SECURE=1 + } || { + PROXY_SECURE=0 + } +fi + +immutableFilesEnable() { + files="${1}" + suffix="${2}" + + for file in "${files[@]}"; do + if [ -f "${file}" ] && ! [ -L "${file}" ]; then + sudo chattr +i "${file}${suffix}" + fi + done +} + +immutableFilesDisable() { + files="${1}" + suffix="${2}" + + for file in "${files[@]}"; do + if [ -f "${file}" ] && ! [ -L "${file}" ]; then + sudo chattr -i "${file}${suffix}" + fi + done +} + +copyAnondist() { + file="${1}" + suffix="${2-.anondist}" + + # Remove any softlinks first + if [ -L "${file}" ]; then + sudo rm -f "${file}" + fi + + if [ -f "${file}" ] && [ -n "$(diff ${file} ${file}${suffix})" ]; then + sudo chattr -i "${file}" + sudo rm -f "${file}" + sudo cp -p "${file}${suffix}" "${file}" + sudo chattr +i "${file}" + elif ! [ -f "${file}" ]; then + sudo cp -p "${file}${suffix}" "${file}" + sudo chattr +i "${file}" + fi +} + +# Will only enable / disable if service is not already in that state +enable_sysv() { + servicename=${1} + disable=${2-0} + + # Check to see if the service is already enabled and if not, enable it + string="/etc/rc$(runlevel | awk '{ print $2 }').d/S[0-9][0-9]${servicename}" + + if [ $(find $string 2>/dev/null | wc -l) -eq ${disable} ] ; then + case ${disable} in + 0) + echo "${1} is currently disabled; enabling it" + sudo systemctl --quiet enable ${servicename} + ;; + 1) + echo "${1} is currently enabled; disabling it" + sudo service ${servicename} stop + sudo systemctl --quiet disable ${servicename} + ;; + esac + fi +} + +disable_sysv() { + enable_sysv ${1} 1 +} + diff --git a/scripts_debian/wheezy+whonix-workstation/packages_wheezy.list b/scripts_debian/wheezy+whonix-workstation/packages_wheezy.list new file mode 120000 index 0000000..d5dfb50 --- /dev/null +++ b/scripts_debian/wheezy+whonix-workstation/packages_wheezy.list @@ -0,0 +1 @@ +../wheezy+whonix/packages_wheezy.list \ No newline at end of file diff --git a/scripts_debian/wheezy+whonix/00_prepare_pre.sh b/scripts_debian/wheezy+whonix/00_prepare_pre.sh new file mode 100755 index 0000000..9b21b60 --- /dev/null +++ b/scripts_debian/wheezy+whonix/00_prepare_pre.sh @@ -0,0 +1,73 @@ +#!/bin/bash -x +# vim: set ts=4 sw=4 sts=4 et : + +################################################################################ +# Allows a pre-built image to be used (if it exists) for installing +# Whonix. This option is useful only for debugging Whonix installations +# +# To use, first create a regualr wheezy template and manually copy the prepared +# image to debian-7-x64-prepard.img +# +# Example: +# cp ~/qubes-builder/qubes-src/linux-template-builder/prepared_images/debian-7-x64.img ~/qubes-builder/qubes-src/linux-template-builder/prepared_images/debian-7-x64-whonix-gateway-prepard.img +################################################################################ + +# ------------------------------------------------------------------------------ +# Return if SNAPSHOT is not "1" +# ------------------------------------------------------------------------------ +# This script is only used if SNAPSHOT is set +if [ ! "${SNAPSHOT}" == "1" ]; then + exit 0 +fi + +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +INSTALLDIR="$(readlink -m mnt)" + +# ------------------------------------------------------------------------------ +# Use a snapshot of the debootstraped debian image to install Whonix (for DEBUGGING) +# ------------------------------------------------------------------------------ + +manage_snapshot() { + umount_kill "${INSTALLDIR}" || : + + mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1 + # Remove old snapshots if whonix completed + if [ -f "${INSTALLDIR}/tmp/.whonix_post" ]; then + warn "Removing stale snapshots" + umount_kill "${INSTALLDIR}" || : + rm -rf "$debootstrap_snapshot" + rm -rf "$updated_snapshot" + return + fi + + warn "Copying $1 to ${IMG}" + mount -o loop "$1" "${INSTALLDIR}" || exit 1 + rm -f "${INSTALLDIR}/tmp/.prepared_groups" + umount_kill "${INSTALLDIR}" || : + cp -f "$1" "${IMG}" +} + +splitPath "${IMG}" path_parts +debootstrap_snapshot="${path_parts[dir]}${path_parts[base]}-debootstrap${path_parts[dotext]}" +updated_snapshot="${path_parts[dir]}${path_parts[base]}-updated${path_parts[dotext]}" + +if [ -f "$updated_snapshot" ]; then + manage_snapshot "$updated_snapshot" +elif [ -f "$debootstrap_snapshot" ]; then + manage_snapshot "$debootstrap_snapshot" +fi + diff --git a/scripts_debian/wheezy+whonix/01_install_core_post.sh b/scripts_debian/wheezy+whonix/01_install_core_post.sh new file mode 100755 index 0000000..9534618 --- /dev/null +++ b/scripts_debian/wheezy+whonix/01_install_core_post.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +# ------------------------------------------------------------------------------ +# Return if SNAPSHOT is not "1" +# ------------------------------------------------------------------------------ +# This script is only used if SNAPSHOT is set +if [ ! "${SNAPSHOT}" == "1" ]; then + exit 0 +fi + +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +# ------------------------------------------------------------------------------ +# Create a snapshot of the already debootstraped image +# ------------------------------------------------------------------------------ +splitPath "${IMG}" path_parts +PREPARED_IMG="${path_parts[dir]}${path_parts[base]}-debootstrap${path_parts[dotext]}" + +if ! [ -f "${PREPARED_IMG}" ] && ! [ -f "${INSTALLDIR}/tmp/.whonix_post" ]; then + umount_kill "${INSTALLDIR}" || : + warn "Copying ${IMG} to ${PREPARED_IMG}" + cp -f "${IMG}" "${PREPARED_IMG}" + mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1 +fi diff --git a/scripts_debian/wheezy+whonix/02_install_groups_packages_installed.sh b/scripts_debian/wheezy+whonix/02_install_groups_packages_installed.sh new file mode 100755 index 0000000..0b22bf2 --- /dev/null +++ b/scripts_debian/wheezy+whonix/02_install_groups_packages_installed.sh @@ -0,0 +1,310 @@ +#!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : + +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ${SCRIPTSDIR}/vars.sh +. ./umount_kill.sh >/dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +# ------------------------------------------------------------------------------ +# XXX: Create a snapshot - Only for DEBUGGING! +# ------------------------------------------------------------------------------ +# Only execute if SNAPSHOT is set +if [ "${SNAPSHOT}" == "1" ]; then + splitPath "${IMG}" path_parts + PREPARED_IMG="${path_parts[dir]}${path_parts[base]}-updated${path_parts[dotext]}" + + if ! [ -f "${PREPARED_IMG}" ] && ! [ -f "${INSTALLDIR}/tmp/.whonix_prepared" ]; then + umount_kill "${INSTALLDIR}" || : + warn "Copying ${IMG} to ${PREPARED_IMG}" + cp -f "${IMG}" "${PREPARED_IMG}" + mount -o loop "${IMG}" "${INSTALLDIR}" || exit 1 + for fs in /dev /dev/pts /proc /sys /run; do mount -B $fs "${INSTALLDIR}/$fs"; done + fi +fi + +# ------------------------------------------------------------------------------ +# chroot Whonix build script +# ------------------------------------------------------------------------------ +read -r -d '' WHONIX_BUILD_SCRIPT <<'EOF' || true +################################################################################ +# Pre Fixups +sudo mkdir -p /boot/grub2 +sudo touch /boot/grub2/grub.cfg +sudo mkdir -p /boot/grub +sudo touch /boot/grub/grub.cfg +sudo mkdir --parents --mode=g+rw "/tmp/uwt" + +# Whonix seems to re-install sysvinit even though there is a hold +# on the package. Things seem to work anyway. BUT hopfully the +# hold on grub* don't get removed +sudo apt-mark hold sysvinit +sudo apt-mark hold grub-pc grub-pc-bin grub-common grub2-common + +# Whonix expects haveged to be started +sudo /etc/init.d/haveged start + +# Whonix does not always fix permissions after writing as sudo, especially +# when running whonixsetup so /var/lib/whonix/done_once is not readable by +# user, so set defualt umask for sudo +#sudo su -c 'echo "Defaults umask = 0002" >> /etc/sudoers' +#sudo su -c 'echo "Defaults umask_override" >> /etc/sudoers' + +################################################################################ +# Whonix installation +export WHONIX_BUILD_UNATTENDED_PKG_INSTALL="1" + +pushd ~/Whonix +sudo ~/Whonix/whonix_build \ + --build $1 \ + --64bit-linux \ + --current-sources \ + --enable-whonix-apt-repository \ + --whonix-apt-repository-distribution $2 \ + --install-to-root \ + --skip-verifiable \ + --minimal-report \ + --skip-sanity-tests || { exit 1; } +popd +EOF + +# ------------------------------------------------------------------------------ +# Cleanup function +# ------------------------------------------------------------------------------ +function cleanup() { + error "Whonix error; umounting ${INSTALLDIR} to prevent further writes" + umount_kill "${INSTALLDIR}" || : + exit 1 +} +trap cleanup ERR +trap cleanup EXIT + +# ------------------------------------------------------------------------------ +# Mount devices, etc required for Whonix installation +# ------------------------------------------------------------------------------ +if ! [ -f "${INSTALLDIR}/tmp/.whonix_prepared" ]; then + info "Preparing Whonix system" + + # -------------------------------------------------------------------------- + # Initialize Whonix submodules + # -------------------------------------------------------------------------- + pushd "${WHONIX_DIR}" + { + git add Makefile || true + git commit Makefile -m 'Added Makefile' || true + su $(logname) -c "git submodule update --init --recursive"; + } + popd + + # -------------------------------------------------------------------------- + # Fake grub installation since Whonix has depends on grub-pc + # -------------------------------------------------------------------------- + mkdir -p "${INSTALLDIR}/boot/grub" + cp "${INSTALLDIR}/usr/lib/grub/i386-pc/"* "${INSTALLDIR}/boot/grub" + rm -f "${INSTALLDIR}/usr/sbin/update-grub" + chroot "${INSTALLDIR}" ln -s /bin/true /usr/sbin/update-grub + + # -------------------------------------------------------------------------- + # sed search and replace. return 0 if replace happened, otherwise 1 + # -------------------------------------------------------------------------- + search_replace() { + local search="$1" + local replace="$2" + local file="$3" + sed -i.bak '/'"$search"'/,${s//'"$replace"'/;b};$q1' "$file" + } + + # -------------------------------------------------------------------------- + # Whonix system config dependancies + # -------------------------------------------------------------------------- + + # Qubes needs a user named 'user' + debug "Whonix Add user" + chroot "${INSTALLDIR}" id -u 'user' >/dev/null 2>&1 || \ + { + # UID needs match host user to have access to Whonix sources + chroot "${INSTALLDIR}" groupadd -f user + [ -n "$SUDO_UID" ] && USER_OPTS="-u $SUDO_UID" + chroot "${INSTALLDIR}" useradd -g user $USER_OPTS -G dialout,cdrom,floppy,sudo,audio,dip,video,plugdev -m -s /bin/bash user + if [ `chroot "${INSTALLDIR}" id -u user` != 1000 ]; then + chroot "${INSTALLDIR}" useradd -g user -u 1000 -M -s /bin/bash user-placeholder + fi + } + + # Install Whonix build scripts + echo "${WHONIX_BUILD_SCRIPT}" > "${INSTALLDIR}/home/user/whonix_build.sh" + chmod 0755 "${INSTALLDIR}/home/user/whonix_build.sh" + + # ------------------------------------------------------------------------------ + # Copy over any extra files + # ------------------------------------------------------------------------------ + copyTree "files" + + touch "${INSTALLDIR}/tmp/.whonix_prepared" +fi + +# ------------------------------------------------------------------------------ +# Install Whonix +# ------------------------------------------------------------------------------ +if [ -f "${INSTALLDIR}/tmp/.whonix_prepared" ] && ! [ -f "${INSTALLDIR}/tmp/.whonix_installed" ]; then + info "Installing Whonix system" + + # -------------------------------------------------------------------------- + # Install Whonix code base + # -------------------------------------------------------------------------- + if ! [ -d "${INSTALLDIR}/home/user/Whonix" ]; then + debug "Installing Whonix build environment..." + chroot "${INSTALLDIR}" su user -c 'mkdir /home/user/Whonix' + fi + + if [ -d "${INSTALLDIR}/home/user/Whonix" ]; then + debug "Building Whonix..." + mount --bind "../Whonix" "${INSTALLDIR}/home/user/Whonix" + fi + + if [ "${TEMPLATE_FLAVOR}" == "whonix-gateway" ]; then + BUILD_TYPE="--torgateway" + elif [ "${TEMPLATE_FLAVOR}" == "whonix-workstation" ]; then + BUILD_TYPE="--torworkstation" + else + error "Incorrent Whonix type \"${TEMPLATE_FLAVOR}\" selected. Not building Whonix modules" + error "You need to set TEMPLATE_FLAVOR environment variable to either" + error "whonix-gateway OR whonix-workstation" + exit 1 + fi + + chroot "${INSTALLDIR}" su user -c "cd ~; ./whonix_build.sh ${BUILD_TYPE} ${DIST}" || { exit 1; } + + touch "${INSTALLDIR}/tmp/.whonix_installed" +fi + +# ------------------------------------------------------------------------------ +# Whonix Post Installation Configurations +# ------------------------------------------------------------------------------ +if [ -f "${INSTALLDIR}/tmp/.whonix_installed" ] && ! [ -f "${INSTALLDIR}/tmp/.whonix_post" ]; then + info "Post Configuring Whonix System" + + # Don't need Whonix interfaces; restore original + pushd "${INSTALLDIR}/etc/network" + { + rm -f interfaces; + ln -s interfaces.backup interfaces; + } + popd + + # Qubes installation will need a normal resolv.conf; will be restored back + # in 04_qubes_install_post.sh within the wheezy+whonix-* directories + pushd "${INSTALLDIR}/etc" + { + rm -f resolv.conf; + cp -p resolv.conf.backup resolv.conf; + } + popd + + # Remove link to hosts file and copy original back + # Will get set back to Whonix hosts file when the + # /usr/lib/whonix/setup-ip is run on startup + pushd "${INSTALLDIR}/etc" + { + rm -f hosts; + cp -p hosts.anondist-orig hosts; + } + popd + + + # Enable Tor + #if [ "${TEMPLATE_FLAVOR}" == "whonix-gateway" ]; then + # sed -i 's/#DisableNetwork 0/DisableNetwork 0/g' "${INSTALLDIR}/etc/tor/torrc" + #fi + + # Restore default user UID to have the same in all builds regardless of build host + if [ -n "`chroot "${INSTALLDIR}" id -u user-placeholder`" ]; then + chroot "${INSTALLDIR}" userdel user-placeholder + chroot "${INSTALLDIR}" usermod -u 1000 user + fi + + # Enable aliases in .bashrc + sed -i "s/^# export/export/g" "${INSTALLDIR}/root/.bashrc" + sed -i "s/^# eval/eval/g" "${INSTALLDIR}/root/.bashrc" + sed -i "s/^# alias/alias/g" "${INSTALLDIR}/root/.bashrc" + sed -i "s/^#force_color_prompt/force_color_prompt/g" "${INSTALLDIR}/home/user/.bashrc" + sed -i "s/#alias/alias/g" "${INSTALLDIR}/home/user/.bashrc" + sed -i "s/alias l='ls -CF'/alias l='ls -l'/g" "${INSTALLDIR}/home/user/.bashrc" + + # Fake that initializer was already run + mkdir -p "${INSTALLDIR}/root/.whonix" + touch "${INSTALLDIR}/root/.whonix/first_run_initializer.done" + + # Prevent whonixcheck error + echo 'WHONIXCHECK_NO_EXIT_ON_UNSUPPORTED_VIRTUALIZER="1"' >> "${INSTALLDIR}/etc/whonix.d/30_whonixcheck_default" + + # Use gdialog as an alternative for dialog + mv -f "${INSTALLDIR}/usr/bin/dialog" "${INSTALLDIR}/usr/bin/dialog.dist" + chroot "${INSTALLDIR}" update-alternatives --force --install /usr/bin/dialog dialog /usr/bin/gdialog 999 + + # Disable unwanted applications + chroot "${INSTALLDIR}" update-rc.d network-manager disable || : + chroot "${INSTALLDIR}" update-rc.d spice-vdagent disable || : + chroot "${INSTALLDIR}" update-rc.d swap-file-creator disable || : + chroot "${INSTALLDIR}" update-rc.d whonix-initializer disable || : + + chroot "${INSTALLDIR}" service apt-cacher-ng stop || : + chroot "${INSTALLDIR}" update-rc.d apt-cacher-ng disable || : + + # Tor will be re-enabled upon initial configuration + chroot "${INSTALLDIR}" update-rc.d tor disable || : + chroot "${INSTALLDIR}" update-rc.d sdwdate disable || : + + # Remove apt-cacher-ng + DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + chroot ${INSTALLDIR} apt-get.anondist-orig -y --force-yes remove --purge apt-cacher-ng + + # Remove original sources.list + rm -f "${INSTALLDIR}/etc/apt/sources.list" + + DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \ + chroot ${INSTALLDIR} apt-get.anondist-orig update + + touch "${INSTALLDIR}/tmp/.whonix_post" +fi + +# ------------------------------------------------------------------------------ +# Execute any template flavor or sub flavor scripts +# ------------------------------------------------------------------------------ +buildStep "99_custom_configuration.sh" + +# ------------------------------------------------------------------------------ +# Bring back original apt-get for installation of Qubues +# ------------------------------------------------------------------------------ +pushd "${INSTALLDIR}/usr/bin" +{ + rm -f apt-get; + cp -p apt-get.anondist-orig apt-get; +} +popd + +# ------------------------------------------------------------------------------ +# Make sure the temporary policy-rc.d to prevent apt from starting services +# on package installation is still active; Whonix may have reset it +# ------------------------------------------------------------------------------ +cat > "${INSTALLDIR}/usr/sbin/policy-rc.d" </dev/null + +# ------------------------------------------------------------------------------ +# Configurations +# ------------------------------------------------------------------------------ +if [ "${VERBOSE}" -ge 2 -o "${DEBUG}" == "1" ]; then + set -x +else + set -e +fi + +rm -f "${INSTALLDIR}/etc/sudoers.d/whonix-build" diff --git a/scripts_debian/wheezy+whonix/packages_wheezy.list b/scripts_debian/wheezy+whonix/packages_wheezy.list new file mode 100644 index 0000000..91e329e --- /dev/null +++ b/scripts_debian/wheezy+whonix/packages_wheezy.list @@ -0,0 +1,28 @@ +git +curl +sudo +locales +console-data +console-common +initramfs-tools +os-prober +bzip2 +file +less +lsof +most +pciutils +strace +sysfsutils +usbutils +lsb-release +acpi-support-base +haveged + +build-essential:native +gcc +fakeroot +lintian + +rsync +grub-pc diff --git a/tests/assert/.travis.yml b/tests/assert/.travis.yml new file mode 100644 index 0000000..4cb26a2 --- /dev/null +++ b/tests/assert/.travis.yml @@ -0,0 +1,4 @@ +language: bash +script: bash tests.sh +before_install: + - sudo apt-get install bc diff --git a/tests/assert/COPYING b/tests/assert/COPYING new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/tests/assert/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/tests/assert/COPYING.LESSER b/tests/assert/COPYING.LESSER new file mode 100644 index 0000000..cca7fc2 --- /dev/null +++ b/tests/assert/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/tests/assert/README.rst b/tests/assert/README.rst new file mode 100644 index 0000000..f2630b4 --- /dev/null +++ b/tests/assert/README.rst @@ -0,0 +1,176 @@ +########### + assert.sh +########### + +**assert.sh** is test-driven development in the Bourne again shell. + +:Version: 1.0.2 +:Author: Robert Lehmann +:License: LGPLv3 +:Requirements: `bc -- an arbitrary precision calculator language + `_ + (installed on all POSIX-compliant systems) + +.. image:: https://travis-ci.org/lehmannro/assert.sh.svg?branch=master + :target: https://travis-ci.org/lehmannro/assert.sh + +Example +======= + +:: + + . assert.sh + + # `echo test` is expected to write "test" on stdout + assert "echo test" "test" + # `seq 3` is expected to print "1", "2" and "3" on different lines + assert "seq 3" "1\n2\n3" + # exit code of `true` is expected to be 0 + assert_raises "true" + # exit code of `false` is expected to be 1 + assert_raises "false" 1 + # end of test suite + assert_end examples + +If you had written the above snippet into ``tests.sh`` you could invoke it +without any extra hassle:: + + $ ./tests.sh + all 4 examples tests passed in 0.014s. + +Watch out to have ``tests.sh`` executable (``chmod +x tests.sh``), otherwise +you need to invoke it with ``bash tests.sh`` + +Now, we will add a failing test case to our suite:: + + # expect `exit 127` to terminate with code 128 + assert_raises "exit 127" 128 + +Remember to insert test cases before ``assert_end`` (or write another +``assert_end`` to the end of your file). Otherwise test statistics will be +omitted. + +When run, the output is:: + + test #5 "exit 127" failed: + program terminated with code 127 instead of 128 + 1 of 5 examples tests failed in 0.019s. + + +Features +======== + ++ lightweight interface: ``assert`` and ``assert_raises`` *only* ++ minimal setup -- source ``assert.sh`` and you're done ++ test grouping in individual suites ++ time benchmarks with real-time display of test progress ++ run all tests, stop on first failure, or collect numbers only + +Use case +======== + +You wrote an application. Following sane development practices, you want to +protect yourself against introducing errors with a test suite. Even though most +languages have excellent testing tools, modifying process state (input ``stdin``, +command line arguments ``argv``, environment variables) is awkard in most +languages. The shell was made to do just that, so why don't run the tests in +your shell? + +Reference +========= + ++ ``assert [stdout] [stdin]`` + + Check for an expected output when running your command. `stdout` supports all + control sequences printf(1) interprets, eg. ``\n`` for a newline. The default + `stdout` is assumed to be empty. + ++ ``assert_raises [exitcode] [stdin]`` + + Verify `command` terminated with the expected status code. The default + `exitcode` is assumed to be 0. + ++ ``assert_end [suite]`` + + Finalize a test suite and print statistics. + +Command line options +-------------------- + +See ``assert.sh --help`` for command line options on test runners. + + -v, --verbose Generate real-time output for every individual test run. + -x, --stop Stop running tests after the first failure. + (Default: run all tests.) + -i, --invariant Do not measure runtime for suites. Useful mainly to parse + test output. + -d, --discover Collect test suites and number of tests only; don't run any + tests. + -c, --continue Do not modify exit code depending on overall suite status. + -h Show brief usage information and exit. + --help Show usage manual and exit. + +Environment variables +--------------------- + +================= ==================== +variable corresponding option +================= ==================== +``$DEBUG`` ``--verbose`` +``$STOP`` ``--stop`` +``$INVARIANT`` ``--invariant`` +``$DISCOVERONLY`` ``--discover-only`` +``$CONTINUE`` ``--continue`` +================= ==================== + +Changelog +========= + +master + * Added support for ``set -e`` environments (closes `#6 + `_, thanks David Schoen.) + * Modified exit code automatically in case *any* test failed in the suite. + * Added ``--continue`` flag to avoid tinkering with the exit code. + +1.0.2 + * Fixed Mac OS compatibility (closes `#3 + `_.) + +1.0.1 + * Added support for ``set -u`` environments (closes `#1 + `_.) + * Fixed several leaks of stderr. + * Fixed propagation of options to nested test suites. + +Related projects +================ + +`ShUnit`__ + ShUnit is a testing framework of the xUnit family for Bourne derived shells. + It is quite feature-rich but requires a whole lot of boilerplate to write a + basic test suite. *assert.sh* aims to be lightweight and easy to setup. + +__ http://shunit.sourceforge.net/ + +`shUnit2`__ + shUnit2 is a modern xUnit-style testing framework. It comes with a bunch of + magic to remove unneccessary verbosity. It requires extra care when crafting + test cases with many subprocess invocations as you have to fall back to shell + features to fetch results. *assert.sh* wraps this functionality out of the + box. + +__ http://code.google.com/p/shunit2/ + +`tap-functions`__ + A Test Anything Protocol (TAP) producer with an inherently natural-language- + style API. Unfortunately it's only of draft quality and decouples the test + runner from analysis, which does not allow for *assert.sh* features such as + ``--collect-only`` and ``--stop``. + +__ http://testanything.org/wiki/index.php/Tap-functions + +`stub.sh`__ + Helpers to fake binaries and bash builtins. It supports mocking features such + as expecting a certain number of invocations and plays well with *assert.sh*. + +__ https://github.com/jimeh/stub.sh diff --git a/tests/assert/assert.sh b/tests/assert/assert.sh new file mode 100644 index 0000000..b0c679c --- /dev/null +++ b/tests/assert/assert.sh @@ -0,0 +1,148 @@ +#!/bin/bash +# assert.sh 1.0 - bash unit testing framework +# Copyright (C) 2009, 2010, 2011, 2012 Robert Lehmann +# +# http://github.com/lehmannro/assert.sh +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +export DISCOVERONLY=${DISCOVERONLY:-} +export DEBUG=${DEBUG:-} +export STOP=${STOP:-} +export INVARIANT=${INVARIANT:-} +export CONTINUE=${CONTINUE:-} + +args="$(getopt -n "$0" -l \ + verbose,help,stop,discover,invariant,continue vhxdic $*)" \ +|| exit -1 +for arg in $args; do + case "$arg" in + -h) + echo "$0 [-vxidc]" \ + "[--verbose] [--stop] [--invariant] [--discover] [--continue]" + echo "`sed 's/./ /g' <<< "$0"` [-h] [--help]" + exit 0;; + --help) + cat < [stdin] + (( tests_ran++ )) || : + [[ -n "$DISCOVERONLY" ]] && return || true + # printf required for formatting + printf -v expected "x${2:-}" # x required to overwrite older results + result="$(eval 2>/dev/null $1 <<< ${3:-})" || true + # Note: $expected is already decorated + if [[ "x$result" == "$expected" ]]; then + [[ -n "$DEBUG" ]] && echo -n . || true + return + fi + result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")" + [[ -z "$result" ]] && result="nothing" || result="\"$result\"" + [[ -z "$2" ]] && expected="nothing" || expected="\"$2\"" + _assert_fail "expected $expected${_indent}got $result" "$1" "$3" +} + +assert_raises() { + # assert_raises [stdin] + (( tests_ran++ )) || : + [[ -n "$DISCOVERONLY" ]] && return || true + status=0 + (eval $1 <<< ${3:-}) > /dev/null 2>&1 || status=$? + expected=${2:-0} + if [[ "$status" -eq "$expected" ]]; then + [[ -n "$DEBUG" ]] && echo -n . || true + return + fi + _assert_fail "program terminated with code $status instead of $expected" "$1" "$3" +} + +_assert_fail() { + # _assert_fail + [[ -n "$DEBUG" ]] && echo -n X + report="test #$tests_ran \"$2${3:+ <<< $3}\" failed:${_indent}$1" + if [[ -n "$STOP" ]]; then + [[ -n "$DEBUG" ]] && echo + echo "$report" + exit 1 + fi + tests_errors[$tests_failed]="$report" + (( tests_failed++ )) || : +} + +_assert_reset +: ${tests_suite_status:=0} # remember if any of the tests failed so far +_assert_cleanup() { + local status=$? + # modify exit code if it's not already non-zero + [[ $status -eq 0 && -z $CONTINUE ]] && exit $tests_suite_status +} +trap _assert_cleanup EXIT diff --git a/tests/assert/tests.sh b/tests/assert/tests.sh new file mode 100755 index 0000000..6a31b6d --- /dev/null +++ b/tests/assert/tests.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +set -e + +. assert.sh + +assert "echo" # no output expected +assert "echo foo" "foo" # output expected +assert "cat" "bar" "bar" # output expected if input's given +assert_raises "true" 0 "" # status code expected +assert_raises "exit 127" 127 "" # status code expected +assert "head -1 < $0" "#!/bin/bash" # redirections +assert "seq 2" "1\n2" # multi-line output expected +assert_raises 'read a; exit $a' 42 "42" # variables still work +assert "echo 1; +echo 2 # ^" "1\n2" # semicolon required! +assert_end demo + +_clean() { + _assert_reset # reset state + DEBUG= STOP= INVARIANT=1 DISCOVERONLY= CONTINUE= # reset flags + eval $* # read new flags +} + +# clean output +assert "_clean; assert true; assert_end" \ +"all 1 tests passed." +# error reports on failure +assert "_clean; assert 'seq 1'; assert_end" \ +'test #1 "seq 1" failed:\n\texpected nothing\n\tgot "1"\n1 of 1 tests failed.' +assert "_clean; assert true '1'; assert_end" \ +'test #1 "true" failed:\n\texpected "1"\n\tgot nothing\n1 of 1 tests failed.' +assert "_clean; assert 'true' 'foo' 'bar'; assert_end" \ +'test #1 "true <<< bar" failed:\n\texpected "foo"\n\tgot nothing\n1 of 1 tests failed.' +# debug output (-v) +assert "_clean DEBUG=1; assert true; assert_end" \ +".\nall 1 tests passed." +assert "_clean DEBUG=1; assert_raises false; assert_end" \ +'X\ntest #1 "false" failed:\n\tprogram terminated with code 1 instead of 0 +1 of 1 tests failed.' +# collect tests only (-d) +assert "_clean DISCOVERONLY=1; assert true; assert false; assert_end" \ +"collected 2 tests." +# stop immediately on failure (-x) +assert "_clean STOP=1; assert_raises false; assert_end" \ +'test #1 "false" failed:\n\tprogram terminated with code 1 instead of 0' +# runtime statistics (omission of -i) +assert_raises "_clean INVARIANT=; +assert_end | egrep 'all 0 tests passed in ([0-9]|[0-9].[0-9]{3})s'" +assert_end output + +# assert_end exit code is the number of failures +assert_raises "_clean; assert_raises false; assert_raises false; assert_end" 2 +# stderr should NOT leak if ignored +assert "_clean; assert less" "" +# stderr should be redirectable though +assert '_clean; assert "less 2>&1" "Missing filename (\"less --help\" for help)"' +# bash failures behave just like stderr +assert "_clean; assert ___invalid" "" +# test suites can be nested and settings are inherited +# (ie. we don't need to invoke the inner suite with the very same options, +# namely --invariant) +assert "_clean; bash -c ' +. assert.sh; +assert_raises true; assert_end outer; +bash -c \". assert.sh; assert_raises true; assert_end inner\" +' '' --invariant" "all 1 outer tests passed. +all 1 inner tests passed." # is $0 +# set the correct exit status +assert_raises "_clean; bash -c \" +. assert.sh; assert true ''; assert_end one; +assert 'echo bar' 'bar'; assert_end two\"" 0 +assert_raises "_clean; bash -c \" +. assert.sh; assert true 'foo'; assert_end one; +assert 'echo bar' 'bar'; assert_end two\"" 1 +# ..but do not override it +assert_raises "_clean; bash -c \" +. assert.sh; assert true 'foo'; assert_end one; +assert 'echo bar' 'bar'; assert_end two; exit 3\"" 3 +# environment variables do not leak +assert "_clean; x=0; assert 'x=1'; assert_raises 'x=2'; echo \$x" 0 +assert "_clean; x=0; assert 'export x=1'; assert_raises 'export x=2'; +echo \$x" 0 +assert_end interaction + +# commit: fixed output to report all errors, not just the first +assert "_clean; +assert_raises false; assert_raises false; +assert_end" 'test #1 "false" failed: +\tprogram terminated with code 1 instead of 0 +test #2 "false" failed: +\tprogram terminated with code 1 instead of 0 +2 of 2 tests failed.' +# commit: added default value for assert_raises +assert_raises "_clean; assert_raises true; assert_end" 0 +# commit: fixed verbose failure reports in assert_raises +assert "_clean DEBUG=1; assert_raises false; assert_end" 'X +test #1 "false" failed: +\tprogram terminated with code 1 instead of 0 +1 of 1 tests failed.' +# commit: redirected assert_raises output +assert "_clean; assert_raises 'echo 1'; assert_end" "all 1 tests passed." +# commit: fixed --discover to reset properly +assert "_clean DISCOVERONLY=1; +assert 1; assert 1; assert_end; +assert 1; assert_end;" "collected 2 tests.\ncollected 1 tests." +# commit: stopped errors from leaking into other test suites +assert "_clean; +assert_raises false; assert_raises false; assert_end; +assert_raises false; assert_end" 'test #1 "false" failed: +\tprogram terminated with code 1 instead of 0 +test #2 "false" failed: +\tprogram terminated with code 1 instead of 0 +2 of 2 tests failed. +test #1 "false" failed: +\tprogram terminated with code 1 instead of 0 +1 of 1 tests failed.' +# issue 1: assert.sh: line 87: DISCOVERONLY: unbound variable +assert "_clean; set -u; assert_raises true; assert true; assert_end" \ +"all 2 tests passed." +assert_end regression diff --git a/tests/shellcheck/INSTALL b/tests/shellcheck/INSTALL new file mode 100755 index 0000000..a643fee --- /dev/null +++ b/tests/shellcheck/INSTALL @@ -0,0 +1,42 @@ +#!/bin/bash + +# https://github.com/koalaman/shellcheck + +sudo yum install cabal-install + +# Let cabal update itself, incase your distro is outdated +sudo cabal update +cabel install cabal-install + +# Clone shellcheck and build +git clone https://github.com/koalaman/shellcheck.git +cd shellcheck + +# With cabel installed, cd to source direstory and: +sudo cabal install + +# Add cabal directory to bash path +source='export PATH=$HOME/.cabal/bin:$PATH' +file=~/.bash_profile +if ! grep -r -q "$source" "${file}"; then + touch $file + echo "$source" >> $file +fi + +# You now need to manually source .bash_profile +echo "You now need to manually source .bash_profile" +echo "source ~/.bash_profile" + +# Then verify PATH is set correctly +echo +echo +echo "Then verify PATH is set correctly" +echo "which shellcheck" +echo "~/.cabal/bin/shellcheck" + + +# To run the unit test suite: +# +# cabal configure --enable-tests +# cabal build +# cabal test diff --git a/tests/template-flavors/NOTES b/tests/template-flavors/NOTES new file mode 100644 index 0000000..a599ccb --- /dev/null +++ b/tests/template-flavors/NOTES @@ -0,0 +1,42 @@ +TODO: +----- + +- Move template flavors into own directories so scripts_dir wont be polluted + ../scripts_flavors/wheezy-whonix-gateway/ + + ../${TEMPLATE_FLAVOR_DIR}/${TEMPLATE_FLAVOR_PREFIX}[-]whonix-gateway/ + +# ------------------------------------------------------------------------------ +# - Make flavor directory have $DIST in name - to prevent it from bwing built +# incorrectly +# - Configuration option to choose alternate location of flavor directory +# - Configuration option to use custom $DIST- prefix (for generic flavors) +# - Take into consideration that multiple templates will build at once so we +# need to set a custom prefix like this: +# ------------------------------------------------------------------------------ + +# - Would use the prefix of 'debian' which would allow same script to be used for +# all 'debian' based builds, or it could have been set as +# 'wheezy+whonix-gateway;' to use a script destined for any distro +TEMPLATE_FLAVOR_PREFIX = wheezy+whonix-gateway;debian \ + wheezy+whonix-workstation;debian + +# Alternate location for template flavor scripts +TEMPLATE_FLAVOR_DIR = wheezy+whonix-gateway;/home/user/whonix/gateway \ + wheezy+whonix-workstation;/home/usr/whonix/workstation + +- allow access to multiple flavor options .. say gnome for whonix-workstation + wheezy+whonix-workstation+gnome+more + +# ------------------------------------------------------------------------------ +# - TEMPLATE_OPTIONS will be iterated and each entry treated as if it was its +# own flavor, but to override you must include base flavor name: +# ------------------------------------------------------------------------------ + +# Would use same FLAVOR for all distros for whonix-workstation+gnome +TEMPLATE_FLAVOR_PREFIX = wheezy+whonix-workstation+gnome; + +# - Template Flavors are in /home/user/whoix/gnome for wheezy+whonix-workstation+gnome +# - DISTS_VM is still lists all OPTIONAL flavors though +TEMPLATE_FLAVOR_DIR = wheezy+whonix-workstation+gnome;/home/usr/whonix/gnome + diff --git a/mnt/.gitignore b/tests/template-flavors/another_location/whonix gw/packages.list similarity index 100% rename from mnt/.gitignore rename to tests/template-flavors/another_location/whonix gw/packages.list diff --git a/tests/template-flavors/another_location/whonix gw/test_pre.sh b/tests/template-flavors/another_location/whonix gw/test_pre.sh new file mode 100755 index 0000000..9a4e120 --- /dev/null +++ b/tests/template-flavors/another_location/whonix gw/test_pre.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +: diff --git a/tests/template-flavors/another_location/whonix-gw/test_pre.sh b/tests/template-flavors/another_location/whonix-gw/test_pre.sh new file mode 100755 index 0000000..9a4e120 --- /dev/null +++ b/tests/template-flavors/another_location/whonix-gw/test_pre.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +: diff --git a/tests/template-flavors/another_location/whonix_gnome/packages.list b/tests/template-flavors/another_location/whonix_gnome/packages.list new file mode 100644 index 0000000..e69de29 diff --git a/tests/template-flavors/another_location/whonix_gnome/test_pre.sh b/tests/template-flavors/another_location/whonix_gnome/test_pre.sh new file mode 100755 index 0000000..9a4e120 --- /dev/null +++ b/tests/template-flavors/another_location/whonix_gnome/test_pre.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +: diff --git a/tests/template-flavors/debian+whonix-gateway+gnome/test_pre.sh b/tests/template-flavors/debian+whonix-gateway+gnome/test_pre.sh new file mode 100755 index 0000000..9a4e120 --- /dev/null +++ b/tests/template-flavors/debian+whonix-gateway+gnome/test_pre.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +: diff --git a/tests/template-flavors/debian+whonix-gateway/test_pre.sh b/tests/template-flavors/debian+whonix-gateway/test_pre.sh new file mode 100755 index 0000000..9a4e120 --- /dev/null +++ b/tests/template-flavors/debian+whonix-gateway/test_pre.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +: diff --git a/tests/template-flavors/packages.list b/tests/template-flavors/packages.list new file mode 100644 index 0000000..e69de29 diff --git a/tests/template-flavors/packages_wheezy.list b/tests/template-flavors/packages_wheezy.list new file mode 100644 index 0000000..e69de29 diff --git a/tests/template-flavors/proxy/test_pre.sh b/tests/template-flavors/proxy/test_pre.sh new file mode 100755 index 0000000..9a4e120 --- /dev/null +++ b/tests/template-flavors/proxy/test_pre.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# vim: set ts=4 sw=4 sts=4 et : + +: diff --git a/tests/template-flavors/test.sh b/tests/template-flavors/test.sh new file mode 100755 index 0000000..b341ce1 --- /dev/null +++ b/tests/template-flavors/test.sh @@ -0,0 +1,464 @@ +#!/bin/bash +# vim: set ts=4 sw=4 sts=4 et : + +VERBOSE=1 + +pushd ../.. +ROOT_DIR=$(readlink -m .) + +# ------------------------------------------------------------------------------ +# Source external scripts +# ------------------------------------------------------------------------------ +. ./functions.sh +. ./tests/assert/assert.sh + +header() { + echo + echo + info "------------------------------------------------------------------------------" + + IFS= read -r title; info "${title}" + while IFS= read -r line; do + echo "${bold}${magenta}${line}${reset}" + done; + + echo + values SCRIPTSDIR + values DIST + values DISTS_VM + values TEMPLATE_FLAVOR + values TEMPLATE_FLAVOR_PREFIX + values TEMPLATE_FLAVOR_DIR + values TEMPLATE_OPTIONS + echo +} + +declare -A VALUES=( + [SCRIPTSDIR]="" + [DIST]="" + [DISTS_VM]="" + [TEMPLATE_FLAVOR]="" + [TEMPLATE_FLAVOR_DIR]="" + [TEMPLATE_FLAVOR_PREFIX]="" + [TEMPLATE_OPTIONS]="" +) + +values() { + label=${1} + value="${1}[@]" + value="${!value}" + + if [ "${VALUES[$label]}" == "${value}" ]; then + printf " ${bold}${magenta}%-22s = ${value}${reset}\n" "${label}" || : + else + printf " ${bold}${black}%-22s = ${value}${reset}\n" "${label}" || : + fi + VALUES[$label]="${value}" +} + +info() { + output "${bold}${blue}${1}${reset}" || : +} + +debug() { + output "${magenta}${1}${reset}" || : +} + +assertTest(){ + TEST=True + printf "${bold}${red}" + assert "$1" "$2" + printf "${reset}" + unset TEST +} + +assertEnd() { + printf "${bold}${red}" + [[ -n "$1" ]] && assert_end "$1" || assert_end + printf "${reset}" +} + +# ------------------------------------------------------------------------------ +# 1. With TEMPLATE_FLAVOR +# ------------------------------------------------------------------------------ +SCRIPTSDIR="tests/template-flavors" +DIST="wheezy" +DISTS_VM="" +TEMPLATE_FLAVOR="whonix-gateway" +TEMPLATE_FLAVOR_PREFIX="" +TEMPLATE_FLAVOR_DIR="" +TEMPLATE_OPTIONS="" + +header < Attempting to kill any processes still running in '${MOUNTDIR}' before un-mounting" + for dir in $(sudo grep "${MOUNTDIR}" /proc/mounts | cut -f2 -d" " | sort -r | grep "^${MOUNTDIR}") + do + sudo lsof "$dir" 2> /dev/null | \ + grep "$dir" | \ + tail -n +2 | \ + awk '{print $2}' | \ + xargs --no-run-if-empty sudo kill -9 + + if ! [ "$2" ] && $(mountpoint -q "$dir"); then + info "un-mounting $dir" + sudo umount -n "$dir" 2> /dev/null || \ + sudo umount -n -l "$dir" 2> /dev/null || \ + error "umount $dir unsuccessful!" + elif ! [ "$2" ]; then + # Look for (deleted) mountpoints + info "not a regular mount point: $dir" + base=$(basename "$dir") + dir=$(dirname "$dir") + base=$(echo "$base" | sed 's/[\].*$//') + dir="$dir/$base" + sudo umount -v -f -n "$dir" 2> /dev/null || \ + sudo umount -v -f -n -l "$dir" 2> /dev/null || \ + error "umount $dir unsuccessful!" + fi + done +} + +kill_processes_in_mount() { + umount_kill $1 "false" || : +} + +if [ $(basename "$0") == "umount_kill.sh" -a "$1" ]; then + umount_kill "$1" +fi