7 echo "Stopping services."
8 sudo service freeside stop
9 sudo service apache2 stop
11 newname=freeside_`date +%Y%m%d`
12 sharedir=$(perl -MFS::Test -e "print FS::Test::share_dir()")
14 # get company_name from existing DB, strip whitespace
15 # (if there is no existing DB, continue anyway)
16 testdbmarker=$(sudo -u freeside \
17 psql -tc 'select value from conf where name='\'company_name''\' | \
24 if psql -l |grep -q '^ *freeside '; then
25 if [ "$testdbmarker" = "Freeside Test $VERSION" ]; then
27 echo "Freeside test database found."
29 echo "Renaming database to $newname."
30 psql postgres -c "ALTER DATABASE freeside RENAME TO $newname"
34 if [ $createdb = YES ]; then
35 echo "Creating new database from stock schema."
36 createdb --owner=freeside freeside
37 sudo -u freeside psql freeside -q -f $sharedir/test.sql > /dev/null
40 if [ -f /usr/local/etc/freeside/htpasswd ]; then
41 newhtpasswd=htpasswd_`date +%Y%m%d`
42 echo "Renaming htpasswd to $newhtpasswd."
43 sudo mv /usr/local/etc/freeside/htpasswd /usr/local/etc/freeside/$newhtpasswd
46 echo "Installing new htpasswd."
47 sudo cp $sharedir/htpasswd /usr/local/etc/freeside/htpasswd
49 newtime=$(sudo -u freeside \
50 psql -tc 'SELECT to_timestamp(max(_date) + 86400) FROM cust_bill' \
52 # no longer needed since we don't run LaTeX in the test script
53 #echo "Setting clock to $newtime."
54 #sudo date -s "$newtime"
56 #echo "Applying upgrades."
57 #sudo -u freeside freeside-upgrade test
58 # shouldn't happen automatically
60 # start Apache on a future date when all of the invoice dates are in the past
61 echo "Restarting Apache."
62 sudo faketime "$newtime" apache2ctl start