Last active
May 22, 2018 10:25
-
-
Save blankdots/d848b737cd62d7c6d6209ac3ab58747f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script works in both MacOS and Linux | |
.PHONY: upload submit user | |
SHELL := /bin/bash | |
DOCKER_PATH=$(shell pwd) | |
#GPG_EXEC=/usr/local/gnupg-2.2/bin/gpg2 | |
GPG_EXEC=/usr/bin/gpg2 | |
SSH_KEY_PUB=~/.ssh/dummy.key.pub | |
SSH_KEY_PRIV=~/.ssh/dummy.key | |
INSTANCE=fin | |
INSTANCE_PORT=$(shell awk -F= '/DOCKER_PORT_inbox/ {print $$2}' $(DOCKER_PATH)/bootstrap/settings) | |
GPG_HOME=$(DOCKER_PATH)/images/keyserver/gpg | |
PGP_PUB=$(DOCKER_PATH)/images/keyserver/pgp/ega.pub | |
PGP_EMAIL=$(shell awk -F= '/PGP_EMAIL/ {print $$2 }' $(DOCKER_PATH)/bootstrap/settings | tr -d ' ' ) | |
CEGA_USERS=$(DOCKER_PATH)/images/cega/users | |
CEGA_MQ_PASSWORD=$(shell awk -F= '/CEGA_MQ_PASSWORD/ {print $$2}' $(DOCKER_PATH)/compose/.trace | tr -d ' ') | |
CEGA_MQ_CONNECTION=amqp://cega_$(INSTANCE):$(CEGA_MQ_PASSWORD)@localhost:5672/$(INSTANCE) | |
OSNAME=$(shell uname -s) | |
# generate a RANDOM # change with whatever | |
STABLE_ID=1245 | |
############################## | |
USER=mysuer | |
#the user used for file encryption and file uploading | |
USER0=john | |
SSH_KEY_PRIV0=$(DOCKER_PATH)/images/cega/users/john.sec | |
all: user upload submit | |
dir/file.gpg: org | |
@mkdir -p dir $(GPG_HOME) | |
$(GPG_EXEC) --homedir $(GPG_HOME) --import $(PGP_PUB) | |
$(GPG_EXEC) --homedir $(GPG_HOME) --cipher-algo AES256 --compress-algo 0 -r $(PGP_EMAIL) -e -o $@ $< | |
upload: user dir/file.gpg dir/file.gpg.md5 dir/file.md5 | |
sftp -P $(INSTANCE_PORT) -i $(SSH_KEY_PRIV0) $(USER0)@localhost <<< $$'put -r dir' | |
dir/file.gpg.md5: dir/file.gpg | |
ifeq ($(OSNAME),Linux) | |
printf '%s' $(shell md5sum $< | cut -d' ' -f1) > $@ | |
else | |
printf '%s' $(shell md5 -q $< ) > $@ | |
endif | |
dir/file.md5: org | |
ifeq ($(OSNAME),Linux) | |
printf '%s' $(shell md5sum $< | cut -d' ' -f1) > $@ | |
else | |
printf '%s' $(shell md5 -q $< ) > $@ | |
endif | |
submit: org dir/file.gpg dir/file.gpg.md5 dir/file.md5 | |
@echo publish.py --connection $(CEGA_MQ_CONNECTION) $(USER0) dir/file.gpg $(STABLE_ID) --unenc ... --enc ... | |
@python $(DOCKER_PATH)/../../../extras/publish.py --connection $(subst cega-mq,localhost,$(CEGA_MQ_CONNECTION)) $(USER0) dir/file.gpg $(STABLE_ID) --unenc $(shell cat dir/file.md5) --enc $(shell cat dir/file.gpg.md5) | |
user: $(CEGA_USERS)/fin/$(USER).yml | |
$(CEGA_USERS)/fin/$(USER).yml: $(CEGA_USERS)/$(USER).yml | |
-cd $(CEGA_USERS)/fin && ln -s ../$(USER).yml . | |
$(CEGA_USERS)/$(USER).yml: | |
@echo --- > $@ | |
@echo "pubkey: $(shell cat $(SSH_KEY_PUB))" >> $@ | |
clean: | |
-unlink $(CEGA_USERS)/fin/$(USER).yml | |
rm -rf dir $(GPG_HOME) $(CEGA_USERS)/$(USER).yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment