#!/bin/bash dbquery() { mysql -s -s -e "$*" trac } # 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