| 1 | #!/usr/bin/perl -w | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | my($clientname, $dbname, $dbhost, $dbuser, $dbpass, $calname, $pubdir, $answer); | ||
| 6 | |||
| 7 | ## get db info etc | ||
| 8 | $dbhost = getinput("Enter valid postgres host (leave blank for localhost): "); | ||
| 9 | $dbname = getinput("Enter valid postgres database name: ", 1); | ||
| 10 | $dbuser = getinput("Enter valid database username: ", 1); | ||
| 11 | $dbpass = getinput("Enter valid database password for user $dbuser: "); | ||
| 12 | $clientname = getinput("Enter client (person owning calendar) name: ", 1); | ||
| 13 | $calname = getinput("Enter calendar name: ", 1); | ||
| 14 | $pubdir = getinput("Enter directory to where you wish to publish static calendars: ", 1); | ||
| 15 | |||
| 16 | # make postgres setup sql script | ||
| 17 | makeSql(); | ||
| 18 | |||
| 19 | # attempt to run sql script? | ||
| 20 | if (!$dbhost) { | ||
| 21 | $answer = getinput("SQL script has been created and stored in ./calendar.sql.\nDo you wish to attempt to run this script now? <yes/no>: [yes]"); | ||
| 22 | if (($answer eq "yes") || ($answer eq "y") || !$answer) { | ||
| 23 | runScript(); | ||
| 24 | } | ||
| 25 | else { | ||
| 26 | print "*** Skipping attempt, please run this script (./calendar.sql) later in order to set up proper database tables.\n\n"; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | else { | ||
| 30 | print "*** SQL script has been created and stored in ./calendar.sql.\nPlease run this later on the database host in order to set up the proper database tables.\n\n"; | ||
| 31 | } | ||
| 32 | |||
| 33 | # print out env variables | ||
| 34 | printEnv(); | ||
| 35 | |||
| 36 | exit(1); | ||
| 37 | |||
| 38 | ################################################################### | ||
| 39 | |||
| 40 | sub printEnv { | ||
| 41 | my $list = "SetEnv DB_NAME \"$dbname\"\nSetEnv DB_HOST \"$dbhost\"\nSetEnv DB_USER \"$dbuser\"\nSetEnv DB_PASS \"$dbpass\"\nSetEnv DB_CLIENT \"$clientname\"\nSetEnv DB_CALENDAR \"$calname\"\nSetEnv CAL_PUB_DIR \"$pubdir\""; | ||
| 42 | open (FILE, ">./CAL_ENV.list"); | ||
| 43 | print FILE $list; | ||
| 44 | close(FILE); | ||
| 45 | print "The following is a list of environment variables which you either need to add to your webserver configuration, or edit the cgi scripts to include. This list has also been printed to './CAL_ENV.list'.\n\n"; | ||
| 46 | print $list."\n\n"; | ||
| 47 | |||
| 48 | } | ||
| 49 | |||
| 50 | sub runScript { | ||
| 51 | my $psql = getinput("Please enter path to psql executable: [/usr/local/pgsql/bin/psql] "); | ||
| 52 | |||
| 53 | $psql = '/usr/local/pgsql/bin/psql' if !$psql; | ||
| 54 | |||
| 55 | print "\nRunning sql setup script, output below....\n\n"; | ||
| 56 | `$psql $dbname -U $dbuser < ./calendar.sql`; | ||
| 57 | } | ||
| 58 | |||
| 59 | |||
| 60 | sub makeSql { | ||
| 61 | open (FILE, ">./calendar.sql") || die("\nCannot open file ./calendar.sql for writing. Please make sure you have the proper permissions to write into this directory.\n\n"); | ||
| 62 | |||
| 63 | print FILE '-- | ||
| 64 | -- Selected TOC Entries: | ||
| 65 | -- | ||
| 66 | \connect - '.$dbuser.' | ||
| 67 | -- | ||
| 68 | -- TOC Entry ID 2 (OID 18851) | ||
| 69 | -- | ||
| 70 | -- Name: client_clientid_seq Type: SEQUENCE Owner: '.$dbuser.' | ||
| 71 | -- | ||
| 72 | |||
| 73 | CREATE SEQUENCE "client_clientid_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; | ||
| 74 | |||
| 75 | -- | ||
| 76 | -- TOC Entry ID 8 (OID 18870) | ||
| 77 | -- | ||
| 78 | -- Name: client Type: TABLE Owner: '.$dbuser.' | ||
| 79 | -- | ||
| 80 | |||
| 81 | CREATE TABLE "client" ( | ||
| 82 | "clientid" integer DEFAULT nextval(\'"client_clientid_seq"\'::text) NOT NULL, | ||
| 83 | "clientname" character varying(64) NOT NULL, | ||
| 84 | Constraint "client_pkey" Primary Key ("clientid") | ||
| 85 | ); | ||
| 86 | |||
| 87 | -- | ||
| 88 | -- TOC Entry ID 4 (OID 18977) | ||
| 89 | -- | ||
| 90 | -- Name: calendar_calendarid_seq Type: SEQUENCE Owner: '.$dbuser.' | ||
| 91 | -- | ||
| 92 | |||
| 93 | CREATE SEQUENCE "calendar_calendarid_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; | ||
| 94 | |||
| 95 | -- | ||
| 96 | -- TOC Entry ID 9 (OID 18996) | ||
| 97 | -- | ||
| 98 | -- Name: calendar Type: TABLE Owner: '.$dbuser.' | ||
| 99 | -- | ||
| 100 | |||
| 101 | CREATE TABLE "calendar" ( | ||
| 102 | "calendarid" integer DEFAULT nextval(\'"calendar_calendarid_seq"\'::text) NOT NULL, | ||
| 103 | "clientid" integer NOT NULL, | ||
| 104 | "name" character varying(64) NOT NULL, | ||
| 105 | "border" integer, | ||
| 106 | "width" character varying(8), | ||
| 107 | "bgcolor" character varying(12), | ||
| 108 | "weekdaycolor" character varying(12), | ||
| 109 | "weekendcolor" character varying(12), | ||
| 110 | "todaycolor" character varying(12), | ||
| 111 | "weekdaybordercolor" character varying(12), | ||
| 112 | "weekendbordercolor" character varying(12), | ||
| 113 | "todaybordercolor" character varying(12), | ||
| 114 | "contentcolor" character varying(12), | ||
| 115 | "weekdaycontentcolor" character varying(12), | ||
| 116 | "weekendcontentcolor" character varying(12), | ||
| 117 | "todaycontentcolor" character varying(12), | ||
| 118 | "headercolor" character varying(12), | ||
| 119 | "weekdayheadercolor" character varying(12), | ||
| 120 | "weekendheadercolor" character varying(12), | ||
| 121 | "header" character varying(64), | ||
| 122 | "cellalignment" character varying(12), | ||
| 123 | "bordercolor" character varying(12), | ||
| 124 | Constraint "calendar_pkey" Primary Key ("calendarid") | ||
| 125 | ); | ||
| 126 | |||
| 127 | -- | ||
| 128 | -- TOC Entry ID 6 (OID 19030) | ||
| 129 | -- | ||
| 130 | -- Name: event_eventid_seq Type: SEQUENCE Owner: '.$dbuser.' | ||
| 131 | -- | ||
| 132 | |||
| 133 | CREATE SEQUENCE "event_eventid_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 ; | ||
| 134 | |||
| 135 | -- | ||
| 136 | -- TOC Entry ID 10 (OID 19049) | ||
| 137 | -- | ||
| 138 | -- Name: event Type: TABLE Owner: '.$dbuser.' | ||
| 139 | -- | ||
| 140 | |||
| 141 | CREATE TABLE "event" ( | ||
| 142 | "eventid" integer DEFAULT nextval(\'"event_eventid_seq"\'::text) NOT NULL, | ||
| 143 | "eventtime" time, | ||
| 144 | "calendarid" integer, | ||
| 145 | "eventday" integer NOT NULL, | ||
| 146 | "eventmonth" integer NOT NULL, | ||
| 147 | "eventyear" integer NOT NULL, | ||
| 148 | "eventname" character varying(128) NOT NULL, | ||
| 149 | "eventdesc" text, | ||
| 150 | "eventlink" character varying(128), | ||
| 151 | Constraint "event_pkey" Primary Key ("eventid") | ||
| 152 | ); | ||
| 153 | |||
| 154 | -- | ||
| 155 | -- Data for TOC Entry ID 11 (OID 18870) | ||
| 156 | -- | ||
| 157 | -- Name: client Type: TABLE DATA Owner: '.$dbuser.' | ||
| 158 | -- | ||
| 159 | |||
| 160 | |||
| 161 | COPY "client" FROM stdin; | ||
| 162 | 1 '.$clientname.' | ||
| 163 | \. | ||
| 164 | -- | ||
| 165 | -- Data for TOC Entry ID 12 (OID 18996) | ||
| 166 | -- | ||
| 167 | -- Name: calendar Type: TABLE DATA Owner: '.$dbuser.' | ||
| 168 | -- | ||
| 169 | |||
| 170 | |||
| 171 | COPY "calendar" FROM stdin; | ||
| 172 | 1 1 '.$calname.' | ||
| 173 | \. | ||
| 174 | -- | ||
| 175 | -- TOC Entry ID 3 (OID 18851) | ||
| 176 | -- | ||
| 177 | -- Name: client_clientid_seq Type: SEQUENCE SET Owner: | ||
| 178 | -- | ||
| 179 | |||
| 180 | SELECT setval (\'"client_clientid_seq"\', 1, \'t\'); | ||
| 181 | |||
| 182 | -- | ||
| 183 | -- TOC Entry ID 5 (OID 18977) | ||
| 184 | -- | ||
| 185 | -- Name: calendar_calendarid_seq Type: SEQUENCE SET Owner: | ||
| 186 | -- | ||
| 187 | |||
| 188 | SELECT setval (\'"calendar_calendarid_seq"\', 1, \'t\'); | ||
| 189 | |||
| 190 | -- | ||
| 191 | -- TOC Entry ID 7 (OID 19030) | ||
| 192 | -- | ||
| 193 | -- Name: event_eventid_seq Type: SEQUENCE SET Owner: | ||
| 194 | -- | ||
| 195 | |||
| 196 | SELECT setval (\'"event_eventid_seq"\', 60, \'t\'); | ||
| 197 | '; | ||
| 198 | |||
| 199 | close(FILE); | ||
| 200 | } | ||
| 201 | |||
| 202 | sub getinput { | ||
| 203 | my ($question) = shift; | ||
| 204 | my ($required) = shift; | ||
| 205 | my($var) = ''; | ||
| 206 | if ($required) { | ||
| 207 | while ($var eq '') { | ||
| 208 | print $question; | ||
| 209 | $var=<STDIN>; | ||
| 210 | chop($var); | ||
| 211 | } | ||
| 212 | } | ||
| 213 | else { | ||
| 214 | print $question; | ||
| 215 | $var=<STDIN>; | ||
| 216 | chop($var); | ||
| 217 | } | ||
| 218 | return $var; | ||
| 219 | } |