#!/bin/bash
########################################################
######################################################## 
# Wire-G App for simple management a Wireguard Tunnel ##
# Author: Désiré Werner Menrath                       ##
# Email: polunga40@unity-mail.de                      ##
# Translate German to English with LibreTranslate     ##
# Translatefiles edit with Poedit                     ##
# Use without warranty!                               ##
######################################################## 
########################################################

############################################################################################################ 
############################################################################################################ 

# abfrage ob benötigte pakete installiert sind, wenn nicht dann installiere automatisch die benötigten Pakete.

if grep -i 'mint\|debian\|ubuntu\|pop|' /etc/os-release > /dev/null 2>&1
    then
        echo $"Wire-G is installed..."
        mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli 
        if ! which yad  > /dev/null ; then sudo apt install yad -y > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi
        
elif grep -i 'arch\|manjaro\|garuda\|endeavour|' /etc/os-release > /dev/null 2>&1
    then
        echo $"Wire-G is installed..."
        mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
        if ! which yad  > /dev/null ; then sudo pacman -S --noconfirm yad > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi 
        
elif grep -i 'fedora' /etc/os-release > /dev/null 2>&1
    then
        echo $"Wire-G is installed..."
        mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
        if ! which yad  > /dev/null ; then sudo dnf install yad > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi
        
elif grep -i 'suse' /etc/os-release > /dev/null 2>&1
    then
        clear
        echo $"Attention OpenSuse is not officially supported!"
        echo
        echo $"yad must install them themselves when they continue!"
        echo $"since these packages are officially not available."
        echo
        read -p $"Enter i for installation and enter key, break down with any other button ..." RESPONSE
        if [ "$RESPONSE" == "i" ]
            then 
            echo $"Wire-G is installed..."
            mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
            
        else 
        exit 1 
        fi  
else
    clear
    echo $"Your System could not be determined."
    echo
    read -n 1 -s -r -p $"To close the window press a button"
    clear
    exit 0
fi

if [ ! -d /home/"$USER"/.local/share ]
    then
        mkdir -p /home/"$USER"/.local/share
        cp -r wg_nmcli /home/"$USER"/.local/share/
    else
        cp -r wg_nmcli /home/"$USER"/.local/share/
fi
if [ ! -d /home/"$USER"/.config/autostart ]
    then
        mkdir -p /home/"$USER"/.config/autostart
fi
wait;
sudo mkdir -p /usr/share/icons/Arch-Symbole ; sudo cp icons/wg-vpn.png /usr/share/icons/Arch-Symbole/
wait;
sudo cp wire_g /sbin/ ; sudo chmod +x /sbin/wire_g ; sudo cp wg_stop /sbin/ ; sudo chmod +x /sbin/wg_stop
wait;
sudo cp wg_on_start /sbin/ ; sudo chmod +x /sbin/wg_on_start
wait; sudo cp Wire-G.desktop /usr/share/applications/
echo
case $LANG in
    de_DE.UTF-8) sudo cp languages/de/*.mo /usr/share/locale/de/LC_MESSAGES/ ;;

              *) echo $"Wire-G uses the standard language." ;;
esac
clear
echo $"Installation successfully!"
echo
read -n 1 -s -r -p $"To close the window press a button"
clear

############################################  END  ##########################################################