2 # Charles Roussel <charles.roussel@ensimag.imag.fr>
3 # Simon Cathebras <simon.cathebras@ensimag.imag.fr>
4 # Julien Khayat <julien.khayat@ensimag.imag.fr>
5 # Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
6 # Simon Perrat <simon.perrat@ensimag.imag.fr>
7 # License: GPL v2 or later
10 # CONFIGURATION VARIABLES
11 # You might want to change these ones
17 TEST_OUTPUT_DIRECTORY=$(pwd)
18 TEST_DIRECTORY="$CURR_DIR"/../../../t
20 export TEST_OUTPUT_DIRECTORY TEST_DIRECTORY CURR_DIR
22 if test "$LIGHTTPD" = "false" ; then
25 WIKI_DIR_INST="$CURR_DIR/$WEB_WWW"
28 # ================= Install part =================
37 # Create the configuration files and the folders necessary to start lighttpd.
38 # Overwrite any existing file.
43 cat > $WEB/lighttpd.conf <<EOF
44 server.document-root = "$CURR_DIR/$WEB_WWW"
46 server.pid-file = "$CURR_DIR/$WEB_TMP/pid"
56 index-file.names = ("index.php" , "index.html")
59 ".pdf" => "application/pdf",
60 ".sig" => "application/pgp-signature",
61 ".spl" => "application/futuresplash",
62 ".class" => "application/octet-stream",
63 ".ps" => "application/postscript",
64 ".torrent" => "application/x-bittorrent",
65 ".dvi" => "application/x-dvi",
66 ".gz" => "application/x-gzip",
67 ".pac" => "application/x-ns-proxy-autoconfig",
68 ".swf" => "application/x-shockwave-flash",
69 ".tar.gz" => "application/x-tgz",
70 ".tgz" => "application/x-tgz",
71 ".tar" => "application/x-tar",
72 ".zip" => "application/zip",
73 ".mp3" => "audio/mpeg",
74 ".m3u" => "audio/x-mpegurl",
75 ".wma" => "audio/x-ms-wma",
76 ".wax" => "audio/x-ms-wax",
77 ".ogg" => "application/ogg",
78 ".wav" => "audio/x-wav",
79 ".gif" => "image/gif",
80 ".jpg" => "image/jpeg",
81 ".jpeg" => "image/jpeg",
82 ".png" => "image/png",
83 ".xbm" => "image/x-xbitmap",
84 ".xpm" => "image/x-xpixmap",
85 ".xwd" => "image/x-xwindowdump",
87 ".html" => "text/html",
88 ".htm" => "text/html",
89 ".js" => "text/javascript",
90 ".asc" => "text/plain",
92 ".cpp" => "text/plain",
93 ".log" => "text/plain",
94 ".conf" => "text/plain",
95 ".text" => "text/plain",
96 ".txt" => "text/plain",
99 ".mpeg" => "video/mpeg",
100 ".mpg" => "video/mpeg",
101 ".mov" => "video/quicktime",
102 ".qt" => "video/quicktime",
103 ".avi" => "video/x-msvideo",
104 ".asf" => "video/x-ms-asf",
105 ".asx" => "video/x-ms-asf",
106 ".wmv" => "video/x-ms-wmv",
107 ".bz2" => "application/x-bzip",
108 ".tbz" => "application/x-bzip-compressed-tar",
109 ".tar.bz2" => "application/x-bzip-compressed-tar",
113 fastcgi.server = ( ".php" =>
115 ( "socket" => "$CURR_DIR/$WEB_TMP/php.socket",
116 "bin-path" => "$PHP_DIR/php-cgi -c $CURR_DIR/$WEB/php.ini"
123 cat > $WEB/php.ini <<EOF
124 session.save_path ='$CURR_DIR/$WEB_TMP'
130 # Start or restart daemon lighttpd. If restart, rewrite configuration files.
132 if test -f "$WEB_TMP/pid"; then
133 echo "Instance already running. Restarting..."
137 "$LIGHTTPD_DIR"/lighttpd -f "$WEB"/lighttpd.conf
139 if test $? -ne 0 ; then
140 echo "Could not execute http deamon lighttpd"
147 # Kill daemon lighttpd and removes files and folders associated.
149 test -f "$WEB_TMP/pid" && kill $(cat "$WEB_TMP/pid")
153 # Create the SQLite database of the MediaWiki. If the database file already
154 # exists, it will be deleted.
155 # This script should be runned from the directory where $FILES_FOLDER is
158 rm -f "$TMP/$DB_FILE"
160 echo "Generating the SQLite database file. It can take some time ..."
161 # Run the php script to generate the SQLite database file
163 php "$FILES_FOLDER/$DB_INSTALL_SCRIPT" $(basename "$DB_FILE" .sqlite) \
164 "$WIKI_ADMIN" "$WIKI_PASSW" "$TMP" "$PORT"
166 if [ ! -f "$TMP/$DB_FILE" ] ; then
167 error "Can't create database file $TMP/$DB_FILE. Try to run ./install-wiki.sh delete first."
170 # Copy the generated database file into the directory the
172 cp "$TMP/$DB_FILE" "$FILES_FOLDER" ||
173 error "Unable to copy $TMP/$DB_FILE to $FILES_FOLDER"
176 # Install a wiki in your web server directory.
178 if test $LIGHTTPD = "true" ; then
182 SERVER_ADDR=$SERVER_ADDR:$PORT
183 # In this part, we change directory to $TMP in order to download,
184 # unpack and copy the files of MediaWiki
186 mkdir -p "$WIKI_DIR_INST/$WIKI_DIR_NAME"
187 if [ ! -d "$WIKI_DIR_INST/$WIKI_DIR_NAME" ] ; then
188 error "Folder $WIKI_DIR_INST/$WIKI_DIR_NAME doesn't exist.
189 Please create it and launch the script again."
192 # Fetch MediaWiki's archive if not already present in the TMP directory
194 if [ ! -f "$MW_VERSION.tar.gz" ] ; then
195 echo "Downloading $MW_VERSION sources ..."
196 wget "http://download.wikimedia.org/mediawiki/1.19/mediawiki-1.19.0.tar.gz" ||
197 error "Unable to download "\
198 "http://download.wikimedia.org/mediawiki/1.19/"\
199 "mediawiki-1.19.0.tar.gz. "\
200 "Please fix your connection and launch the script again."
201 echo "$MW_VERSION.tar.gz downloaded in `pwd`. "\
202 "You can delete it later if you want."
204 echo "Reusing existing $MW_VERSION.tar.gz downloaded in `pwd`."
206 archive_abs_path=$(pwd)/"$MW_VERSION.tar.gz"
207 cd "$WIKI_DIR_INST/$WIKI_DIR_NAME/" ||
208 error "can't cd to $WIKI_DIR_INST/$WIKI_DIR_NAME/"
209 tar xzf "$archive_abs_path" --strip-components=1 ||
210 error "Unable to extract WikiMedia's files from $archive_abs_path to "\
211 "$WIKI_DIR_INST/$WIKI_DIR_NAME"
216 # Copy the generic LocalSettings.php in the web server's directory
217 # And modify parameters according to the ones set at the top
219 # Note that LocalSettings.php is never modified.
220 if [ ! -f "$FILES_FOLDER/LocalSettings.php" ] ; then
221 error "Can't find $FILES_FOLDER/LocalSettings.php " \
222 "in the current folder. "\
223 "Please run the script inside its folder."
225 cp "$FILES_FOLDER/LocalSettings.php" \
226 "$FILES_FOLDER/LocalSettings-tmp.php" ||
227 error "Unable to copy $FILES_FOLDER/LocalSettings.php " \
228 "to $FILES_FOLDER/LocalSettings-tmp.php"
230 # Parse and set the LocalSettings file of the user according to the
231 # CONFIGURATION VARIABLES section at the beginning of this script
232 file_swap="$FILES_FOLDER/LocalSettings-swap.php"
233 sed "s,@WG_SCRIPT_PATH@,/$WIKI_DIR_NAME," \
234 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
235 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
236 sed "s,@WG_SERVER@,http://$SERVER_ADDR," \
237 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
238 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
239 sed "s,@WG_SQLITE_DATADIR@,$TMP," \
240 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
241 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
242 sed "s,@WG_SQLITE_DATAFILE@,$( basename $DB_FILE .sqlite)," \
243 "$FILES_FOLDER/LocalSettings-tmp.php" > "$file_swap"
244 mv "$file_swap" "$FILES_FOLDER/LocalSettings-tmp.php"
246 mv "$FILES_FOLDER/LocalSettings-tmp.php" \
247 "$WIKI_DIR_INST/$WIKI_DIR_NAME/LocalSettings.php" ||
248 error "Unable to move $FILES_FOLDER/LocalSettings-tmp.php" \
249 "in $WIKI_DIR_INST/$WIKI_DIR_NAME"
250 echo "File $FILES_FOLDER/LocalSettings.php is set in" \
251 " $WIKI_DIR_INST/$WIKI_DIR_NAME"
253 echo "Your wiki has been installed. You can check it at
254 http://$SERVER_ADDR/$WIKI_DIR_NAME"
257 # Reset the database of the wiki and the password of the admin
259 # Warning: This function must be called only in a subdirectory of t/ directory
261 # Copy initial database of the wiki
262 if [ ! -f "../$FILES_FOLDER/$DB_FILE" ] ; then
263 error "Can't find ../$FILES_FOLDER/$DB_FILE in the current folder."
265 cp "../$FILES_FOLDER/$DB_FILE" "$TMP" ||
266 error "Can't copy ../$FILES_FOLDER/$DB_FILE in $TMP"
267 echo "File $FILES_FOLDER/$DB_FILE is set in $TMP"
270 # Delete the wiki created in the web server's directory and all its content
271 # saved in the database.
273 if test $LIGHTTPD = "true"; then
276 # Delete the wiki's directory.
277 rm -rf "$WIKI_DIR_INST/$WIKI_DIR_NAME" ||
278 error "Wiki's directory $WIKI_DIR_INST/" \
279 "$WIKI_DIR_NAME could not be deleted"
280 # Delete the wiki's SQLite database.
281 rm -f "$TMP/$DB_FILE" ||
282 error "Database $TMP/$DB_FILE could not be deleted."
285 # Delete the wiki's SQLite database
286 rm -f "$TMP/$DB_FILE" || error "Database $TMP/$DB_FILE could not be deleted."
287 rm -f "$FILES_FOLDER/$DB_FILE"
288 rm -rf "$TMP/$MW_VERSION"