mirror of
https://git.fsfe.org/FSFE/fsfe-local-build.git
synced 2026-04-14 16:47:38 +02:00
adding option to use python simplehttp webserver module which doesn't require users to install lighttpd
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
config.cfg
|
||||
lighttpd-fsfe.conf
|
||||
pywebserver-fsfe.log
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# FSFE Local Build
|
||||
|
||||
FUll instructions can be found in an extensive blog post: https://blog.mehl.mx/2016/build-fsfe-websites-locally/
|
||||
This is a collection of scripts and configuration files necessary to build fsfe.org websites locally.
|
||||
|
||||
Full instructions can be found in an extensive blog post: https://blog.mehl.mx/2016/build-fsfe-websites-locally/
|
||||
|
||||
@@ -1,13 +1,29 @@
|
||||
### BUILD DIRECTORIES ###
|
||||
|
||||
# SVN trunk directory (repository with XHTML source files)
|
||||
LOC_trunk=~/subversion/fsfe/fsfe-web/trunk
|
||||
|
||||
# Directory in which the result of the build process (html files) will be saved
|
||||
LOC_out=~/subversion/fsfe/local-build/fsfe.org
|
||||
|
||||
# Path to lighttpd config file (default: points to a file in the same directory as the script)
|
||||
HTTPD_conf=$ROOT/lighttpd-fsfe.conf
|
||||
|
||||
# Directory of the secondary SVN directory with which you made a first full build.
|
||||
# Avoids having some generated files in your clean trunk.
|
||||
# Default: Leave empty if you just want to use one SVN source directory
|
||||
# Default: Leave empty if you just want to use one SVN source directory (recommended)
|
||||
LOC_trunk_dev=
|
||||
|
||||
|
||||
### LOCAL WEBSERVER ###
|
||||
|
||||
# Choose your local webserver.
|
||||
# Default is "python" which is python's inbuilt http server that is available on most distributions
|
||||
# Use "lighttpd" if you want to use the Lighttpd webserver. This has to be configured manually (see guide)
|
||||
HTTPD=python
|
||||
|
||||
# Choose on which port the webserver runs. This has no effect for "lighttpd".
|
||||
HTTPD_port=5080
|
||||
|
||||
# If you use other webservers like "lighttpd", this is the path to its config file
|
||||
# Default: points to a lighttpd config file in the same directory as the script
|
||||
# Has no effect if you use the "python" webserver
|
||||
HTTPD_conf=$ROOT/lighttpd-fsfe.conf
|
||||
|
||||
|
||||
@@ -110,11 +110,25 @@ fi
|
||||
|
||||
|
||||
### START WEBSERVER if necessary
|
||||
if [ ! $(pgrep lighttpd) ]; then
|
||||
echo "[INFO] Starting webserver"
|
||||
/usr/sbin/lighttpd -f $HTTPD_conf
|
||||
else
|
||||
echo "[INFO] Webserver already seems to be running."
|
||||
if [ "$HTTPD" == "python" ]; then # python
|
||||
if [ ! $(pgrep -f "pywebserver-fsfe.py $LOC_out") ]; then
|
||||
echo "[INFO] Starting $HTTPD webserver"
|
||||
nohup "$ROOT/pywebserver-fsfe.py" "$LOC_out" "$HTTPD_port" > "$ROOT"/pywebserver-fsfe.log 2>&1 &
|
||||
else
|
||||
echo "[INFO] $HTTPD webserver already seems to be running."
|
||||
fi
|
||||
elif [ "$HTTPD" == "lighttpd" ]; then
|
||||
if [ ! $(pgrep lighttpd) ]; then # lighttpd
|
||||
echo "[INFO] Starting $HTTPD webserver"
|
||||
/usr/sbin/lighttpd -f "$HTTPD_conf"
|
||||
else
|
||||
echo "[INFO] $HTTPD webserver already seems to be running."
|
||||
fi
|
||||
elif [ "$HTTPD" == "" ]; then # empty variable
|
||||
echo "[ERROR] No webserver specified. Please define variable HTTPD in config.cfg. Aborting now."
|
||||
exit 1
|
||||
else # something custom
|
||||
echo "[WARNING] Unknown webserver defined. Please check variable HTTPD in config.cfg."
|
||||
fi
|
||||
|
||||
### SHOW RESULTS
|
||||
|
||||
15
pywebserver-fsfe.py
Executable file
15
pywebserver-fsfe.py
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import http.server
|
||||
import socketserver
|
||||
import os
|
||||
import sys
|
||||
|
||||
WEB_DIR = sys.argv[1]
|
||||
WEB_PORT = int(sys.argv[2])
|
||||
|
||||
os.chdir(WEB_DIR)
|
||||
|
||||
Handler = http.server.SimpleHTTPRequestHandler
|
||||
httpd = socketserver.TCPServer(("", WEB_PORT), Handler)
|
||||
httpd.serve_forever()
|
||||
Reference in New Issue
Block a user