From 2021e855a054a982481c2fa03e40a86ad1b35a53 Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Wed, 15 Feb 2023 22:14:33 -0500 Subject: [PATCH] Fixes WSL check on macOS --- .../universal/run_onchange_after_14-warp.tmpl | 2 +- .../universal/run_onchange_after_24-vpn-linux.tmpl | 6 +++--- .../universal/run_onchange_after_27-tor.tmpl | 2 +- .../universal/run_onchange_after_28-privoxy.tmpl | 2 +- .../universal/run_onchange_after_45-vmware.tmpl | 2 +- .../universal/run_onchange_before_11-install-docker.tmpl | 4 ++-- .../endlessh/run_onchange_after_endlessh.tmpl | 2 +- .../fail2ban/run_onchange_after_fail2ban.tmpl | 2 +- home/private_dot_ssh/system/run_onchange_after_sshd.tmpl | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/home/.chezmoiscripts/universal/run_onchange_after_14-warp.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_14-warp.tmpl index 88af3217..45651412 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_14-warp.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_14-warp.tmpl @@ -2,7 +2,7 @@ #!/usr/bin/env bash ### Configure CloudFlare WARP (if not WSL and warp-cli is installed) -if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]] && command -v warp-cli > /dev/null; then +if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]] && command -v warp-cli > /dev/null; then ### Register CloudFlare WARP if warp-cli --accept-tos status | grep 'Registration missing' > /dev/null; then logg info 'Registering CloudFlare WARP' diff --git a/home/.chezmoiscripts/universal/run_onchange_after_24-vpn-linux.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_24-vpn-linux.tmpl index 5d2c3b8e..7cc7102d 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_24-vpn-linux.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_24-vpn-linux.tmpl @@ -9,7 +9,7 @@ RESTART_NM=false -### Ensure NetworkManager plugins are +### Ensure NetworkManager plugins are # NOTE: By default, all the NetworkManager plugins are installed. if command -v apt-get > /dev/null; then sudo apt-get install -y network-manager* @@ -72,7 +72,7 @@ if command -v nmcli > /dev/null; then logg info "Adding $WG_FILE to /etc/NetworkManager/system-connections WG_FILENAME="$(basename "$WG_FILE")" chezmoi decrypt "$WG_FILE" | sudo tee "/etc/NetworkManager/system-connections/$WG_FILENAME" - + ### Register the excluded subnets in the routeadd / routedel files for EXCLUDED_SUBNET in '{{ $removeShortcuts := join "' '" .host.vpn.excludedSubnets }}'; do ensureNetworkConfigs @@ -87,7 +87,7 @@ if command -v nmcli > /dev/null; then fi ### Restart NetworkManager if changes were made and environment is not WSL - if [ "$RESTART_NM" == 'true' ] && [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then + if [ "$RESTART_NM" == 'true' ] && [[ ! "$(test -d proc && grep Microsoft /proc/version > /dev/null)" ]]; then logg info 'Restarting NetworkManager since VPN profiles were updated' sudo service NetworkManager restart fi diff --git a/home/.chezmoiscripts/universal/run_onchange_after_27-tor.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_27-tor.tmpl index 264a24a3..26c74629 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_27-tor.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_27-tor.tmpl @@ -28,7 +28,7 @@ if command -v toron > /dev/null; then # macOS brew services restart tor else - if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then + if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]]; then # Linux sudo systemctl enable tor sudo systemctl restart tor diff --git a/home/.chezmoiscripts/universal/run_onchange_after_28-privoxy.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_28-privoxy.tmpl index 3defb0e4..b2b6883c 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_28-privoxy.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_28-privoxy.tmpl @@ -28,7 +28,7 @@ if command -v privoxy > /dev/null; then # macOS brew services restart privoxy else - if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then + if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]]; then # Linux sudo systemctl enable privoxy sudo systemctl restart privoxy diff --git a/home/.chezmoiscripts/universal/run_onchange_after_45-vmware.tmpl b/home/.chezmoiscripts/universal/run_onchange_after_45-vmware.tmpl index f649532e..baacac8a 100644 --- a/home/.chezmoiscripts/universal/run_onchange_after_45-vmware.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_after_45-vmware.tmpl @@ -56,7 +56,7 @@ if command -v vmware > /dev/null; then logg info '/usr/lib/vmware/isoimages/darwin.iso is already present on the system so VMware macOS unlocking will not be performed' fi - if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then + if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]]; then ### Start / enable VMWare service logg info 'Ensuring `vmware.service` is enabled and running' sudo systemctl enable vmware.service diff --git a/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.tmpl b/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.tmpl index ba063f07..4c80960c 100644 --- a/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.tmpl +++ b/home/.chezmoiscripts/universal/run_onchange_before_11-install-docker.tmpl @@ -122,7 +122,7 @@ function gVisorSource() { else sudo git clone https://github.com/google/gvisor.git /usr/local/src/gvisor fi - + ### Build gVisor cd /usr/local/src/gvisor sudo mkdir -p bin @@ -177,7 +177,7 @@ if [ ! -d /Applications ] || [ ! -d /System ]; then fi # Restart / enable Docker - if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]] && command -v systemctl > /dev/null; then + if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]] && command -v systemctl > /dev/null; then logg info 'Restarting Docker service' sudo systemctl restart docker.service sudo systemctl restart containerd.service diff --git a/home/private_dot_ssh/endlessh/run_onchange_after_endlessh.tmpl b/home/private_dot_ssh/endlessh/run_onchange_after_endlessh.tmpl index df644cb3..f2a5558a 100644 --- a/home/private_dot_ssh/endlessh/run_onchange_after_endlessh.tmpl +++ b/home/private_dot_ssh/endlessh/run_onchange_after_endlessh.tmpl @@ -7,7 +7,7 @@ {{ includeTemplate "universal/logg" }} ### Update /etc/endlessh/config if environment is not WSL -if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then +if [[ ! "$(test -d proc && grep Microsoft /proc/version > /dev/null)" ]]; then if command -v endlessh > /dev/null; then if [ -d /etc/endlessh ]; then logg info 'Copying ~/.ssh/endlessh/config to /etc/endlessh/config' diff --git a/home/private_dot_ssh/fail2ban/run_onchange_after_fail2ban.tmpl b/home/private_dot_ssh/fail2ban/run_onchange_after_fail2ban.tmpl index af48e722..2fad118d 100644 --- a/home/private_dot_ssh/fail2ban/run_onchange_after_fail2ban.tmpl +++ b/home/private_dot_ssh/fail2ban/run_onchange_after_fail2ban.tmpl @@ -22,7 +22,7 @@ function restartFail2Ban() { } ### Update the jail.local file if environment is not WSL -if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then +if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]]; then if [ -d /etc/fail2ban ]; then logg info 'Copying ~/.ssh/fail2ban/jail.local to /etc/fail2ban/jail.local' sudo cp -f "$HOME/.ssh/fail2ban/jail.local" /etc/fail2ban/jail.local diff --git a/home/private_dot_ssh/system/run_onchange_after_sshd.tmpl b/home/private_dot_ssh/system/run_onchange_after_sshd.tmpl index 4a5a6a21..68bdb574 100644 --- a/home/private_dot_ssh/system/run_onchange_after_sshd.tmpl +++ b/home/private_dot_ssh/system/run_onchange_after_sshd.tmpl @@ -8,7 +8,7 @@ {{ includeTemplate "universal/logg" }} ### Update /etc/ssh/sshd_config if environment is not WSL -if [[ ! "$(grep Microsoft /proc/version > /dev/null)" ]]; then +if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]]; then if [ -d /etc/ssh ]; then logg info 'Copying ~/.ssh/system/banner to /etc/ssh/banner' sudo cp -f "$HOME/.ssh/system/banner" /etc/ssh/banner