#!/bin/bash
###menu
if [ ! "$(cat /proc/cpuinfo | grep 'Raspberry')" != "" ]; then
sudo cat > /bin/menu <<- "EOFX2"
#!/bin/bash
if [ $EUID -ne 0 ]; then
    whiptail --title "sudo su" --msgbox "requiere ser usuario root , escriba (sudo su) antes de entrar a menu / requires root user, type (sudo su) before entering menu" 0 50
    exit 1
fi
while : ; do
  choix=$(whiptail --title "Proyecto emq-TE1+ Rev: R00ab / Scrip Proyect by HP3ICC 73." --menu "Suba o Baje con las flechas del teclado y seleccione el número de opción:" 22 75 13 \
  1 " APRS " \
  2 " MMDVMHost " \
  3 " Dvswitch " \
  4 " Server & Reflector " \
  5 " Cross Bridge " \
  6 " DDNS NoIP " \
  7 " GoTTY " \
  8 " Firewall " \
  9 " Update " \
  10 " Reiniciar Equipo " \
  11 " Set Time Zone " \
  12 " Salir del menú " 3>&1 1>&2 2>&3)
exitstatus=$?

if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $choix
else
    echo "You chose cancel."
    break
fi

case $choix in
  1)
    menu-aprs;;
  2)
    menu-mmdvm;;
  3)
    menu-dvs;;
  4)
  while : ; do
    network=$(whiptail --title "Server & Reflector" --menu "Select menu:" 15 60 8 \
      "1" "pYSFReflector3" \
      "2" "P25 Reflector" \
      "3" "XLX Reflector" \
      "4" "HBLink3 Server" \
      "5" "ADN Peer DMR Server" \
      "6" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-ysf ;;
        "2")
          menu-p25r ;;
        "3")
          menu-xlx ;;
        "4")
          menu-hbl ;;
        "5")
          menu-adn ;;
        "6")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  5)
   while : ; do
    network=$(whiptail --title "Cross Bridge" --menu "Select menu:" 15 60 6 \
      "1" "NXDN2DMR" \
      "2" "YSF2DMR" \
      "3" "YSF Bridge YSF " \
      "4" "P25 Bridge DMR/XLXD " \
      "5" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-nxdn2dmr ;;
        "2")
          menu-ysf2dmr ;;
        "3")
          menu-ysf2ysf ;;
        "4")
          menu-p25b ;;
        "5")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  6)
    menu-noip ;;
  7)
    menu-web ;;
  8)
    menu-ufw ;;
  9)
    bash -c "$(curl -fsSL https://gitlab.com/hp3icc/emq-TE1/-/raw/main/update.sh)" ;;
  10)
    menu-reboot ;;
  11)
    dpkg-reconfigure tzdata ;;
  12)
 break
    ;;
esac
done
exit 0

EOFX2
fi
if [ ! "$(cat /proc/cpuinfo | grep 'Raspberry')" != "" ]; then
  if  [ -d "/etc/asterisk" ]; then
sudo cat > /bin/menu <<- "EOFX2"
#!/bin/bash
if [ $EUID -ne 0 ]; then
    whiptail --title "sudo su" --msgbox "requiere ser usuario root , escriba (sudo su) antes de entrar a menu / requires root user, type (sudo su) before entering menu" 0 50
    exit 1
fi
while : ; do
  choix=$(whiptail --title "Proyecto emq-TE1+ Rev: R00ab / Scrip Proyect by HP3ICC 73." --menu "Suba o Baje con las flechas del teclado y seleccione el número de opción:" 22 75 13 \
  1 " APRS " \
  2 " MMDVMHost " \
  3 " Dvswitch " \
  4 " Server & Reflector " \
  5 " Cross Bridge " \
  6 " DDNS NoIP " \
  7 " GoTTY " \
  8 " Firewall " \
  9 " Update " \
  10 " Reiniciar Equipo " \
  11 " Set Time Zone " \
  12 " Salir del menú " 3>&1 1>&2 2>&3)
exitstatus=$?

if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $choix
else
    echo "You chose cancel."
    break
fi

case $choix in
  1)
    menu-aprs;;
  2)
    menu-mmdvm;;
  3)
    menu-dvs;;
  4)
  while : ; do
    network=$(whiptail --title "Server & Reflector" --menu "Select menu:" 15 60 8 \
      "1" "pYSFReflector3" \
      "2" "P25 Reflector" \
      "3" "XLX Reflector" \
      "4" "HBLink3 Server" \
      "5" "ADN Peer DMR Server" \
      "6" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-ysf ;;
        "2")
          menu-p25r ;;
        "3")
          menu-xlx ;;
        "4")
          menu-hbl ;;
        "5")
          menu-adn ;;
        "6")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  5)
   while : ; do
    network=$(whiptail --title "Cross Bridge" --menu "Select menu:" 15 60 7 \
      "1" "NXDN2DMR" \
      "2" "YSF2DMR" \
      "3" "YSF Bridge YSF " \
      "4" "P25 Bridge DMR/XLXD " \
      "5" "ASL Bridge " \
      "6" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-nxdn2dmr ;;
        "2")
          menu-ysf2dmr ;;
        "3")
          menu-ysf2ysf ;;
        "4")
          menu-p25b ;;
        "5")
          menu-asl ;;
        "6")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  6)
    menu-noip ;;
  7)
    menu-web ;;
  8)
    menu-ufw ;;
  9)
    bash -c "$(curl -fsSL https://gitlab.com/hp3icc/emq-TE1/-/raw/main/update.sh)" ;;
  10)
    menu-reboot ;;
  11)
    dpkg-reconfigure tzdata ;;
  12)
 break
    ;;
esac
done
exit 0

EOFX2
  fi
fi
if [ "$(cat /proc/cpuinfo | grep 'Raspberry')" != "" ]; then
sudo cat > /bin/menu <<- "EOFX1"
#!/bin/bash
if [ $EUID -ne 0 ]; then
    whiptail --title "sudo su" --msgbox "requiere ser usuario root , escriba (sudo su) antes de entrar a menu / requires root user, type (sudo su) before entering menu" 0 50
    exit 1
fi
while : ; do
  choix=$(whiptail --title "Proyecto emq-TE1+ Rev: R00ab / Scrip Proyect by HP3ICC 73." --menu "Suba o Baje con las flechas del teclado y seleccione el número de opción:" 22 75 13 \
  1 " APRS " \
  2 " MMDVMHost " \
  3 " Dvswitch " \
  4 " Server & Reflector " \
  5 " Cross Bridge " \
  6 " WiFi & IP Tools " \
  7 " DDNS NoIP " \
  8 " GoTTY " \
  9 " Firewall " \
  10 " Update " \
  11 " Reiniciar Equipo " \
  12 " Set Time Zone " \
  13 " Salir del menú " 3>&1 1>&2 2>&3)
exitstatus=$?

if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $choix
else
    echo "You chose cancel."
    break
fi

case $choix in
  1)
    menu-aprs;;
  2)
    menu-mmdvm;;
  3)
    menu-dvs;;
  4)
 while : ; do
    network=$(whiptail --title "Server & Reflector" --menu "Select menu:" 15 60 8 \
      "1" "pYSFReflector3" \
      "2" "P25 Reflector" \
      "3" "XLX Reflector" \
      "4" "HBLink3 Server" \
      "5" "ADN Peer DMR Server" \
      "6" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-ysf ;;
        "2")
          menu-p25r ;;
        "3")
          menu-xlx ;;
        "4")
          menu-hbl ;;
        "5")
          menu-adn ;;
        "6")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  5)
   while : ; do
    network=$(whiptail --title "Cross Bridge" --menu "Select menu:" 15 60 6 \
      "1" "NXDN2DMR" \
      "2" "YSF2DMR" \
      "3" "YSF BRIDGE YSF " \
      "4" "P25 BRIDGE DMR/XLXD " \
      "5" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-nxdn2dmr ;;
        "2")
          menu-ysf2dmr ;;
        "3")
          menu-ysf2ysf ;;
        "4")
          menu-p25b ;;
        "5")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  6)
    menu-wifi-manager;;
  7)
    menu-noip ;;
  8)
    menu-web ;;
  9)
    menu-ufw ;;
  10)
    bash -c "$(curl -fsSL https://gitlab.com/hp3icc/emq-TE1/-/raw/main/update.sh)" ;;
  11)
    menu-reboot ;;
  12)
    dpkg-reconfigure tzdata ;;
  13)
break
    ;;
esac
done
exit 0

EOFX1
fi
if [ "$(cat /proc/cpuinfo | grep 'Raspberry')" != "" ]; then
  if  [ -d "/etc/asterisk" ]; then  
sudo cat > /bin/menu <<- "EOFX1"
#!/bin/bash
if [ $EUID -ne 0 ]; then
    whiptail --title "sudo su" --msgbox "requiere ser usuario root , escriba (sudo su) antes de entrar a menu / requires root user, type (sudo su) before entering menu" 0 50
    exit 1
fi
while : ; do
  choix=$(whiptail --title "Proyecto emq-TE1+ Rev: R00ab / Scrip Proyect by HP3ICC 73." --menu "Suba o Baje con las flechas del teclado y seleccione el número de opción:" 22 75 13 \
  1 " APRS " \
  2 " MMDVMHost " \
  3 " Dvswitch " \
  4 " Server & Reflector " \
  5 " Cross Bridge " \
  6 " WiFi & IP Tools " \
  7 " DDNS NoIP " \
  8 " GoTTY " \
  9 " Firewall " \
  10 " Update " \
  11 " Reiniciar Equipo " \
  12 " Set Time Zone " \
  13 " Salir del menú " 3>&1 1>&2 2>&3)
exitstatus=$?

if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $choix
else
    echo "You chose cancel."
    break
fi

case $choix in
  1)
    menu-aprs;;
  2)
    menu-mmdvm;;
  3)
    menu-dvs;;
  4)
  while : ; do
    network=$(whiptail --title "Server & Reflector" --menu "Select menu:" 15 60 8 \
      "1" "pYSFReflector3" \
      "2" "P25 Reflector" \
      "3" "XLX Reflector" \
      "4" "HBLink3 Server" \
      "5" "ADN Peer DMR Server" \
      "6" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-ysf ;;
        "2")
          menu-p25r ;;
        "3")
          menu-xlx ;;
        "4")
          menu-hbl ;;
        "5")
          menu-adn ;;
        "6")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  5)
   while : ; do
    network=$(whiptail --title "Cross Bridge" --menu "Select menu:" 15 60 7 \
      "1" "NXDN2DMR" \
      "2" "YSF2DMR" \
      "3" "YSF Bridge YSF " \
      "4" "P25 Bridge DMR/XLXD " \
      "5" "ASL Bridge " \
      "6" "menu principal" 3>&1 1>&2 2>&3)

    exitstatus=$?

    if [ $exitstatus = 0 ]; then
      case "$network" in
        "1")
          menu-nxdn2dmr ;;
        "2")
          menu-ysf2dmr ;;
        "3")
          menu-ysf2ysf ;;
        "4")
          menu-p25b ;;
        "5")
          menu-asl ;;
        "6")
          break ;;
        *)
          echo "Invalid selection" ;;
      esac
    else
      echo "You chose cancel."
      break
    fi
  done
  ;;
  6)
    menu-wifi-manager;;
  7)
    menu-noip ;;
  8)
    menu-web ;;
  9)
    menu-ufw ;;
  10)
    bash -c "$(curl -fsSL https://gitlab.com/hp3icc/emq-TE1/-/raw/main/update.sh)" ;;
  11)
    menu-reboot ;;
  12)
    dpkg-reconfigure tzdata ;;
  13)
break
    ;;
esac
done
exit 0

EOFX1
  fi
fi
variable22=$(grep "EMQ-VER:" /opt/emq-ver | grep -Eo '[A.0-9]{1,9}')
sudo sed -i "s/R00ab/$variable22/g"  /bin/menu
ln -sf /bin/menu /bin/MENU
chmod +x /bin/menu*
chmod +x /bin/MENU*
