]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: add 'strip' subcommand
authorLuis Ressel <aranea@aixah.de>
Wed, 13 Mar 2019 23:36:22 +0000 (00:36 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sat, 23 Mar 2019 11:49:48 +0000 (12:49 +0100)
`wg-quick strip` prints the config file to stdout after stripping it of
all wg-quick-specific options.

This enables tricks such as `wg addconf $DEV <(wg-quick strip $DEV)`.

Signed-off-by: Luis Ressel <aranea@aixah.de>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/man/wg-quick.8
src/wg-quick/darwin.bash
src/wg-quick/freebsd.bash
src/wg-quick/linux.bash
src/wg-quick/openbsd.bash

index 00d7dbac2b43111a7bad8a2707dd9e1addb62753..6250adc0b3bc09b15d3b12c14ce80337fe5f7cdd 100644 (file)
@@ -11,6 +11,8 @@ wg-quick - set up a WireGuard interface simply
 .I down
 |
 .I save
+|
+.I strip
 ] [
 .I CONFIG_FILE
 |
@@ -27,7 +29,11 @@ an interface. Running \fIup\fP adds a WireGuard interface, brings up the interfa
 supplied IP addresses, sets up mtu and routes, and optionally runs pre/post up scripts. Running \fIdown\fP
 optionally saves the current configuration, removes the WireGuard interface, and optionally
 runs pre/post down scripts. Running \fIsave\fP saves the configuration of an existing
-interface without bringing the interface down.
+interface without bringing the interface down. Use \fIstrip\fP to output a configuration file
+with all
+.BR wg-quick (8)-specific
+options removed, suitable for use with
+.BR wg (8).
 
 \fICONFIG_FILE\fP is a configuration file, whose filename is the interface name
 followed by `.conf'. Otherwise, \fIINTERFACE\fP is an interface name, with configuration
@@ -243,6 +249,13 @@ For convenience, if only an interface name is supplied, it automatically chooses
 
 This will load the configuration file `/etc/wireguard/wgnet0.conf'.
 
+The \fIstrip\fP command is useful for reloading configuration files without disrupting active
+sessions:
+
+\fB    # wg addconf wgnet0 <(wg-quick strip wgnet0)\fP
+
+(Note that the above command will add and update peers but will not remove peers.)
+
 .SH SEE ALSO
 .BR wg (8),
 .BR ip (8),
index bf07fdb13265012a148b2c7b96558399a8e9ff52..aa3edeb9ac0400d0d2bf55b0f280b4dc1b957b23 100755 (executable)
@@ -385,7 +385,7 @@ execute_hooks() {
 
 cmd_usage() {
        cat >&2 <<-_EOF
-       Usage: $PROGRAM [ up | down | save ] [ CONFIG_FILE | INTERFACE ]
+       Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
 
          CONFIG_FILE is a configuration file, whose filename is the interface name
          followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -452,6 +452,10 @@ cmd_save() {
        save_config
 }
 
+cmd_strip() {
+       echo "$WG_CONFIG"
+}
+
 # ~~ function override insertion point ~~
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
@@ -468,6 +472,10 @@ elif [[ $# -eq 2 && $1 == save ]]; then
        auto_su
        parse_options "$2"
        cmd_save
+elif [[ $# -eq 2 && $1 == strip ]]; then
+       auto_su
+       parse_options "$2"
+       cmd_strip
 else
        cmd_usage
        exit 1
index c3fa47a5c8f9c4ebb5d22ac4dbf907cfd8226a03..9d3a40260e793d3905cb0cbec6c89bf625eda824 100755 (executable)
@@ -368,7 +368,7 @@ execute_hooks() {
 
 cmd_usage() {
        cat >&2 <<-_EOF
-       Usage: $PROGRAM [ up | down | save ] [ CONFIG_FILE | INTERFACE ]
+       Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
 
          CONFIG_FILE is a configuration file, whose filename is the interface name
          followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -431,6 +431,10 @@ cmd_save() {
        save_config
 }
 
+cmd_strip() {
+       echo "$WG_CONFIG"
+}
+
 # ~~ function override insertion point ~~
 
 make_temp
@@ -450,6 +454,10 @@ elif [[ $# -eq 2 && $1 == save ]]; then
        auto_su
        parse_options "$2"
        cmd_save
+elif [[ $# -eq 2 && $1 == strip ]]; then
+       auto_su
+       parse_options "$2"
+       cmd_strip
 else
        cmd_usage
        exit 1
index 84643c4d4ebed90f5eef107058830ccc4a5bb293..5eaa5042aabde8bc60d388cfd8e45aaec9b58e9a 100755 (executable)
@@ -247,7 +247,7 @@ execute_hooks() {
 
 cmd_usage() {
        cat >&2 <<-_EOF
-       Usage: $PROGRAM [ up | down | save ] [ CONFIG_FILE | INTERFACE ]
+       Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
 
          CONFIG_FILE is a configuration file, whose filename is the interface name
          followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -305,6 +305,10 @@ cmd_save() {
        save_config
 }
 
+cmd_strip() {
+       echo "$WG_CONFIG"
+}
+
 # ~~ function override insertion point ~~
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
@@ -321,6 +325,10 @@ elif [[ $# -eq 2 && $1 == save ]]; then
        auto_su
        parse_options "$2"
        cmd_save
+elif [[ $# -eq 2 && $1 == strip ]]; then
+       auto_su
+       parse_options "$2"
+       cmd_strip
 else
        cmd_usage
        exit 1
index 99961627ee9760d37316c3d82b590457745a353f..b2346097ce2adcd782e5877b943d27b0197dbcf8 100755 (executable)
@@ -361,7 +361,7 @@ execute_hooks() {
 
 cmd_usage() {
        cat >&2 <<-_EOF
-       Usage: $PROGRAM [ up | down | save ] [ CONFIG_FILE | INTERFACE ]
+       Usage: $PROGRAM [ up | down | save | strip ] [ CONFIG_FILE | INTERFACE ]
 
          CONFIG_FILE is a configuration file, whose filename is the interface name
          followed by \`.conf'. Otherwise, INTERFACE is an interface name, with
@@ -426,6 +426,10 @@ cmd_save() {
        save_config
 }
 
+cmd_strip() {
+       echo "$WG_CONFIG"
+}
+
 # ~~ function override insertion point ~~
 
 if [[ $# -eq 1 && ( $1 == --help || $1 == -h || $1 == help ) ]]; then
@@ -442,6 +446,10 @@ elif [[ $# -eq 2 && $1 == save ]]; then
        auto_su
        parse_options "$2"
        cmd_save
+elif [[ $# -eq 2 && $1 == strip ]]; then
+       auto_su
+       parse_options "$2"
+       cmd_strip
 else
        cmd_usage
        exit 1