2022-12-18 23:20:11 +01:00
|
|
|
# any HTTP request returns the contents of: ./lib/deploy.sh
|
|
|
|
# If the deploy script is older then a day, do a git pull
|
|
|
|
|
|
|
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
|
|
|
class handler(BaseHTTPRequestHandler):
|
|
|
|
def do_GET(self):
|
|
|
|
self.send_response(200)
|
|
|
|
self.send_header('Content-type','text/plain')
|
|
|
|
self.end_headers()
|
2022-12-18 23:46:56 +01:00
|
|
|
if (time.time() - os.path.getmtime('./lib/deploy.sh') > 86400) or self.path == '/pull':
|
2022-12-18 23:20:11 +01:00
|
|
|
subprocess.call(['git', 'pull'])
|
|
|
|
with open('./lib/deploy.sh') as f:
|
|
|
|
self.wfile.write(bytes(f.read(), 'utf-8'))
|
2022-12-18 23:49:48 +01:00
|
|
|
self.wfile.write(bytes("# Git pull: " + str(time.time() - os.path.getmtime('./lib/deploy.sh')) + " seconds ago", 'utf-8'))
|
2022-12-18 23:20:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
server = HTTPServer(('', 80), handler)
|
|
|
|
print('started httpserver...')
|
|
|
|
server.serve_forever()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print('^C received, shutting down the web server')
|
|
|
|
server.socket.close()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|