一键全自动DD脚本简易版linux重装系统脚本

此脚本基于萌咖大佬的网络重装脚本开发,自动检测ip,傻瓜式重装系统,目前支持CentOS 6/7、Ubuntu 16/18、Debian 9,自定义dd包以后可能会加上(咕咕咕

顺便安利一波自己的CentOS 7 DD包,仅400M,极速dd,开机内存30M,脚本已经内置了噢~

脚本使用

wget --no-check-certificate -qO AutoDD.sh 'http://git.io/autodd.sh' && bash AutoDD.sh

下载不了的话自行复制进行运行

#!/bin/sh

if [[ $EUID -ne 0 ]]; then
    clear
    echo "Error: This script must be run as root!" 1>&2
    exit 1
fi

function isValidIp() {
  local ip=$1
  local ret=1
  if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
    ip=(${ip//\./ })
    [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
    ret=$?
  fi
  return $ret
}

function updateIp() {
  CopyRight
  read -r -p "Your IP: " MAINIP
  read -r -p "Your Gateway: " GATEWAYIP
  read -r -p "Your Netmask: " NETMASK
}

function ipCheck() {
  isLegal=0
  for add in $MAINIP $GATEWAYIP $NETMASK; do
    isValidIp $add
    if [ $? -eq 1 ]; then
      isLegal=1
    fi
  done
  return $isLegal
}

function CopyRight() {
  clear
  echo "################################################"
  echo "#                                              #"
  echo "#  Auto ReInstall Script                       #"
  echo "#                                              #"
  echo "#  Author: hiCasper                            #"
  echo "#  Blog: https://blog.hicasper.com             #"
  echo "#  Last Modified: 2019-11-22                   #"
  echo "#                                              #"
  echo "#  Supported by MoeClub                        #"
  echo "#                                              #"
  echo "################################################"
  echo -e "\n"
}

function start() {
  CopyRight
  echo "IP: $MAINIP"
  echo "Gateway: $GATEWAYIP"
  echo "Netmask: $NETMASK"
  echo -e "\nPlease select an OS:"
  echo "  1) CentOS 7 (DD)"
  echo "  2) CentOS 6 (tuna mirror)"
  echo "  3) CentOS 6"
  echo "  4) Debian 9"
  echo "  5) Debian 10"
  echo "  6) Ubuntu 16.04"
  echo "  7) Ubuntu 18.04"
  echo "  8) Custom image"
  echo "  0) Exit"
  echo -ne "\nYour option: "
  read N
  case $N in
    1) echo "Password: Pwd@CentOS"; read -s -n1 -p "Press any key to continue..." ; bash /tmp/InstallNET.sh --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK -dd 'https://api.moetools.net/get/centos-7-image' ;;
    2) bash /tmp/InstallNET.sh -c 6.9 -v 64 -a --mirror 'http://mirrors.tuna.tsinghua.edu.cn/centos-vault' --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $SUBNET ;;
    3) bash /tmp/InstallNET.sh -c 6.9 -v 64 -a --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK ;;
    4) bash /tmp/InstallNET.sh -d 9 -v 64 -a --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK ;;
    5) bash /tmp/InstallNET.sh -d 10 -v 64 -a --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK ;;
    6) bash /tmp/InstallNET.sh -u 16.04 -v 64 -a --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK ;;
    7) bash /tmp/InstallNET.sh -u 18.04 -v 64 -a --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK ;;
    8)
      read -r -p "Custom image URL: " imgURL
      echo -e "\n"
      read -r -p "Are you sure start reinstall? [Y/n]: " input
      case $input in
        [yY][eE][sS]|[yY]) bash /tmp/InstallNET.sh --ip-addr $MAINIP --ip-gate $GATEWAYIP --ip-mask $NETMASK -dd $imgURL;;
        *) clear; echo "Canceled by user!"; exit 1;;
      esac
      ;;
    0) exit 0;;
    *) echo "Wrong input!"; exit 1;;
  esac
}

if [ -f "/tmp/InstallNET.sh" ]; then
  rm -f /tmp/InstallNET.sh
fi
wget --no-check-certificate -qO /tmp/InstallNET.sh 'https://moeclub.org/attachment/LinuxShell/InstallNET.sh' && chmod a+x /tmp/InstallNET.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 ))"

ipCheck
if [ $? -eq 0 ]; then
  CopyRight
  echo "IP: $MAINIP"
  echo "Gateway: $GATEWAYIP"
  echo "Netmask: $NETMASK"
  echo -ne "\n"
  read -r -p "Please confirm your network infomation [Y/n]: " input
  case $input in
    [yY][eE][sS]|[yY]) start;;
    [nN][oO]|[nN])
      updateIp
      ipCheck
      if [ $? -eq 0 ]; then
        start
      else
        echo -e "\nIllegal address!"; exit 1
      fi
      ;;
    *) echo "Wrong input!"; exit 1;;
  esac
else
  echo -e "\nIllegal address!"
  updateIp
  ipCheck
  if [ $? -eq 0 ]; then
    start
  else
    echo -e "\nIllegal address!"
  fi
fi

root密码

Pwd@CentOS

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 787772394@qq.com

文章标题:一键全自动DD脚本简易版linux重装系统脚本

本文作者:二豆子·pwnd0u

发布时间:2020-12-22, 12:25:46

最后更新:2020-12-22, 12:27:33

原始链接:http://blog.codefat.cn/2020/12/22/%E7%AE%80%E6%98%93%E7%89%88linux%E9%87%8D%E8%A3%85%E7%B3%BB%E7%BB%9F%E8%84%9A%E6%9C%AC/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏

/*爱心代码*/ /*雪花效果*/ /*百度代码自动提交*/