From a0df6b9b8fbf7d4db53bb21f379cb1941d823a5b Mon Sep 17 00:00:00 2001 From: Tomas Touceda Date: Thu, 25 Apr 2013 12:12:02 -0300 Subject: Reorder files, normalize repo and add sample config --- pkg/utils/bootstrap | 59 ++++++ pkg/utils/gpg-key-generator | 209 +++++++++++++++++++++ .../gpg-keys/generated-2013-02-15_19-15-001.pub | Bin 0 -> 2779 bytes .../gpg-keys/generated-2013-02-15_19-15-001.sec | Bin 0 -> 5453 bytes .../gpg-keys/generated-2013-02-15_19-15-002.pub | Bin 0 -> 2779 bytes .../gpg-keys/generated-2013-02-15_19-15-002.sec | Bin 0 -> 5453 bytes .../gpg-keys/generated-2013-02-15_19-15-003.pub | Bin 0 -> 2779 bytes .../gpg-keys/generated-2013-02-15_19-15-003.sec | Bin 0 -> 5453 bytes pkg/utils/gpg-keys/gpg-batch-key-script | 45 +++++ pkg/utils/test_bootstrap | 39 ++++ 10 files changed, 352 insertions(+) create mode 100755 pkg/utils/bootstrap create mode 100755 pkg/utils/gpg-key-generator create mode 100644 pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.pub create mode 100644 pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.sec create mode 100644 pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.pub create mode 100644 pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.sec create mode 100644 pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.pub create mode 100644 pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.sec create mode 100644 pkg/utils/gpg-keys/gpg-batch-key-script create mode 100755 pkg/utils/test_bootstrap (limited to 'pkg') diff --git a/pkg/utils/bootstrap b/pkg/utils/bootstrap new file mode 100755 index 0000000..b76a572 --- /dev/null +++ b/pkg/utils/bootstrap @@ -0,0 +1,59 @@ +#!/bin/bash +############################################################################## +# +# bootstrap +# ----------------------- +# Setup a virtualenv, without ever using sudo. +# +# @author Isis Agora Lovecruft, 0x2cdb8b35 +# @date 18 February 2013 +# @version 0.0.1 +############################################################################## + +set -ex -- + +PYTHON=$(which python) +GIT=$(which git) + +VENV_VERSION=1.8.4 +VENV_URL=https://pypi.python.org/packages/source/v/virtualenv +VENV_TARBALL=virtualenv-${VENV_VERSION}.tar.gz + +VENV_WRAPPER_VERSION=3.6 +VENV_WRAPPER_URL=https://pypi.python.org/packages/source/v/virtualenvwrapper +VENV_WRAPPER_TARBALL=virtualenvwrapper-${VENV_WRAPPER_VERSION}.tar.gz + +BOOTSTRAP_ENV=.bootstrap +BOOTSTRAP_OPTS='--no-site-packages --setuptools --unzip-setuptools --never-download' + +PACKAGE_NAME=leap_mx +PACKAGE_URL=https://github.com/isislovecruft/leap_mx.git +PACKAGE_WORKON=${PWD}/${PACKAGE_NAME} +PACKAGE_REQUIREMENTS=${PACKAGE_WORKON}/pkg/mx-requirements.pip +PACKAGE_OPTS=${BOOTSTRAP_OPTS}'' ## xxx add parameter for extra options + +echo 'Downloading virtualenv source from' +echo "${VENV_URL}..." +\wget -O ${VENV_TARBALL} ${VENV_URL}/${VENV_TARBALL} +tar xvzf ${VENV_TARBALL} + +echo 'Downloading virtualenv-wrapper source from:' +echo "${VENV_WRAPPER_URL}" +\wget -O $VENV_WRAPPER_TARBALL ${VENV_WRAPPER_URL}/${VENV_WRAPPER_TARBALL} +tar xvzf virtualenvwrapper-${VENV_WRAPPER_VERSION}.tar.gz + + +echo 'Creating initial virtualenv bootstrap environment, called "bootstrap"' +echo 'in which we will install virtualenv, to avoid using sudo.' +$PYTHON virtualenv-${VENV_VERSION}/virtualenv.py $BOOTSTRAP_OPTS $BOOTSTRAP_ENV +rm -rf virtualenv-${VENV_VERSION} +${BOOTSTRAP_ENV}/bin/pip install ${VENV_TARBALL} +echo 'Installing virtualenvwrapper in "bootstrap" virtualenv...' +${BOOTSTRAP_ENV}/bin/pip install ${VENV_WRAPPER_TARBALL} + +echo 'Using "bootstrap" virtualenv to create project virtualenv...' +source ${BOOTSTRAP_ENV}/local/bin/virtualenvwrapper.sh +echo "Cloning from ${PACKAGE_URL}..." +${GIT} clone ${PACKAGE_URL} ${PACKAGE_NAME} +mkvirtualenv -a $PROJECT_WORKON -r ${PACKAGE_REQUIREMENTS} \ + ${PACKAGE_OPTS} ${PACKAGE_NAME} diff --git a/pkg/utils/gpg-key-generator b/pkg/utils/gpg-key-generator new file mode 100755 index 0000000..54d29fb --- /dev/null +++ b/pkg/utils/gpg-key-generator @@ -0,0 +1,209 @@ +#!/bin/bash +############################################################################## +# +# gpg-key-generator +# ------------------- +# Create batch processed keys for dummy users in the CouchDB, for testing. +# see +# www.gnupg.org/documentation/manuals/gnupg-devel/Unattended-GPG-key-generation.html +# for syntax specification. +# +# @author Isis Agora Lovecruft, 0x2cdb8b35 +# @date 11 February 2013 +# @version 0.1.0 +############################################################################## + + +here="${PWD}" +test_dir="${here}/gpg-keys" +batch_file="${test_dir}/gpg-batch-key-script" +default_keypair_password="leap" +default_keypair_email="blackhole@leap.se" + +function usage () +{ + echo -e "\033[40m\033[36m Usage: $0 [-n [-c|-a]] | [-d|-h]\033[0m" + echo -e "\033[40m\033[36m --------------------------------------------------------\033[0m" + echo -e "\033[40m\033[36m Creates a set of GPG dummy keys for unittesting purposes.\033[0m" + echo + echo -e "\033[40m\033[36m Keys will be created in ${test_dir}, \033[0m" + echo -e "\033[40m\033[36m and a GnuPG batch file named ${batch_file##*/} \033[0m" + echo -e "\033[40m\033[36m will also be created in that same directory. \033[0m" + echo -e "\033[40m\033[36m The default password to all keys is: "'"'"${default_keypair_passwd}"'"'" \033[0m" + echo + echo -e "\033[40m\033[36m Options:\033[0m" + echo -e "\033[40m\033[36m -n,--number Number of keys (to create/append) \033[0m" + echo -e "\033[40m\033[36m -c,--create Create a fresh set of N test keys \033[0m" + echo -e "\033[40m\033[36m -a,--append Append another set of N test keys \033[0m" + echo -e "\033[40m\033[36m -d,--delete Delete the test keys and directory\033[0m" + echo -e "\033[40m\033[36m -h,--help This cruft\033[0m" +} + +## @param $1: the filename to write to +## @param $2: the directory to place test keys and batch files in +## @param $3: the number of keypairs to create +function write_gpg_batch_file () +{ + ## if the test directory doesn't exist, create it: + if ! test -w "${1}" ; then + if ! test -d "${2}"; then + mkdir $2 + fi + fi + + # if the batch file is already there, ask to back it up: + if test -r "${1}" ; then + read -ers -N 1 -t 60 \ + -p"Should we keep a backup copy the previous batch file? (Y/n) " bak + case $bak in + n|N ) echo -e "\033[40m\033[31m Overwriting ${1}...\033[0m" ;; + * ) iii=0 + backup="${1}.${iii}-"$(date +"%F")".bak" + while ! test -r "$backup" ; do + echo -e"\033[40m\033[36m Backing up to: \033[0m" + echo -e"\033[40m\033[36m ${backup} \033[0m" + cp $1 $backup + iii=$(( $iii + 1 )) + done ;; + esac + ## then always delete the old otherwise we'll append to that and generate + ## the previous batch's keys too: + ! test -r "${1}" || rm $1 + fi + + ## and whether we backed up or not, make our file if it doesn't exist: + if ! test -w "${1}" ; then + touch $1 && chmod +rw $1 + fi + echo -e "\033[40m\033[36m Writing GPG key generation batch file to: \033[0m" + echo -e "\033[40m\033[36m ${1}... \033[0m" + + total_keypairs=$(printf "%03d" ${3}) + echo "Total keypairs to be generated: ${total_keypairs}" + + this_month=$(date +"%m") # ## this is awkward...isn't there + expire_soon=$(( ${this_month} + 1 )) ## a better way? + next_month=$(printf "%02d" ${expire_soon}) + expiry_date=$(date +"%Y-")${next_month}$(date +"-%d") + echo "Expiry date for keypairs: ${expiry_date}" + + for i in $(seq -f "%03g" 1 $3 ) ; do + now=$(date +"%Y-%m-%d_%H-%M") + echo "Writing generation parameters for keypair #${i}..." + cat >> $1 < 0 ]] ; then + SHORTS="hcadn:" + LONGS="help,create,append,destroy,number:" + ARGS=$(getopt -s bash --options $SHORTS --longoptions $LONGS \ + --name ${0##*/} -- "$@") + + if [ $? != 0 ] ; then + echo -e "\033[40m\033[31m Unable to parse options. \033[0m">&2 + exit 1 + fi + eval set -- "$ARGS" + while test -n "$1" ; do + case $1 in + -n|--number ) export CREATE_N="$2" + if test -z "$CREATE_N"; then CREATE_N="3"; fi; + shift 2 ;; + -c|--create ) delete_batch_keys ${test_dir} + write_gpg_batch_file ${batch_file} ${test_dir} \ + ${CREATE_N} + run_gpg_batch_file ${batch_file} ${test_dir} + shift ;; + -a|--append ) run_gpg_batch_file ${batch_file} ${test_dir} + shift ;; + -d|--destroy ) delete_batch_keys ${test_dir} ; shift ;; + --) shift ; break ;; + * ) usage ; shift ;; + esac + done + finish +else + usage +fi + +unset here test_dir batch_file CREATE_N + diff --git a/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.pub b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.pub new file mode 100644 index 0000000..1c8fd34 Binary files /dev/null and b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.pub differ diff --git a/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.sec b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.sec new file mode 100644 index 0000000..97a60e7 Binary files /dev/null and b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.sec differ diff --git a/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.pub b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.pub new file mode 100644 index 0000000..1cbf8d8 Binary files /dev/null and b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.pub differ diff --git a/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.sec b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.sec new file mode 100644 index 0000000..f89cd97 Binary files /dev/null and b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.sec differ diff --git a/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.pub b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.pub new file mode 100644 index 0000000..bc0ac12 Binary files /dev/null and b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.pub differ diff --git a/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.sec b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.sec new file mode 100644 index 0000000..397f44a Binary files /dev/null and b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.sec differ diff --git a/pkg/utils/gpg-keys/gpg-batch-key-script b/pkg/utils/gpg-keys/gpg-batch-key-script new file mode 100644 index 0000000..7e48db0 --- /dev/null +++ b/pkg/utils/gpg-keys/gpg-batch-key-script @@ -0,0 +1,45 @@ +%echo Generating keypair 001/003... +Key-Type: RSA +Key-Length: 4096 +Subkey-Type: RSA +Subkey-Length: 4096 +Name-Real: Louis Lingg +Name-Email: blackhole@leap.se +Name-Comment: Test Key 001/003 +Expire-Date: 2013-03-15 +Passphrase: leap +%pubring generated-2013-02-15_19-15-001.pub +%secring generated-2013-02-15_19-15-001.sec +%commit +%echo done. 001 keys out of 003 completed. + +%echo Generating keypair 002/003... +Key-Type: RSA +Key-Length: 4096 +Subkey-Type: RSA +Subkey-Length: 4096 +Name-Real: Louis Lingg +Name-Email: blackhole@leap.se +Name-Comment: Test Key 002/003 +Expire-Date: 2013-03-15 +Passphrase: leap +%pubring generated-2013-02-15_19-15-002.pub +%secring generated-2013-02-15_19-15-002.sec +%commit +%echo done. 002 keys out of 003 completed. + +%echo Generating keypair 003/003... +Key-Type: RSA +Key-Length: 4096 +Subkey-Type: RSA +Subkey-Length: 4096 +Name-Real: Louis Lingg +Name-Email: blackhole@leap.se +Name-Comment: Test Key 003/003 +Expire-Date: 2013-03-15 +Passphrase: leap +%pubring generated-2013-02-15_19-15-003.pub +%secring generated-2013-02-15_19-15-003.sec +%commit +%echo done. 003 keys out of 003 completed. + diff --git a/pkg/utils/test_bootstrap b/pkg/utils/test_bootstrap new file mode 100755 index 0000000..f072d10 --- /dev/null +++ b/pkg/utils/test_bootstrap @@ -0,0 +1,39 @@ +#!/bin/bash +############################################################################## +# +# test_bootstrap +# -------------- +# Test that the bootstrap script works correctly by making a temporary new +# user. +# +# @author Isis Agora Lovecruft, 0x2cdb8b35 +# @date 18 February 2013 +# @version 0.0.1 +############################################################################## + +set -ex - + +HERE=$(pwd) +TEST_USER=bootstraptester + +echo "Creating new user: "'"'"${TEST_USER}"'"'"" +sudo adduser --home /home/${TEST_USER} --shell /bin/bash ${TEST_USER} && \ + echo -e "notsecure\nnotsecure\n" | sudo passwd ${TEST_USER} + +echo 'Copying boostrap script to new user home directory...' +sudo cp ${HERE}/bootstrap /home/${TEST_USER}/bootstrap && \ + sudo chown ${TEST_USER}:${TEST_USER} /home/${TEST_USER}/bootstrap + +echo 'Logging in as new user and executing bootstrap script...' +echo 'Executing test of bootstrap script...' +## -S pulls password from stdin +echo -e "notsecure\n" | sudo -S -H -u ${TEST_USER} -i /home/${TEST_USER}/bootstrap + +if [[ "$?" != 0 ]] ; then + echo 'Error while testing bootstrap...' +else + echo 'Test of bootstrap successful.' +fi + +echo "Deleting user: "'"'"${TEST_USER}"'"'"" +sudo deluser --remove-home ${TEST_USER} -- cgit v1.2.3