Skip to content

Instantly share code, notes, and snippets.

@maemichi-monosense
Created July 27, 2016 03:52
Show Gist options
  • Save maemichi-monosense/89cae307c287ef9a42d8b94a23b1cf06 to your computer and use it in GitHub Desktop.
Save maemichi-monosense/89cae307c287ef9a42d8b94a23b1cf06 to your computer and use it in GitHub Desktop.
SSH/Config Makefile
CP := cp -p
CONFIG_FILES := $(wildcard conf.d/*.conf)
SSH_DIR := $(HOME)/.ssh
define USAGE
Usage:
it make ~/.ssh/{config, keylist.txt}
usage show this
help same as usage
update git update
list list all conf.d/*.conf
config generate config from conf.d/*.conf
keylist show keylist from keylist.txt
deploy deploy config and keylist.txt to ~/.ssh/
clean remove config
endef
export USAGE
# failsafe
.PHONY: help usage
help usage:
@echo "$$USAGE" | \
column -t -s $$'\t'
.PHONY: it
it: config deploy clean;
.PHONY: list
list: $(CONFIG_FILES)
@echo $^ | \
xargs -n 1 echo
.PHONY: update
update:
git fetch --prune
git pull origin master
config: $(CONFIG_FILES)
echo "# -*- ssh-config -*-" | \
cat - $^ \
> $@
keylist: keylist.txt
grep -v '^#' $^
.PHONY: deploy
deploy: config keylist.txt
$(CP) config $(SSH_DIR)
$(CP) keylist.txt $(SSH_DIR)
.PHONY: clean
clean:
# rm -f config
define SHQX
perl -p -i -e 's/^# \$sh\((.*)\)$/ join "\n", qx{$1} /e' $1
endef
define STRIP
grep -E -v '^(# -\*-|//)' $1
endef
@maemichi-monosense
Copy link
Author

maemichi-monosense commented Dec 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment