#!/bin/sh

MAINIP=$(ip route get 1 | awk '{print $NF;exit}')
GATEWAYIP=$(ip route | grep default | awk '{print $3}')
SUBNET=$(ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}' | head -1 | awk -F '/' '{print $2}')

value=$(( 0xffffffff ^ ((1 << (32 - $SUBNET)) - 1) ))
NETMASK="$(( (value >> 24) & 0xff )).$(( (value >> 16) & 0xff )).$(( (value >> 8) & 0xff )).$(( value & 0xff ))"

wget -N --no-check-certificate https://www.815494.com/html/shell/reinstall/Reinstall2022.sh && chmod a+x Reinstall2022.sh
wget -N --no-check-certificate https://www.815494.com/html/shell/reinstall/InstallNET2022.sh && chmod a+x InstallNET2022.sh

clear
echo "                                                           "
echo "###########################################################"
echo "#                                                         #"
echo "#  雨落星辰自动DD一键脚本 V3.0                            #"
echo "#                                                         #"
echo "#  最后更新: 2021-11-26  www.815494.com                   #"
echo "#  交流QQ群: 7766900                                      #"
echo "#  所有系统无特殊说明默认密码：815494.com                 #"
echo "#                                                         #"
echo "#                                                         #"
echo "###########################################################"
echo "                                                           "
echo "IP: $MAINIP"
echo "网关: $GATEWAYIP"
echo "网络掩码: $NETMASK"
echo "                                                            "                                     
echo "请选择您需要的镜像包,甲骨文请选择EFI安装包:"
echo "                                                                "
echo "Which System do you want to Install:"
echo "                                                                "
echo "                                                                "
echo "  11) Latest 【CentOS 8】(推荐)(passwd:cxthhhhh.com) "
echo "  12) Latest 【CentOS 7】(passwd:cxthhhhh.com)"
echo "                                                                "
echo "  21) Latest 【Debian 11】"
echo "  22) Latest 【Debian 10】(推荐)"
echo "  23) Latest 【Debian 9】"
echo "                                                                "
echo "  31) Latest 【Ubuntu 20.04】(推荐)"
echo "  32) Latest 【Ubuntu 18.04】"
echo "  33) Latest 【Ubuntu 16.04】"
echo "                                                                "
echo "  41) Microsoft 【Windows Server 2019】(passwd:cxthhhhh.com)"
echo "  42) 【Windows Server 2016】数据中心版 64位 精简(Password:nat.ee)"
echo "  43) Microsoft 【Windows Server 2012】(passwd:cxthhhhh.com)"
echo "  44) 【Windows Server 2012】-数据中心版-精简(Password:WinSrv2012r2x64-Chinese)"
echo "  45) 【Windows Server 2016】数据中心版 64位 精简-EFI(Password:nat.ee)"
echo "  46) 【Windows Server 2022】数据中心版 64位 精简(Password:nat.ee)"
echo "                                                                "
echo "  ======以下系统已经过时，失去官方技术支持，不推荐使用。======  "
echo "  ====== The system is outdated and is not recommended. ======  "
echo "                                                                "
echo "  81) Latest 【CentOS 6】"
echo "  82) Latest 【Debian 8】"
echo "  83) Latest 【Debian 7】"
echo "  84) Latest 【Ubuntu 14.04】"
echo "  85) Microsoft 【Windows 10 Lite】(passwd:cxthhhhh.com)"
echo "  86) Windows Server 2008R2 数据中心版 64位 简体中文(Password:nat.ee)"
echo "  87) Windows 7 企业版 SP1 简体中文 X64位(Password:nat.ee)"
echo "  88) Microsoft 【Windows_Server_2003】(passwd:cxthhhhh.com)"
echo "  89) Windows Server 2008R2 数据中心版 64位 简体中文-EFI(Password:nat.ee)"
echo "  90) Windows 7 企业版 SP1 简体中文 X64位-EFI(Password:nat.ee)"
echo "  91) WindowsServer2003x86-精简-仅291MB-系统占用内存小(Password:WinSrv2003x86-Chinese)"
echo "                                                                "
echo '  自定义安装请使用：bash Reinstall2022.sh -DD "%URL%" '
echo "                                                                "
echo "================================================================"
echo ""
echo -n "请输入编号: "
read N
case $N in
  11) bash Reinstall2022.sh -CentOS_8 ;;
  12) bash Reinstall2022.sh -CentOS_7 ;;
  21) bash InstallNET2022.sh -d 11 -v 64 -p 815494.com ;;
  22) bash InstallNET2022.sh -d 10 -v 64 -p 815494.com ;;
  23) bash InstallNET2022.sh -d 9 -v 64 -p 815494.com ;;
  31) bash Reinstall2022.sh -Ubuntu_20.04 ;;
  32) bash Reinstall2022.sh -Ubuntu_18.04 ;;
  33) bash Reinstall2022.sh -Ubuntu_16.04 ;;
  41) bash Reinstall2022.sh -Windows_Server_2019;;
  42) bash Reinstall2022.sh -Windows_Server_2016 ;;
  43) bash Reinstall2022.sh -Windows_Server_2012R2 ;;
  44) bash Reinstall2022.sh -Windows_Server_2012R2_LSJ ;;
  45) bash Reinstall2022.sh -Windows_Server_2016_EFI ;;
  46) bash Reinstall2022.sh -Windows_Server_2022 ;;
  
  81) bash Reinstall2022.sh -CentOS_6 ;;
  82) bash Reinstall2022.sh -Debian_8 ;;
  83) bash Reinstall2022.sh -Debian_7 ;;
  84) bash Reinstall2022.sh -Ubuntu_14.04 ;;
  85) bash Reinstall2022.sh -Windows_10_Lite ;;
  86) bash Reinstall2022.sh -Windows_Server_2008R2 ;;
  87) bash Reinstall2022.sh -Windows_7 ;;
  88) bash Reinstall2022.sh -Windows_Server_2003 ;;
  89) bash Reinstall2022.sh -Windows_Server_2008R2EFI ;;
  90) bash Reinstall2022.sh -Win7-EFI ;;
  91) bash Reinstall2022.sh -LSJ2003 ;;
  *) echo "Wrong input, please enter again!" ;;
esac