#!/usr/bin/tclsh # postinst script for helga # we only handle configure behavior if { [lindex $argv 0] != "configure" } { exit 0 } set helgaroot /helga set tclLibPath "/usr/share/tcltk" set version 1.0 set libPath $helgaroot/dist/$version/shell/lib # create the site dir file mkdir $helgaroot/site # create dist/log and site/log, make them world-writable file mkdir $helgaroot/site/log file attributes $helgaroot/site/log -permissions 0777 file mkdir $helgaroot/dist/log file attributes $helgaroot/dist/log -permissions 0777 puts "Creating configuration directory..." set confPath $helgaroot/dist/conf file mkdir $confPath if { ![file exists $confPath/helga.conf] } { puts "Creating Helga configuration file..." set confText "HELGAROOT=$helgaroot\n" append confText "HELGADOCROOT=\$HELGAROOT/public\n" append confText "HELGADISTROOT=\$HELGAROOT/dist\n" append confText "HELGASITEROOT=\$HELGAROOT/site\n" append confText "HELGACONFPATH=\$HELGADISTROOT/conf\n" append confText "HELGASHELLPATH=\$HELGADISTROOT/$version/shell\n" append confText "HELGAWEBPATH=\$HELGADISTROOT/$version/web\n" append confText "SVNSERVER=localhost\n" append confText "SQLSERVER=localhost\n" append confText "SQLDB=helga\n" append confText "SESSION_LENGTH=1800" set fp [open $confPath/helga.conf w] puts $fp $confText close $fp file attributes $confPath/helga.conf -permissions 0644 } if { ![file exists $confPath/admin.conf] } { puts "Creating Helga admin configuration file..." set confText "BASICSQLPASS=sqlbasic\n" append confText "ADVANCEDSQLPASS=sqladvanced\n" append confText "ADMINSQLPASS=sqladmin" set fp [open $confPath/admin.conf w] puts $fp $confText close $fp file attributes $confPath/admin.conf -permissions 0600 } # add HELGAROOT=/helga to /etc/profile if { [catch "grep HELGAROOT /etc/profile"] } { puts "Adding HELGAROOT to /etc/profile..." set fp [open /etc/profile] set data [read $fp] close $fp set profileLines [split $data \n] set newProfileData "" set addedLine false foreach line $profileLines { append newProfileData "$line\n" if { !$addedLine && [string index $line 0] != "#" } { append newProfileData "export HELGAROOT=$helgaroot\n\n" set addedLine true } } file delete /etc/profile set fp [open /etc/profile w] puts $fp $newProfileData close $fp } set ::env(HELGAROOT) /helga puts "Creating symlink to Helga Tcl libraries in $tclLibPath..." file delete $tclLibPath/helga$version file link $tclLibPath/helga$version $libPath set docroot $helgaroot/public puts "Creating Helga docroot directory..." file mkdir $docroot puts "Making your install of Helga Web web-accessible..." file delete $docroot/global file link $docroot/global $helgaroot/dist/1.0/web puts "Creating global index.html file..." set indexPath $docroot/index.html set indexText "" set fp [open $indexPath w] puts $fp $indexText close $fp puts "Adding a virtual host called helga to your apache set up..." set vhostData "" append vhostData "\n" append vhostData "\tServerName helga\n\n" append vhostData "\tServerAdmin brian@helgaproject.org\n\n" append vhostData "\tDocumentRoot $helgaroot/public/\n\n" append vhostData "\t\n" append vhostData "\t\tOptions Indexes FollowSymLinks MultiViews\n" append vhostData "\t\tAllowOverride None\n" append vhostData "\t\tOrder allow,deny\n" append vhostData "\t\tallow from all\n" append vhostData "\t\n\n" append vhostData "\tErrorLog /var/log/apache2/error.log\n\n" append vhostData "\tLogLevel warn\n\n" append vhostData "\tCustomLog /var/log/apache2/access.log combined\n\n" append vhostData "" set fp [open /etc/apache2/sites-available/helga w] puts $fp $vhostData close $fp exec a2ensite helga puts -nonewline "Enter your MySQL root password: " flush stdout exec stty -echo gets stdin rootpass exec stty echo puts "\nCreating your Helga MySQL database..." exec mysql -u root --password=$rootpass -e "CREATE DATABASE helga" # create Helga db users puts "Creating your Helga MySQL users..." exec mysql -u root --password=$rootpass -e "GRANT ALL ON helga.* TO helgaGuest@'localhost'"; exec mysql -u root --password=$rootpass -e "GRANT ALL ON helga.* TO helgaBasic@'localhost' IDENTIFIED BY 'sqlbasic'"; exec mysql -u root --password=$rootpass -e "GRANT ALL ON helga.* TO helgaAdvanced@'localhost' IDENTIFIED BY 'sqladvanced'"; exec mysql -u root --password=$rootpass -e "GRANT ALL ON helga.* TO helgaAdmin@'localhost' IDENTIFIED BY 'sqladmin' WITH GRANT OPTION"; # run sqlRake puts "Running sqlRake script to populate your database..." if { [catch "open \"| $helgaroot/dist/1.0/util/sqlRake $rootpass 2>@stdout\"" fp] } { puts "ERROR: can't open pipe for sqlRake - $fp" exit 1 } fconfigure $fp -buffering none while { [gets $fp data] >= 0 } { puts $data flush stdout } if { [catch {close $fp} errmsg] } { if { ![string match "child process exited abnormally" "$errmsg"] } { return "ERROR: could not close pipe for '$cmd' - $errmsg" } } # build production js files #exec "Building the Helga JavaScript files..." #exec $helgaroot/dist/1.0/web/lib/js/build.sh file copy /etc/sudoers /etc/sudoers.prehelga_backup set fp [open /etc/sudoers] set data [read $fp] close $fp set sudoLines [split $data \n] set newSudo "" foreach line $sudoLines { if { [string range $line 0 7] == "Defaults" } { set envIndex [string first env_reset $line] if { $envIndex == -1 } { set line "$line,!env_reset" } elseif { [string index $line [expr $envIndex - 1]] != "!" } { set line [string replace $line $envIndex [expr $envIndex + 8] !env_reset] } } append newSudo "$line\n" } append newSudo "ALL ALL=NOPASSWD:$helgaroot/dist/*/shell/helgaAuth.tclsh\n" append newSudo "ALL ALL=NOPASSWD:$helgaroot/dist/*/shell/getSessionData.tclsh\n" append newSudo "ALL ALL=NOPASSWD:$helgaroot/dist/*/shell/hpasswd.tclsh" set fp [open /etc/sudoers.helga w] puts $fp $newSudo close $fp file attributes /etc/sudoers.helga -permissions 0440 puts -nonewline "\nHelga installation complete. During the process we have created a file /etc/sudoers.helga. This file must either replace /etc/sudoers or be merged with it. Do you understand? " flush stdout gets stdin response exit 0