Luigi Santivetti | d93cb0f | 2020-02-17 22:21:28 +0000 | [diff] [blame^] | 1 | PY?=python3 |
| 2 | PELICAN?=pelican |
| 3 | PELICANOPTS= |
| 4 | |
| 5 | BASEDIR=$(CURDIR) |
| 6 | INPUTDIR=$(BASEDIR)/content |
| 7 | OUTPUTDIR=$(BASEDIR)/output |
| 8 | CONFFILE=$(BASEDIR)/pelicanconf.py |
| 9 | PUBLISHCONF=$(BASEDIR)/publishconf.py |
| 10 | |
| 11 | FTP_HOST=localhost |
| 12 | FTP_USER=anonymous |
| 13 | FTP_TARGET_DIR=/ |
| 14 | |
| 15 | SSH_HOST=localhost |
| 16 | SSH_PORT=22 |
| 17 | SSH_USER=root |
| 18 | SSH_TARGET_DIR=/var/www |
| 19 | |
| 20 | S3_BUCKET=my_s3_bucket |
| 21 | |
| 22 | CLOUDFILES_USERNAME=my_rackspace_username |
| 23 | CLOUDFILES_API_KEY=my_rackspace_api_key |
| 24 | CLOUDFILES_CONTAINER=my_cloudfiles_container |
| 25 | |
| 26 | DROPBOX_DIR=~/Dropbox/Public/ |
| 27 | |
| 28 | GITHUB_PAGES_BRANCH=gh-pages |
| 29 | |
| 30 | INSTALLDIR= |
| 31 | UID="www-data" |
| 32 | GID="www-data" |
| 33 | MOD="664" |
| 34 | |
| 35 | DEBUG ?= 0 |
| 36 | ifeq ($(DEBUG), 1) |
| 37 | PELICANOPTS += -D |
| 38 | endif |
| 39 | |
| 40 | RELATIVE ?= 0 |
| 41 | ifeq ($(RELATIVE), 1) |
| 42 | PELICANOPTS += --relative-urls |
| 43 | endif |
| 44 | |
| 45 | help: |
| 46 | @echo 'Makefile for a pelican Web site ' |
| 47 | @echo ' ' |
| 48 | @echo 'Usage: ' |
| 49 | @echo ' make html (re)generate the web site ' |
| 50 | @echo ' make clean remove the generated files ' |
| 51 | @echo ' make regenerate regenerate files upon modification ' |
| 52 | @echo ' make publish generate using production settings ' |
| 53 | @echo ' make serve [PORT=8000] serve site at http://localhost:8000' |
| 54 | @echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 ' |
| 55 | @echo ' make devserver [PORT=8000] start/restart develop_server.sh ' |
| 56 | @echo ' make stopserver stop local server ' |
| 57 | @echo ' make ssh_upload upload the web site via SSH ' |
| 58 | @echo ' make rsync_upload upload the web site via rsync+ssh ' |
| 59 | @echo ' make dropbox_upload upload the web site via Dropbox ' |
| 60 | @echo ' make ftp_upload upload the web site via FTP ' |
| 61 | @echo ' make s3_upload upload the web site via S3 ' |
| 62 | @echo ' make cf_upload upload the web site via Cloud Files' |
| 63 | @echo ' make github upload the web site via gh-pages ' |
| 64 | @echo ' ' |
| 65 | @echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html ' |
| 66 | @echo 'Set the RELATIVE variable to 1 to enable relative urls ' |
| 67 | @echo ' ' |
| 68 | |
| 69 | html: |
| 70 | $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) |
| 71 | |
| 72 | clean: |
| 73 | [ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR) |
| 74 | |
| 75 | regenerate: |
| 76 | $(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) |
| 77 | |
| 78 | serve: |
| 79 | ifdef PORT |
| 80 | cd $(OUTPUTDIR) && $(PY) -m pelican.server $(PORT) |
| 81 | else |
| 82 | cd $(OUTPUTDIR) && $(PY) -m pelican.server |
| 83 | endif |
| 84 | |
| 85 | serve-global: |
| 86 | ifdef SERVER |
| 87 | cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 $(SERVER) |
| 88 | else |
| 89 | cd $(OUTPUTDIR) && $(PY) -m pelican.server 80 0.0.0.0 |
| 90 | endif |
| 91 | |
| 92 | |
| 93 | devserver: |
| 94 | ifdef PORT |
| 95 | $(BASEDIR)/develop_server.sh restart $(PORT) |
| 96 | else |
| 97 | $(BASEDIR)/develop_server.sh restart |
| 98 | endif |
| 99 | |
| 100 | stopserver: |
| 101 | $(BASEDIR)/develop_server.sh stop |
| 102 | @echo 'Stopped Pelican and SimpleHTTPServer processes running in background.' |
| 103 | |
| 104 | publish: |
| 105 | $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS) |
| 106 | |
| 107 | ssh_upload: publish |
| 108 | scp -P $(SSH_PORT) -r $(OUTPUTDIR)/* $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) |
| 109 | |
| 110 | rsync_upload: publish |
| 111 | rsync -e "ssh -p $(SSH_PORT)" -P -rvzc --delete $(OUTPUTDIR)/ $(SSH_USER)@$(SSH_HOST):$(SSH_TARGET_DIR) --cvs-exclude |
| 112 | |
| 113 | dropbox_upload: publish |
| 114 | cp -r $(OUTPUTDIR)/* $(DROPBOX_DIR) |
| 115 | |
| 116 | ftp_upload: publish |
| 117 | lftp ftp://$(FTP_USER)@$(FTP_HOST) -e "mirror -R $(OUTPUTDIR) $(FTP_TARGET_DIR) ; quit" |
| 118 | |
| 119 | s3_upload: publish |
| 120 | s3cmd sync $(OUTPUTDIR)/ s3://$(S3_BUCKET) --acl-public --delete-removed --guess-mime-type --no-mime-magic --no-preserve |
| 121 | |
| 122 | cf_upload: publish |
| 123 | cd $(OUTPUTDIR) && swift -v -A https://auth.api.rackspacecloud.com/v1.0 -U $(CLOUDFILES_USERNAME) -K $(CLOUDFILES_API_KEY) upload -c $(CLOUDFILES_CONTAINER) . |
| 124 | |
| 125 | github: publish |
| 126 | ghp-import -m "Generate Pelican site" -b $(GITHUB_PAGES_BRANCH) $(OUTPUTDIR) |
| 127 | git push origin $(GITHUB_PAGES_BRANCH) |
| 128 | |
| 129 | install: |
| 130 | @command [ -z "$(INSTALLDIR)" ] && echo "INSTALLDIR unset. i.e. make install INSTALLDIR=\"/path/to/dir\"" && exit 1 ||: |
| 131 | @command [ ! -d $(OUTPUTDIR) ] && echo "OUTPUTDIR unset. i.e. make html" && exit 1 ||: |
| 132 | @echo "Copying $(OUTPUTDIR) to $(INSTALLDIR)" |
| 133 | @command sudo cp -ra $(OUTPUTDIR)/* $(INSTALLDIR) ||: |
| 134 | @echo "Setting chown to $(UID):$(GID)" |
| 135 | @command sudo chown -R $(UID):$(GID) $(INSTALLDIR) ||: |
| 136 | @echo "Setting chmod $(MOD) to files" |
| 137 | @command find $(INSTALLDIR) -type f | sudo xargs -i{} chmod $(MOD) {} ||: |
| 138 | @echo "Installed files:" |
| 139 | @command find $(INSTALLDIR) -type f ||: |
| 140 | @echo "Done." |
| 141 | |
| 142 | |
| 143 | .PHONY: html help clean regenerate serve serve-global devserver stopserver publish ssh_upload rsync_upload dropbox_upload ftp_upload s3_upload cf_upload github install |