From f27184e291baddcc572ddd2db7ccbafd42278620 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 17 Aug 2008 14:00:03 +0200 Subject: initial commit --- bin/addproject | 112 ++++++++++++++++++++++++++++++ bin/config.sh | 9 +++ bin/delproject | 99 +++++++++++++++++++++++++++ bin/functions.sh | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 422 insertions(+) create mode 100755 bin/addproject create mode 100644 bin/config.sh create mode 100755 bin/delproject create mode 100644 bin/functions.sh diff --git a/bin/addproject b/bin/addproject new file mode 100755 index 0000000..4a038dd --- /dev/null +++ b/bin/addproject @@ -0,0 +1,112 @@ +#!/bin/bash + +# main function +main() { + echo + + # project_name may not be an empty string and must be >= 3 characters + while [[ ${#project_name} -lt 3 ]] + do + eask_str "a project name (min 3 chars)" + project_name=${REPLY} + done + + # who requests the project ? + while [[ -z ${user_email} ]] + do + eask_str "email address (*.fu-berlin.de) of applicant" + user_email=${REPLY} + don (*.fu-berlin.de) of applicant" + user_email=${REPLY} + done + + einfo + einfo "$(color yellow)public project:$(color) read access for everyone with a spline-dev account." \ + "write access only for project members. this is the default." + einfo "$(color yellow)private project:$(color) read and write access only for project members." + einfo + eask_bool "Should the project be private?" n + project_closed=${REPLY} + + svn_home=${SVN_ROOT}/${project_name} + trac_home=${TRAC_ROOT}/${project_name} + trac_db=trac_${project_name} + + eheading "creating new subversion directory" + eexec svnadmin create ${svn_home} + tmpdir=$(mktemp -d) + eexec mkdir -p ${tmpdir}/{trunk,tags,branches} + eexec svn -q import -m "initial import for project ${project_name}" ${tmpdir} file://${svn_home} + eexec chown -R apache:apache ${svn_home} + eexec rm -rf ${tmpdir} + + eheading "creating new trac project" + eexec mysqladmin create ${trac_db} + eexec trac-admin ${trac_home} initenv --inherit=${TRAC_INI} ${project_name} "mysql://${MYSQL_USER}:${MYSQL_PASS}@${MYSQL_HOST}/${trac_db}" svn ${svn_home} + if [[ ${project_closed} == y ]] + then + for perm in BROWSER_VIEW CHANGESET_VIEW FILE_VIEW LOG_VIEW MILESTONE_VIEW \ + REPORT_SQL_VIEW REPORT_VIEW ROADMAP_VIEW SEARCH_VIEW TICKET_VIEW \ + TIMELINE_VIEW WIKI_VIEW + do + eexec trac-admin ${trac_home} permission remove anonymous ${perm} + done + fi + + for perm in TICKET_CREATE TICKET_MODIFY WIKI_CREATE WIKI_MODIFY + do + eexec trac-admin ${trac_home} permission remove authenticated ${perm} + done + + eexec trac-admin ${trac_home} permission add authenticated TRAC_ADMIN + + eheading "setting up apache2" + eexec sed -i -e "\$a\\# ${project_name} (added on $(date -R))\\" ${APACHE_PROJECT_CONF} + eexec sed -i -e "\$a\\Use TracProject ${project_name}\\" ${APACHE_PROJECT_CONF} + + if [[ ${project_closed} == y ]] + then + eexec sed -i -e "\$a\\Use SVNProjectClosed ${project_name}\\" ${APACHE_PROJECT_CONF} + else + eexec sed -i -e "\$a\\Use SVNProject ${project_name}\\" ${APACHE_PROJECT_CONF} + fi + + echo >> ${APACHE_PROJECT_CONF} + eexec /etc/init.d/apache2 reload + + eheading "committing changes to our git-repository in /etc" + pushd /etc > /dev/null + eexec git add ${APACHE_PROJECT_CONF/\/etc\/} + eexec git commit -m "added new project ${project_name}" + popd > /dev/null + + eheading "requesting new mailinglist for the project" + # register mailinglist (owner is user_email) for the new project + eexec wget --no-check-certificate --post-data "name=commit-${project_name}&email=${user_email}" \ + https://lists.spline.inf.fu-berlin.de/cgi-bin/neueliste.pl + + echo + einfo + einfo "done! success! jipii! neeeat!" + einfo "you can find your project at $(color yellow)https://dev.spline.de/trac/${project_name}$(color)" + einfo + echo +} + +# go to script dir +pushd $(dirname $0) > /dev/null + +# get global functions +source "./functions.sh" + +# load configuration +source "./config.sh" + +# exit on errors +set -e + +# start main program +main "$@" + +# leave script dir +popd > /dev/null diff --git a/bin/config.sh b/bin/config.sh new file mode 100644 index 0000000..182f577 --- /dev/null +++ b/bin/config.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +MYSQL_HOST=localhost +MYSQL_USER=trac +MYSQL_PASS=z8cdFshvR +SVN_ROOT=/var/lib/svn +TRAC_INI=/etc/trac/trac.ini +TRAC_ROOT=/var/lib/trac +APACHE_PROJECT_CONF=/etc/apache2/vhosts.d/dev_vhost.include diff --git a/bin/delproject b/bin/delproject new file mode 100755 index 0000000..4852276 --- /dev/null +++ b/bin/delproject @@ -0,0 +1,99 @@ +#!/bin/bash + +# main function +main() { + echo + + # project_name may not be an empty string and must be >= 3 characters + while [[ ${#project_name} -lt 3 ]] + do + eask_str "a project name (min 3 chars)" + project_name=${REPLY} + done + + svn_home=${SVN_ROOT}/${project_name} + trac_home=${TRAC_ROOT}/${project_name} + trac_db=trac_${project_name} + + eheading "deleting apache configuration" + eexec sed -i -e "/^# ${project_name} /,/^\$/d" ${APACHE_PROJECT_CONF} + eexec /etc/init.d/apache2 reload + + eheading "committing changes to our git-repository in /etc" + pushd /etc >> /dev/null + eexec git add ${APACHE_PROJECT_CONF/\/etc\/} + eexec git commit -m "deleted project ${project_name}" || : + popd >> /dev/null + + + random_dir=$(echo $RANDOM |md5sum |awk '{print $1}') + backup_file=/var/www/localhost/htdocs/backup/${random_dir}/${project_name}-$(date +%Y%b%d).tar.bz2 + + eheading "creating backup in ${backup_file}" + + tmpdir=$(mktemp -d) + eexec rsync -a ${svn_home}/ ${tmpdir}/svn/ + eexec rsync -a ${trac_home}/ ${tmpdir}/trac/ + eexec mysqldump ${trac_db} -r ${tmpdir}/trac.sql + eexec mkdir -p $(dirname ${backup_file}) + eexec tar --exclude trac.ini -cjf ${backup_file} -C ${tmpdir} . + eexec rm -rf ${tmpdir} + + # get all member email from the database 'mysql trac' + members=$(mysql -s -s -e \ + "select u.email from user u join member m on m.user_id = u.id join project p on p.id = m.project_id where p.project_name = '${project_name}'" \ + trac) + + eheading "making the backup available for the project members" + einfo "sending backup link to " + for member in ${members} + do + einfo " ${member}" + sendmail -t <<-EOF + From: dev@spline.de + Subject: the project ${project_name} has been deleted + To: ${member} + + hello ${member}, + + the project ${project_name} of which you have been a member has been + deleted. for the next week you can however download a backup of the + project using this link: + + https://dev.spline.de/backup/${random_dir}/$(basename ${backup_file}) + + yours, + the dev.spline.de team + EOF + done + + eheading "deleting project files" + eexec rm -rf ${svn_home} + eexec rm -rf ${trac_home} + eexec mysqladmin --force drop ${trac_db} + eexec mysql -e "DELETE FROM project WHERE project_name = '${project_name}'" trac + + einfo + einfo "done! success! jipii! neeeat!" + einfo "you cannot find your project anywhere now" + einfo + echo +} + +# go to script dir +pushd $(dirname $0) > /dev/null + +# get global functions +source "./functions.sh" + +# load configuration +source "./config.sh" + +# exit on errors +set -e + +# start main program +main "$@" + +# leave script dir +popd > /dev/null diff --git a/bin/functions.sh b/bin/functions.sh new file mode 100644 index 0000000..3dbbb7c --- /dev/null +++ b/bin/functions.sh @@ -0,0 +1,202 @@ +# output handling +coco() { + [[ -z "$1" ]] && echo -ne "\033[0m" || echo -ne "\033[${1}m" +} + +# name all colors to get rid of hieroglyphics +color() { + case $1 in + black) coco '0;30' ;; + dgray) coco '1;30' ;; + red) coco '0;31' ;; + lred) coco '1;31' ;; + green) coco '0;32' ;; + lgreen) coco '1;32' ;; + brown) coco '0;33' ;; + yellow) coco '1;33' ;; + blue) coco '0;34' ;; + lblue) coco '1;34' ;; + purple) coco '0;35' ;; + lpurple) coco '1;35' ;; + cyan) coco '0;36' ;; + lcyan) coco '1;36' ;; + lgray) coco '0;37' ;; + white) coco '1;37' ;; + *) coco '0' ;; + esac +} + +_einfon() { + echo -ne " ${GOOD}*${NORMAL} $*" + return 0 +} + +_einfo() { + echo -e " ${GOOD}*${NORMAL} $*" + return 0 +} + +_ewarn() { + echo -e " ${WARN}*${NORMAL} $*" + return 0 +} + +_eerror() { + echo -e " ${BAD}*${NORMAL} $*" + return 0 +} + +_ewrap() { + local cmd="$1" + shift + + local c="${ENDCOL}" + local p="$* " + local max=$((COLS - 11)) + + # Only use what we have space for + local d="${p%%\\n*}" + if [[ ${d} == "${p}" ]] ; then + d="${p:0:${max}}" + else + d="${d} " + fi + + # Grab the last whole word + [[ ${#d} == "${max}" ]] && d="${d% *}" + + # Print that + _${cmd} "${d}" + + # Recurse on the rest + local r="$*" + d="${d} " + r="${r:${#d}}" + [[ -n ${r} ]] && ${cmd} "${r}" + + return 0 +} + +einfo() { + _ewrap einfo "$*" +} + +ewarn() { + _ewrap ewarn "$*" +} + +eerror() { + _ewrap eerror "$*" + return 1 +} + +eheading() { + echo + echo -n "$(color green)>>> " + echo -n "$@" + echo " <<<$(color)" +} + +# input handling +eask_num() { + local -i reply= + _einfon + read -p "Please enter ${1:-Number} or press CTRL-C to abort> " reply + REPLY=${reply} +} + +eask_str() { + local reply= + _einfon + read -p "Please enter ${1:-String} or press CTRL-C to abort> " reply + REPLY=${reply} +} + +eask_bool() { + local reply= default=${2} str="[y/n]" + + if [[ ${default} == y || ${default} == Y || ${default} == true ]] + then + str="[Y/n]" + elif [[ ${default} == n || ${default} == N || ${default} == false ]] + then + str="[y/N]" + fi + + while [[ "${reply}" != y && "${reply}" != n ]]; do + _einfon + read -p "${1} ${str} " reply + + if [[ -z ${reply} ]] + then + reply=${default} + break + fi + done + + REPLY=${reply} +} + + +echoose() { + einfo ${1:-"Choose something from the following list"} + einfo + shift + + local -a items= + + while true; do + items=() + + for i in "$@"; do + items=( "${items[@]}" "${i}" ) + einfo "${#items[@]}) ${i}" + done + + eask_num + + if [[ ${REPLY} -le 0 || ${REPLY} -gt ${#items[@]} ]]; then + eerror "\nInvalid selection. Try again.\n " || : + else + break + fi + done + + REPLY=${items[$(( ${REPLY} - 1 ))]} +} + +# make-like exec wrapper +eexec() { + einfo "$@" + "$@" +} + +# alway use the right thing, even if EDITOR is not set +editor() { + if [[ -z "${EDITOR}" || ! -x "${EDITOR}" ]]; then + if [[ -x /usr/bin/vim ]]; then + EDITOR=/usr/bin/vim + elif [[ -x /usr/bin/nano ]]; then + EDITOR=/usr/bin/nano + fi + fi + + [[ -x ${EDITOR} ]] && ${EDITOR} "$@" +} + +# Setup a secure $PATH. Just add system defaults. +PATH="/bin:/sbin:/usr/bin:/usr/sbin" + +if [[ -z ${COLS} || -n ${COLUMNS} ]] ; then + COLS="${COLUMNS:-0}" + (( COLS == 0 )) && COLS=$(set -- `stty size 2>/dev/null` ; echo "$2") + (( COLS > 0 )) || (( COLS = 80 )) +fi + +ENDCOL=$'\e[A\e['$(( COLS - 9 ))'C' +GOOD=$'\e[32;01m' +WARN=$'\e[33;01m' +BAD=$'\e[31;01m' +NORMAL=$'\e[0m' + +# vim: set ts=4 : -- cgit v1.2.3