Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions ocserv-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ install() {

apt update -y

ip=$(hostname -I|cut -f1 -d ' ')
echo "Your Server IP address is:$ip"

echo "Please select connection method:"
echo "1) Domain Name"
echo "2) IP Address"
read -p "Input number [1-2]: " host_type

if [ "$host_type" == "1" ]; then
read -p "Enter Your Domain Name: " ip
else
ip=$(hostname -I | cut -f1 -d ' ')
echo " Auto-detected IP: $ip"
fi
echo "Your Server Host Name is:$ip"

echo -e "\e[32mInstalling gnutls-bin\e[39m"

Expand Down Expand Up @@ -41,17 +52,18 @@ certtool --generate-privkey --outfile server-key.pem
certtool --generate-certificate --load-privkey server-key.pem --load-ca-certificate ca-cert.pem --load-ca-privkey ca-key.pem --template server.tmpl --outfile server-cert.pem

echo -e "\e[32mInstalling ocserv\e[39m"
# ocserv will use /etc/ocserv/ocserv.conf as config file by default
apt install ocserv
cp /etc/ocserv/ocserv.conf ~/certificates/

sed -i -e 's@auth = "@#auth = "@g' /etc/ocserv/ocserv.conf
sed -i -e 's@auth = "pam@auth = "#auth = "pam"@g' /etc/ocserv/ocserv.conf
sed -i -e 's@try-mtu-discovery = @try-mtu-discovery = true@g' /etc/ocserv/ocserv.conf
sed -i 's|^[# ]*try-mtu-discovery.*|try-mtu-discovery = true|' /etc/ocserv/ocserv.conf
sed -i -e 's@dns = @#dns = @g' /etc/ocserv/ocserv.conf
sed -i -e 's@# multiple servers.@dns = 8.8.8.8@g' /etc/ocserv/ocserv.conf
sed -i -e 's@route =@#route =@g' /etc/ocserv/ocserv.conf
sed -i -e 's@no-route =@#no-route =@g' /etc/ocserv/ocserv.conf
sed -i -e 's@cisco-client-compat@cisco-client-compat = true@g' /etc/ocserv/ocserv.conf
sed -i 's|^[# ]*cisco-client-compat.*|cisco-client-compat = true|' ocserv.conf
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you tell me what's the reason behind these two changes?

sed -i -e 's@##auth = "#auth = "pam""@auth = "plain[passwd=/etc/ocserv/ocpasswd]"@g' /etc/ocserv/ocserv.conf

sed -i -e 's@server-cert = /etc/ssl/certs/ssl-cert-snakeoil.pem@server-cert = /etc/ocserv/server-cert.pem@g' /etc/ocserv/ocserv.conf
Expand All @@ -62,9 +74,12 @@ read username

ocpasswd -c /etc/ocserv/ocpasswd $username
iptables -t nat -A POSTROUTING -j MASQUERADE
sed -i -e 's@#net.ipv4.ip_forward=@net.ipv4.ip_forward=@g' /etc/sysctl.conf
#sed -i -e 's@#net.ipv4.ip_forward=@net.ipv4.ip_forward=@g' /etc/sysctl.conf
#The config file might be different in different OS. The command below works for debain 6.12.48.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of making this specific and customized for Debian, let's find out the distro and decide based on that

#The most important thing is path!!
echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/ocserv-custom.conf
sysctl -p /etc/sysctl.d/ocserv-custom.conf

sysctl -p /etc/sysctl.conf
cp ~/certificates/server-key.pem /etc/ocserv/
cp ~/certificates/server-cert.pem /etc/ocserv/
echo -e "\e[32mStopping ocserv service\e[39m"
Expand Down