#!/bin/bash
# Function to check if the command was successful
check_success() {
if [ $? -ne 0 ]; then
echo "Error: $1"
exit 1
fi
}
# Get short hostname
HOSTNAME=$(hostname -s)
# Update and install OpenVPN
echo "Installing OpenVPN..."
sudo apt-get update
sudo apt-get install -y openvpn
check_success "Failed to install OpenVPN"
# Download VPN certificates
echo "Downloading VPN certificates..."
wget --user=user_installer --password=zdthyekcz2022 https://upgrade.offset-partners.ru/vpn-offset/vpncerts_offset.zip -O /opt/vpncerts.zip
check_success "Failed to download VPN certificates"
# Unarchive the VPN config file
echo "Extracting VPN config file..."
unzip -P "dnCN\$L0EwtZtLW" /opt/vpncerts.zip "${HOSTNAME}.conf" -d /etc/openvpn/
check_success "Failed to extract VPN config file"
# Remove VPN archive
echo "Removing VPN archive..."
rm -f /opt/vpncerts.zip
check_success "Failed to remove VPN archive"
# Allow OpenVPN to autoconnect
echo "Enabling OpenVPN autoconnect..."
sudo sed -i 's/#AUTOSTART="all"/AUTOSTART="all"/' /etc/default/openvpn
check_success "Failed to enable OpenVPN autoconnect"
echo "Deleting script..."
rm -- "$0"