Skip to content

Commit 7e620a4

Browse files
committed
add nextextender vagrant to just
1 parent 3b7bf04 commit 7e620a4

File tree

1 file changed

+75
-71
lines changed

1 file changed

+75
-71
lines changed

files/justfiles/kompassos.just

Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
# Test this Just file: /usr/bin/just --justfile files/justfiles/kompassos.just
2+
13
# Install vagrant https://thenets.org/running-vagrant-libvirt-on-bluefin-or-aurora/
24
[group('Apps')]
35
install-vagrant:
46
#!/usr/bin/env bash
7+
# Install the libvirt-devel - libvirt-devel already installed in KompassOS
8+
# rpm-ostree install libvirt-devel
59
# Add the hashicorp/tap repo
610
brew tap hashicorp/tap
711
# Install vagrant for Linux
@@ -12,7 +16,8 @@ install-vagrant:
1216
# Setup NetExtender VPN with Vagrant
1317
[group('Apps')]
1418
setup-netextender-vagrant vpn_server="" vpn_port="" vpn_domain="" vpn_user="" target_dir="":
15-
#!/usr/bin/bash
19+
#!/usr/bin/env bash
20+
set -euo pipefail
1621
source /usr/lib/ujust/ujust.sh
1722

1823
# Check if vagrant is installed
@@ -102,76 +107,75 @@ setup-netextender-vagrant vpn_server="" vpn_port="" vpn_domain="" vpn_user="" ta
102107
VPN_USER="{{ vpn_user }}"
103108
fi
104109

105-
# Create Vagrantfile in the target directory
106-
cat > "$TARGET_DIR/Vagrantfile" << EOF
107-
# -*- mode: ruby -*-
108-
# vi: set ft=ruby :
109-
110-
Vagrant.configure("2") do |config|
111-
config.vm.box = "generic/ubuntu2204"
112-
config.vm.box_version = "4.3.12"
113-
114-
config.vm.network "private_network", ip: "192.168.121.10"
115-
116-
config.vm.provider "libvirt" do |libvirt|
117-
libvirt.cpus = 1
118-
libvirt.memory = 1024
119-
end
120-
121-
# Create user and set up SSH key
122-
if "$SSH_PUBLIC_KEY" != ""
123-
config.vm.provision "shell", inline: <<-SHELL
124-
# Create user if it doesn't exist
125-
if ! id -u $CURRENT_USER >/dev/null 2>&1; then
126-
useradd -m -s /bin/bash $CURRENT_USER
127-
# Add user to sudo group
128-
usermod -aG sudo $CURRENT_USER
129-
# Set up password-less sudo for the user
130-
echo "$CURRENT_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$CURRENT_USER
131-
fi
132-
133-
# Set up SSH key
134-
mkdir -p /home/$CURRENT_USER/.ssh
135-
echo "$SSH_PUBLIC_KEY" > /home/$CURRENT_USER/.ssh/authorized_keys
136-
chmod 700 /home/$CURRENT_USER/.ssh
137-
chmod 600 /home/$CURRENT_USER/.ssh/authorized_keys
138-
chown -R $CURRENT_USER:$CURRENT_USER /home/$CURRENT_USER/.ssh
139-
SHELL
140-
end
141-
142-
config.vm.provision "shell", inline: <<-SHELL
143-
printf "\\nDisk free space before...\\n"
144-
df -lhT /
145-
apt-get update
146-
apt-get install -y default-jre wget
147-
printf "\\nAllowTcpForwarding..\\n"
148-
sudo sed -i "s/#AllowTcpForwarding yes/AllowTcpForwarding yes/g" /etc/ssh/sshd_config
149-
wget https://software.sonicwall.com/NetExtender/NetExtender-linux-amd64-10.3.0-21.tar.gz
150-
tar -zxvf NetExtender-linux-amd64-10.3.0-21.tar.gz
151-
cd netextender
152-
sudo ./install.sh
153-
154-
sudo cat >/etc/networkd-dispatcher/routable.d/50-ifup-hooks <<EOFHOOK
155-
#!/bin/sh
156-
if ! iptables -t nat -C POSTROUTING -o snwl_ssltunnel -j MASQUERADE 2>/dev/null
157-
then
158-
nxcli connection delete ${VPN_DOMAIN}
159-
nxcli connection add ${VPN_DOMAIN} --server ${VPN_SERVER}:${VPN_PORT} --username=${VPN_USER} --password=CHANGE_ME --domain=${VPN_DOMAIN} --protocol Auto
160-
echo 1 > /proc/sys/net/ipv4/ip_forward
161-
iptables -t nat -A POSTROUTING -o snwl_ssltunnel -j MASQUERADE
162-
fi
163-
exit 0
164-
EOFHOOK
165-
166-
sudo chmod 755 /etc/networkd-dispatcher/routable.d/50-ifup-hooks
167-
168-
sudo echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/ip_forward.conf
169-
echo "add the following to the host system: ip route add 10.5.50.0/24 via 192.168.121.10"
170-
echo "to connect use: nxcli connect ${VPN_DOMAIN}"
171-
reboot
172-
SHELL
173-
end
174-
EOF
110+
# Write Vagrantfile
111+
{
112+
echo '# -*- mode: ruby -*-'
113+
echo '# vi: set ft=ruby :'
114+
echo ''
115+
echo 'Vagrant.configure("2") do |config|'
116+
echo ' config.vm.box = "generic/ubuntu2204"'
117+
echo ' config.vm.box_version = "4.3.12"'
118+
echo ''
119+
echo ' config.vm.network "private_network", ip: "192.168.121.10"'
120+
echo ''
121+
echo ' config.vm.provider "libvirt" do |libvirt|'
122+
echo ' libvirt.cpus = 1'
123+
echo ' libvirt.memory = 1024'
124+
echo ' end'
125+
echo ''
126+
if [ -n "$SSH_PUBLIC_KEY" ]; then
127+
echo ' config.vm.provision "shell", inline: <<-SHELL'
128+
echo ' # Create user if it doesn'"'"'t exist'
129+
echo " if ! id -u $CURRENT_USER >/dev/null 2>&1; then"
130+
echo " useradd -m -s /bin/bash $CURRENT_USER"
131+
echo " # Add user to sudo group"
132+
echo " usermod -aG sudo $CURRENT_USER"
133+
echo " # Set up password-less sudo for the user"
134+
echo " echo '$CURRENT_USER ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/$CURRENT_USER"
135+
echo " fi"
136+
echo ''
137+
echo " # Set up SSH key"
138+
echo " mkdir -p /home/$CURRENT_USER/.ssh"
139+
echo " echo '$SSH_PUBLIC_KEY' > /home/$CURRENT_USER/.ssh/authorized_keys"
140+
echo " chmod 700 /home/$CURRENT_USER/.ssh"
141+
echo " chmod 600 /home/$CURRENT_USER/.ssh/authorized_keys"
142+
echo " chown -R $CURRENT_USER:$CURRENT_USER /home/$CURRENT_USER/.ssh"
143+
echo ' SHELL'
144+
echo ''
145+
fi
146+
echo ' config.vm.provision "shell", inline: <<-SHELL'
147+
echo ' printf "\nDisk free space before...\n"'
148+
echo ' df -lhT /'
149+
echo ' apt-get update'
150+
echo ' apt-get install -y default-jre wget'
151+
echo ' printf "\nAllowTcpForwarding..\n"'
152+
echo ' sudo sed -i "s/#AllowTcpForwarding yes/AllowTcpForwarding yes/g" /etc/ssh/sshd_config'
153+
echo ' wget https://software.sonicwall.com/NetExtender/NetExtender-linux-amd64-10.3.0-21.tar.gz'
154+
echo ' tar -zxvf NetExtender-linux-amd64-10.3.0-21.tar.gz'
155+
echo ' cd netextender'
156+
echo ' sudo ./install.sh'
157+
echo ''
158+
echo ' sudo cat >/etc/networkd-dispatcher/routable.d/50-ifup-hooks <<EOFHOOK'
159+
echo '#!/bin/sh'
160+
echo 'if ! iptables -t nat -C POSTROUTING -o snwl_ssltunnel -j MASQUERADE 2>/dev/null'
161+
echo 'then'
162+
echo " nxcli connection delete $VPN_DOMAIN"
163+
echo " nxcli connection add $VPN_DOMAIN --server $VPN_SERVER:$VPN_PORT --username=$VPN_USER --password=CHANGE_ME --domain=$VPN_DOMAIN --protocol Auto"
164+
echo ' echo 1 > /proc/sys/net/ipv4/ip_forward'
165+
echo ' iptables -t nat -A POSTROUTING -o snwl_ssltunnel -j MASQUERADE'
166+
echo 'fi'
167+
echo 'exit 0'
168+
echo 'EOFHOOK'
169+
echo ''
170+
echo ' sudo chmod 755 /etc/networkd-dispatcher/routable.d/50-ifup-hooks'
171+
echo ''
172+
echo ' sudo echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/ip_forward.conf'
173+
echo ' echo "add the following to the host system: ip route add 10.5.50.0/24 via 192.168.121.10"'
174+
echo " echo \"to connect use: nxcli connect""
175+
echo ' reboot'
176+
echo ' SHELL'
177+
echo 'end'
178+
} > "$TARGET_DIR/Vagrantfile"
175179
176180
echo "${green}${bold}Vagrantfile created successfully in: ${TARGET_DIR}${normal}"
177181
echo "Note: You'll need to modify the password in the generated Vagrantfile before using it."

0 commit comments

Comments
 (0)