Compare commits

..

No commits in common. "9472f995a0d61415bdab9c4ad9249b67b3893054" and "31dbf3acd23d890813e59dc539c0d76faee889fe" have entirely different histories.

3 changed files with 25 additions and 41 deletions

View File

@ -18,7 +18,6 @@ readConfig
SOFTWARE=( SOFTWARE=(
make make
w3m links w3m links
tree
qrencode qrencode
htop iftop iotop htop iftop iotop
tmux tmux

View File

@ -100,13 +100,16 @@ echo "# Copying assets..."
@ pct-push-r $ID ./assets / @ pct-push-r $ID ./assets /
@ lxc-attach $ID -- chmod +x /root/getFreeClientIP @ lxc-attach $ID -- chmod +x /root/getFreeClientIP
echo "# Setup: wireguard server and client profile..." #echo "# Setup: wireguard server..."
@ lxc-attach $ID -- bash -c "cd /root \ @ lxc-attach $ID -- bash -c "cd /root && make server"
&& QRCODE=${QRCODE} make server default.client"
#echo "# client config:" echo "# Setup: wireguard default profile..."
#@ mkdir -p clients @ lxc-attach $ID -- bash -c "cd /root \
#@ pct pull $ID /etc/wireguard/clients/default.wg clients/default.conf && QRCODE=${QRCODE} make default.client"
echo "# client config:"
@ mkdir -p clients
@ pct pull $ID /etc/wireguard/clients/default.conf clients/default.conf
echo "# Post config..." echo "# Post config..."
pctSet $ID "${OPTS_STAGE_2}" $REBOOT pctSet $ID "${OPTS_STAGE_2}" $REBOOT

View File

@ -1,6 +1,3 @@
#----------------------------------------------------------------------
#
#----------------------------------------------------------------------
INTERFACE := wg0 INTERFACE := wg0
@ -24,8 +21,6 @@ ALLOWED_IPS ?= ${ALLOWED_IPS}
#----------------------------------------------------------------------
%_id: %_id:
@ mkdir -p $$(dirname $@) @ mkdir -p $$(dirname $@)
wg genkey 2> /dev/null > $@ wg genkey 2> /dev/null > $@
@ -36,10 +31,6 @@ ALLOWED_IPS ?= ${ALLOWED_IPS}
cat $< | wg pubkey > $@ cat $< | wg pubkey > $@
%_ip:
./getFreeClientIP > $@
# NOTE: the first letter of each pattern is quoted to prevent it from # NOTE: the first letter of each pattern is quoted to prevent it from
# being substituted when generating this Makefile from template. # being substituted when generating this Makefile from template.
$(SERVER_CONF): $(SERVER_TPL) $(SERVER_KEY) $(SERVER_CONF): $(SERVER_TPL) $(SERVER_KEY)
@ -53,55 +44,46 @@ $(SERVER_CONF): $(SERVER_TPL) $(SERVER_KEY)
wg-quick up $(INTERFACE) wg-quick up $(INTERFACE)
.PRECIOUS: %.wg # XXX need to figure out a way to link this to the .config file without
%.wg: $(CLIENT_TPL) $(SERVER_CLIENT_TPL) \ # conflicting with the server's wg0.conf
%_id %_id.pub %_ip \ %.client: $(CLIENT_TPL) $(SERVER_CLIENT_TPL) \
$(CLIENT_DIR)/%_id $(CLIENT_DIR)/%_id.pub \
$(SERVER_CONF) $(SERVER_PUBLIC_KEY) $(SERVER_CONF) $(SERVER_PUBLIC_KEY)
@ mkdir -p $(shell dirname "$*") @ mkdir -p $(CLIENT_DIR)
cat "$<" \ cat "$<" \
| sed \ | sed \
-e 's/\$${\DNS}/$(DNS)/g' \ -e 's/\$${\DNS}/$(DNS)/g' \
-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \ -e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \ -e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
-e 's/\$${\ALLOWED_IPS}/$(subst /,\/,$(ALLOWED_IPS))/g' \ -e 's/\$${\ALLOWED_IPS}/$(subst /,\/,$(ALLOWED_IPS))/g' \
-e 's/\$${\CLIENT_IP}/$(shell cat $*_ip)\/32/g' \ -e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/32/g' \
-e 's/\$${\CLIENT_PRIVATE_KEY}/$(shell sed -e 's/\//\\\//g' "$*_id")/g' \ -e 's/\$${\CLIENT_PRIVATE_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id")'/g' \
-e 's/\$${\SERVER_PUBLIC_KEY}/$(shell sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")/g' \ -e 's/\$${\SERVER_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")'/g' \
> "$@" > "$(CLIENT_DIR)/$*.conf"
cat "$(SERVER_CLIENT_TPL)" \ cat "$(SERVER_CLIENT_TPL)" \
| sed \ | sed \
-e 's/\$${\CLIENT_IP}/$(shell cat $*_ip)\/32/g' \ -e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/32/g' \
-e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \ -e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \
-e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \ -e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \
-e 's/\$${\CLIENT_PUBLIC_KEY}/$(shell sed -e 's/\//\\\//g' "$*_id.pub")/g' \ -e 's/\$${\CLIENT_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id.pub")'/g' \
-e 's/\$${\SERVER_PUBLIC_KEY}/$(shell sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")/g' \ -e 's/\$${\SERVER_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")'/g' \
>> "$(SERVER_CONF)" >> "$(SERVER_CONF)"
make update $*.show
.PHONY: %.show %.show: $(CLIENT_DIR)/%.conf
%.show: %.wg
@ [ "$(QRCODE)" == "1" ] \ @ [ "$(QRCODE)" == "1" ] \
&& ( echo "# Profile: $*" \ && ( echo "# Profile: $*" \
&& qrencode -t UTF8 -r "$<" ) && qrencode -t UTF8 -r "$(CLIENT_DIR)/$*.conf" )
@ cat "$<" @ cat "$(CLIENT_DIR)/$*.conf"
@ echo @ echo
.PHONY: %.client
%.client: $(CLIENT_DIR)/%.wg update $(CLIENT_DIR)/%.show
@
#----------------------------------------------------------------------
.PHONY: update
update: update:
wg syncconf $(INTERFACE) <(wg-quick strip $(INTERFACE)) wg syncconf $(INTERFACE) <(wg-quick strip $(INTERFACE))
.PHONY: server
server: $(SERVER_CONF) server: $(SERVER_CONF)
#----------------------------------------------------------------------