diff --git a/srchub-install.py b/srchub-install.py index ce5d64e..9a70dab 100644 --- a/srchub-install.py +++ b/srchub-install.py @@ -2,6 +2,7 @@ import locale from dialog import Dialog from subprocess import call import sys +import os # This is almost always a good thing to do at the beginning of your programs. locale.setlocale(locale.LC_ALL, '') @@ -55,20 +56,162 @@ INDEFERO_SVN_APACHE = """ AuthUserFile /home/svn/dav_svn.passwd """ -d = Dialog(dialog="dialog", autowidgetsize=True) -distro = "" -def install_debian_package(package): - d.infobox(package, title="Installing...") - # install package +GIT_DAEMON_CONF = """#!/bin/sh +exec 2>&1 +echo 'git-daemon starting.' +exec chpst -ugit:git \ + "$(git --exec-path)"/git-daemon --verbose --base-path=/home/git/repositories /home/git/repositories +""" + +HTACCESS = """ +Options +FollowSymLinks +RewriteEngine On +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule ^(.*) /index.php/$1 +""" + +FINAL_MSG = """ +I did NOT modify Apache for you - +In /etc/apache2/sites-available you should find 3 files: +[1] - indefero.base - this is what is needed for private repos +[2] - indefero.svn - this is what is needed for subversion repos +[3] - indefero.hg - this is what is needed for mercurial repos +Add what you want into your virtualhost config +SUBVERSION AND MERCURIAL WILL NOT WORK OTHERWISE! + +Please add the following to your sudoers (visudo) file - this grants Apache the ability to reload itself: +www-data ALL=(ALL) NOPASSWD: /etc/init.d/apache2 reload + +You will need to edit /home/www/indefero/src/IDF/conf/idf.php and fill in your database information +Then run: + php /home/www/pluf/src/migrate.php --conf=IDF/conf/idf.php -a -i -d +Then finally to create the user: + php /home/www/indefero/scripts/bootstrap.php +to create the admin user (username: admin, password: admin) +""" + +AUTHBASIC_PATCH = """ +--- Authbasic.php 2013-07-23 22:33:50.000000000 -0500 ++++ /usr/share/php/File/Passwd/Authbasic.php 2013-06-03 19:07:37.000000000 -0500 +@@ -17,7 +17,7 @@ + * @author Michael Wallner + * @copyright 2003-2005 Michael Wallner + * @license http://www.php.net/license/3_0.txt PHP License 3.0 +- * @version CVS: $Id$ ++ * @version CVS: $Id: Authbasic.php,v 1.17 2005/03/30 18:33:33 mike Exp $ + * @link http://pear.php.net/package/File_Passwd + */ + +@@ -52,7 +52,7 @@ + * + * @author Michael Wallner + * @package File_Passwd +-* @version $Revision$ ++* @version $Revision: 1.17 $ + * @access public + */ + class File_Passwd_Authbasic extends File_Passwd_Common +@@ -79,7 +79,7 @@ + * @var array + * @access private + */ +- var $_modes = array('md5' => 'm', 'des' => 'd', 'sha' => 's'); ++ var $_modes = array('plain' => 'p', 'md5' => 'm', 'des' => 'd', 'sha' => 's'); + + /** + * Constructor +@@ -298,7 +298,7 @@ + $mode = strToLower($mode); + if (!isset($this->_modes[$mode])) { + return PEAR::raiseError( +- sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, $mode), ++ sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, $this->_mode), + FILE_PASSWD_E_INVALID_ENC_MODE + ); + } +@@ -326,7 +326,9 @@ + return File_Passwd::crypt_des($pass, $salt); + } elseif ($mode == 'sha') { + return File_Passwd::crypt_sha($pass, $salt); +- } ++ } elseif ($mode == 'plain') { ++ return $pass; ++ } + + return PEAR::raiseError( + sprintf(FILE_PASSWD_E_INVALID_ENC_MODE_STR, $mode), + +""" +d = Dialog(dialog="dialog", autowidgetsize=True) +distro = "" def exit_msg(): print "Thank you for using the srchub installer\n" print "Please send feedback to adamsna@datanethost.net" def install_cron_jobs(): - return d.yesno("Do you want me to attempt to install the cron jobs?") + answer = d.yesno("Do you want me to attempt to install the cron jobs?") + if answer == d.DIALOG_OK: + d.infobox("Setting up cron jobs...") + commands = [] + commands.append("0 1 * * * %s" % ("/usr/bin/php5 /home/www/indefero/scripts/activitycron.php")) + commands.append("*/5 * * * * %s" % ("/bin/sh /home/www/indefero/scripts/SyncMercurial.sh")) + commands.append("15 * * * * /usr/bin/php5 /home/www/indefero/scripts/calculateforgecron.php") + commands.append("*/5 * * * * /usr/bin/php5 /home/www/indefero/scripts/queuecron.php") + for command in commands: + call(["(crontab -l; echo '%s') | crontab" % command]) + +def update_mercurial_hooks(): + hgconf = "" + d.infobox("Checking for mercurial hooks...") + with open('/etc/mercurial/hgrc', 'r') as content_file: + hgconf = content_file.read() + if "hgchangegroup" not in hgconf: + hgconf += "\n[hooks]\nchangegroup = /home/www/indefero/scripts/hgchangegroup.php" + with open('/etc/mercurial/hgrc', 'w') as content_file: + content_file.write(hgconf) + +def setup_git_daemon(): + d.infobox("Setting up git daemon...") + if not os.path.isfile("/etc/sv/git-daemon/run.srchub"): + call(["mv", "/etc/sv/git-daemon/run", "/etc/sv/git-daemon/run.srchub"]) + with open('/etc/sv/git-daemon/run', 'w') as content_file: + content_file.write(GIT_DAEMON_CONF) + call(["adduser", "git"]) + +def setup_web_links(): + code, user_input = d.inputbox("I need to setup some web links. Where is your web root? (no leading slash)", init="/var/www") + call(["ln", "-s", "/home/www/indefero/www/index.php", "%s/index.php" % user_input]) + call(["ln", "-s", "/home/www/indefero/www/media", "%s/media" % user_input]) + with open("%s/.htaccess" % user_input, 'w') as content_file: + content_file.write(HTACCESS) + +def install_pear_modules(): + call(["pear", "install", "File_Passwd"]) + call(["pear", "upgrade-all"]) + call(["pear", "install", "--alldeps", "Mail"]) + call(["pear", "install", "--alldeps", "Mail_mime"]) + +def fix_auth_basic(): + with open('/tmp/patch', 'w') as content_file: + content_file.write(AUTHBASIC_PATCH) + call(["patch", "-N", "/usr/share/php/File/Passwd/Authbasic.php", "<", "/tmp/Authbasic.patch"]) + call(["rm /tmp/patch"]) + +def prep_apache(): + call(["a2enmod", "rewrite"]) + with open('/etc/apache2/sites-available/indefero.base', 'w') as content_file: + content_file.write(INDEFERO_BASE_APACHE) + with open('/etc/apache2/sites-available/indefero.hg', 'w') as content_file: + content_file.write(INDEFERO_HG_APACHE) + with open('/etc/apache2/sites-available/indefero.svn', 'w') as content_file: + content_file.write(INDEFERO_SVN_APACHE) + +def final_msg(): + d.msgbox(FINAL_MSG) def install_package(package): if distro == "Debian": @@ -79,7 +222,7 @@ def install_packages(): if code == d.OK: d.gauge_start("Installing...") packages = ["git", "mercurial", "subversion", "mariadb-server", "mariadb-client", "libapache2-mod-php5", - "php5-curl", "php5-mysql", "php5-cli", "git-daemon-run", "gitweb", "php-pear"] + "php5-curl", "php5-mysql", "php5-cli", "git-daemon-run", "gitweb", "php-pear", "patch"] percent = 0 i = 0 for package in packages: @@ -87,7 +230,7 @@ def install_packages(): install_package(package) i += 1 percent = (i / len(packages)) * 100 - + d.gauge_stop() d.set_background_title("Srchub Installer") @@ -116,10 +259,35 @@ code, tag = d.menu("Choose carefully:", choices=[ ]) if code == d.OK: + install_packages() if tag == "1": # Install srchub - pass + call(["git", "clone", "git://srchub.org/srchub-git.git", "/home/www"]) + + install_cron_jobs() + update_mercurial_hooks() + setup_git_daemon() + setup_web_links() + install_pear_modules() + fix_auth_basic() + prep_apache() + final_msg() + print FINAL_MSG else: # Install indefero vanilla - pass + call(["git", "clone", "git://srchub.org/indefero.git", "/home/www/indefero"]) + call(["git", "clone", "git://srchub.org/pluf2.git", "/home/www/pluf"]) + + install_cron_jobs() + update_mercurial_hooks() + setup_git_daemon() + setup_web_links() + install_pear_modules() + prep_apache() + final_msg() + print FINAL_MSG + + + -exit_msg() \ No newline at end of file +exit_msg() +sys.exit() \ No newline at end of file