summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorTomas Touceda <chiiph@leap.se>2013-04-25 12:12:02 -0300
committerTomas Touceda <chiiph@leap.se>2013-04-25 12:12:02 -0300
commita0df6b9b8fbf7d4db53bb21f379cb1941d823a5b (patch)
tree688a9442985c1e849a301dd85b1988c38643c7e5 /pkg
parent28a5992e9b4c5a9a080ad39ba6483843c99f1c47 (diff)
Reorder files, normalize repo and add sample config
Diffstat (limited to 'pkg')
-rwxr-xr-xpkg/utils/bootstrap59
-rwxr-xr-xpkg/utils/gpg-key-generator209
-rw-r--r--pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.pubbin0 -> 2779 bytes
-rw-r--r--pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.secbin0 -> 5453 bytes
-rw-r--r--pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.pubbin0 -> 2779 bytes
-rw-r--r--pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.secbin0 -> 5453 bytes
-rw-r--r--pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.pubbin0 -> 2779 bytes
-rw-r--r--pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.secbin0 -> 5453 bytes
-rw-r--r--pkg/utils/gpg-keys/gpg-batch-key-script45
-rwxr-xr-xpkg/utils/test_bootstrap39
10 files changed, 352 insertions, 0 deletions
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 <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 <N> 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 <<EOF
+%echo Generating keypair ${i}/${total_keypairs}...
+Key-Type: RSA
+Key-Length: 4096
+Subkey-Type: RSA
+Subkey-Length: 4096
+Name-Real: Louis Lingg
+Name-Email: $default_keypair_email
+Name-Comment: Test Key ${i}/${total_keypairs}
+Expire-Date: $expiry_date
+Passphrase: $default_keypair_password
+%pubring generated-${now}-${i}.pub
+%secring generated-${now}-${i}.sec
+%commit
+%echo done. $i keys out of ${total_keypairs} completed.
+
+EOF
+ done
+}
+
+## @param $1: the filename to write to
+## @param $2: the directory to place test keys and batch files in
+function run_gpg_batch_file ()
+{
+ our_gpg=$(which gpg)
+
+ if ! test -r "${batch_file}" ; then
+ echo -e "\033[40m\033[31m Could not find ${batch_file}. Exiting...\033[0m"
+ exit 1
+ fi
+
+ if test -z "$our_gpg" ; then
+ echo -e "\033[40m\033[31m Could not find gnupg. Exiting...\033[0m"
+ exit 1
+ fi
+
+ if test -n "${our_gpg}" ; then
+ cd ${2} && $($our_gpg --batch --gen-key ${1})
+ fi
+}
+
+## @param $1: the test dir
+function delete_batch_keys ()
+{
+ if test -d "$1" ; then
+ read -ers -N 1 -t 60 \
+ -p'Delete the current GPG test keys directory? (Y/n) ' delkeys
+ if test -n "$delkeys" ; then
+ case $delkeys in
+ n|N )
+ echo -e "\033[40m\033[31m Skipping deletion. \033[0m" ;;
+ *)
+ echo -e "\033[40m\033[36m Deleting old test keys...\033[0m"
+ if test -d "$1" ; then
+ rm -r $1
+ else
+ echo -e "\033[40m\033[31m Cannot delete: $1\033[0m"
+ fi ;;
+ esac
+ fi
+ fi
+}
+
+function finish ()
+{
+ cat<<FIN
+To use the generated GnuPG keys, assuming you do not wish to use
+the default keyrings in your home directory, you should do:
+
+ \$ useradd -N -m keytester
+ \$ cd ${test_dir}
+ \$ for key in \`find . -name "generated-*"\`; do chown keytester:$USER \$key; done
+ \$ for key in \`find . -name *.sec\`; do chown keytester:$USER \$key; done
+ \$ sudo -i -u keytester
+ \$ cd ${test_dir}
+ \$ for key in \`find . -name "generated-*"\`; do gpg --import \$key; done
+ \$ gpg --list-keys
+
+FIN
+}
+
+## main
+if [[ "$#" > 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
--- /dev/null
+++ b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.pub
Binary files 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
--- /dev/null
+++ b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-001.sec
Binary files 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
--- /dev/null
+++ b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.pub
Binary files 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
--- /dev/null
+++ b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-002.sec
Binary files 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
--- /dev/null
+++ b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.pub
Binary files 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
--- /dev/null
+++ b/pkg/utils/gpg-keys/generated-2013-02-15_19-15-003.sec
Binary files 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}