From d0ee1baa737fd57a16dd72a452b651c884902a35 Mon Sep 17 00:00:00 2001 From: Eicke Herbertz Date: Wed, 31 Jan 2024 22:46:59 +0100 Subject: [PATCH] Cleanup file mode flags Having to pass "-o-" to get a QR Code was strange, so: make default not dependent on whether output is stdout, make -t without -o imply "-o -" and write to stdout, add -q/--qrcode as alias for "-t qr-utf8". --- wg-setup-client | 24 +++++++++++++++--------- wg-setup-client.sig | Bin 566 -> 565 bytes 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/wg-setup-client b/wg-setup-client index c3d99d1..7551022 100755 --- a/wg-setup-client +++ b/wg-setup-client @@ -35,14 +35,16 @@ Usage: $0 [-fhs] [-d ] [-e ] [-i ] [-n ] [-o -n,--name= Client name on the server instead of \$HOSTNAME, useful for file mode and containers -o,--out-file= File mode: don't configure interface, write configuration to - given file (- for stdout). For networkd files, either .netdev - or .network can be provided and both will be created. + given file. Type is detected or specified with -t. Defaults + to stdout when only -t is provided. For networkd files, either + .netdev or .network can be provided and both will be created. -p,--pubkey= WireGuard public key of the Server + -q,--qrcode Output QR Code to stdout (alias for '-t qr-utf8') -s,--server Create a server configuration (skip peer setup) -t,--type= Type of output for file mode, supported values are: auto (default), wg-quick, networkd, zip, qr-utf8, qr-png - *auto* uses qr-utf8 if out-file is stdout, otherwise tries - to read the file extension and falls back to wg-quick format. + *auto* tries to read the file extension of -o and falls back + to wg-quick format. Write to stdout if -o is not provided. ip-addr ip address for this client port listening port in --server mode EOF @@ -104,8 +106,8 @@ EOF command -v wg >/dev/null || error "wg not found. Please install wireguard-tools first!" -opts=d:e:fhi:n:o:p:st: -lopts=descr:,endpoint:,force,help,iface:,ifname:,name:,out-file:,pubkey:,server,type: +opts=d:e:fhi:n:o:p:qst: +lopts=descr:,endpoint:,force,help,iface:,ifname:,name:,out-file:,pubkey:,qrcode,server,type: parsed_opts=$(getopt -o $opts -l $lopts -n "$0" -- "$@") eval set -- "$parsed_opts" @@ -117,7 +119,7 @@ wg_ifname=wg0 hostname=$HOSTNAME wg_public_key= file_mode= -out_file= +out_file=- out_type=auto create_server= ip_address= @@ -166,11 +168,17 @@ while [[ "$1" != "--" ]]; do wg_public_key="$2" shift 2 ;; + -q|--qrcode) + file_mode=1 + out_type=qr-utf8 + shift + ;; -s|--server) create_server=yes shift ;; -t|--type) + file_mode=1 out_type="$2" shift 2 ;; @@ -254,8 +262,6 @@ if [[ "$backend" == "auto" ]]; then backend=none if [[ "$out_type" == "auto" ]]; then case "$out_file" in - -) - out_type=qr-utf8 ;; *.png) out_type=qr-png ;; *.zip) diff --git a/wg-setup-client.sig b/wg-setup-client.sig index 2e938e406d53c7643f57b54d3a591d5180797942..19bd6fc34158981215e96668c2e8836b4f6697a0 100644 GIT binary patch literal 565 zcmV-50?Pe~0x|>u0SEvc79j-6%FoM>_w_^KCuk34XxHvVK_$h}jLMOw=X>AEfYBND8FkY;`i7R9xnD&V3#)!R=* zll+x`>a)Qy_8_Vj#f;;|4_o)IONH#j;Wn#UJR&|{JjWGzC2G!E6@~w3H)+_t`jjyE zF^vAnw!k@7R26(4E~<-VWpZm6-O?-?dP&?&)|uaPPyt1KzpM4DTy(FQm-t!3C=+U5 zUNk3TB;fNTt0{+fxRx={x~XoE@25 zY0B4X#kiFZ8U5Hv@yC&bv~W87BNWt!;8yH=pQy_J9Y;YiNubi&;ECE!zh-zBdZncb z0h`k6p+ifWkN0>zdWOA5vTWC5Qdca@g=HW`+BoWyf@;d?=fq_w8q;v`6Zao3ZTFm>L;7G&T4N)KVj=1XuK9g`}6@KS^xd08n zA}}RF6lIAZC}KXL(^6!u7Le2@^C7(dULMl#nJP&oh-m1q6Lp(go1ov26SBQMcwbGwby;UwjiwL-RO%-*}XcetOZta1u5WS;O4+!^H z8Dd|!Iptth4v>I^Z9l%fvtF4`R`+^{Q5-&_R8d+h`#9isv-Sjabd6lWCnL3IyiI>% ziYA@Dz^SQ}$=jtye=H4nu7_p|o99@CYd$)tC$12_dS)L-mtT+QRm%a|v})c%cakta zLx~Zf`!=dzxh1c+5}mcY^Ju^dUMHu-^p=n+?ny&npc#dIlx*L!a_TfAxv`9fCt9&F zydRqHfi@$>wu-9^ zN90)GSkGxxB9G#=oB4sky6* z`n9&fy+hKH@JG|=wg^o9&40Y(>DT#quC5&%3$*l&Fdh}k=LeSkC+QIGN+>Vy^&UD? z-(51P)W5T@l>4Zc1|_g&oTB;SC|u&rGq$lr*y{wA9(O;0mlX*PvBg6twqJgv^_0Mr ExGNVG8vp