Skip to content

Commit

Permalink
Update InstallNET.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
veip007 authored Feb 16, 2023
1 parent a88e2f3 commit c54ccc9
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions InstallNET.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export GRUBDIR=''
export GRUBFILE=''
export GRUBVER=''
export VER=''
export setCMD=''
export setConsole=''

while [[ $# -ge 1 ]]; do
case $1 in
Expand Down Expand Up @@ -118,6 +120,16 @@ while [[ $# -ge 1 ]]; do
WinRemote="$1"
shift
;;
-cmd)
shift
setCMD="$1"
shift
;;
-console)
shift
setConsole="$1"
shift
;;
-firmware)
shift
IncFirmware="1"
Expand Down Expand Up @@ -189,7 +201,7 @@ function selectMirror(){
[ -n "$TEMP" ] || exit 1
mirrorStatus=0
declare -A MirrorBackup
MirrorBackup=(["debian0"]="" ["debian1"]="http://deb.debian.org/debian" ["debian2"]="http://archive.debian.org/debian" ["ubuntu0"]="" ["ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["ubuntu1"]="http://ports.ubuntu.com" ["centos0"]="" ["centos1"]="http://mirror.centos.org/centos" ["centos2"]="http://vault.centos.org")
MirrorBackup=(["debian0"]="" ["debian1"]="http://deb.debian.org/debian" ["debian2"]="http://archive.debian.org/debian" ["ubuntu0"]="" ["ubuntu1"]="http://archive.ubuntu.com/ubuntu" ["ubuntu2"]="http://ports.ubuntu.com" ["centos0"]="" ["centos1"]="http://mirror.centos.org/centos" ["centos2"]="http://vault.centos.org")
echo "$New" |grep -q '^http://\|^https://\|^ftp://' && MirrorBackup[${Relese}0]="$New"
for mirror in $(echo "${!MirrorBackup[@]}" |sed 's/\ /\n/g' |sort -n |grep "^$Relese")
do
Expand Down Expand Up @@ -230,7 +242,7 @@ function getInterface(){
}

function getDisk(){
disks=`lsblk | sed 's/[[:space:]]*$//g' |grep "disk$" |cut -d' ' -f1 |head -n1`
disks=`lsblk | sed 's/[[:space:]]*$//g' |grep "disk$" |cut -d' ' -f1 |grep -v "fd[0-9]*\|sr[0-9]*" |head -n1`
[ -n "$disks" ] || echo ""
echo "$disks" |grep -q "/dev"
[ $? -eq 0 ] && echo "$disks" || echo "/dev/$disks"
Expand All @@ -248,15 +260,21 @@ function getGrub(){
if [ -z "$fileName" ]; then
ls -1 "$folder" 2>/dev/null |grep -q '^grubenv$'
[ $? -eq 0 ] || return
grubEnv=`readlink -f "${folder}/grubenv"`
folder=`dirname "$grubEnv"`
folder=`find "$Boot" -type f -name "grubenv" 2>/dev/null |xargs dirname |grep -v "^$folder" |head -n1`
[ -n "$folder" ] || return
fileName=`ls -1 "$folder" 2>/dev/null |grep '^grub.conf$\|^grub.cfg$'`
fi
[ -n "$fileName" ] || return
[ "$fileName" == "grub.cfg" ] && ver="0" || ver="1"
echo "${folder}:${fileName}:${ver}"
}

function lowMem(){
mem=`grep "^MemTotal:" /proc/meminfo 2>/dev/null |grep -o "[0-9]*"`
[ -n "$mem" ] || return 0
[ "$mem" -le "524288" ] && return 1 || return 0
}

if [[ "$loaderMode" == "0" ]]; then
Grub=`getGrub "/boot"`
[ -z "$Grub" ] && echo -ne "Error! Not Found grub.\n" && exit 1;
Expand Down Expand Up @@ -339,6 +357,7 @@ if [[ -n "$tmpDIST" ]]; then
[[ "$isDigital" == '9' ]] && DIST='stretch';
[[ "$isDigital" == '10' ]] && DIST='buster';
[[ "$isDigital" == '11' ]] && DIST='bullseye';
# [[ "$isDigital" == '12' ]] && DIST='bookworm';
}
}
LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
Expand All @@ -355,6 +374,7 @@ if [[ -n "$tmpDIST" ]]; then
[[ "$isDigital" == '16.04' ]] && DIST='xenial';
[[ "$isDigital" == '18.04' ]] && DIST='bionic';
[[ "$isDigital" == '20.04' ]] && DIST='focal';
# [[ "$isDigital" == '22.04' ]] && DIST='jammy';
}
}
LinuxMirror=$(selectMirror "$Relese" "$DIST" "$VER" "$tmpMirror")
Expand Down Expand Up @@ -531,12 +551,16 @@ if [[ "$loaderMode" == "0" ]]; then

[[ "$setInterfaceName" == "1" ]] && Add_OPTION="net.ifnames=0 biosdevname=0" || Add_OPTION=""
[[ "$setIPv6" == "1" ]] && Add_OPTION="$Add_OPTION ipv6.disable=1"

lowMem || Add_OPTION="$Add_OPTION lowmem=+2"

if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain= -- quiet"
BOOT_OPTION="auto=true $Add_OPTION hostname=$linux_relese domain=$linux_relese quiet"
elif [[ "$linux_relese" == 'centos' ]]; then
BOOT_OPTION="ks=file://ks.cfg $Add_OPTION ksdevice=$interfaceSelect"
fi

[ -n "$setConsole" ] && BOOT_OPTION="$BOOT_OPTION --- console=$setConsole"

[[ "$Type" == 'InBoot' ]] && {
sed -i "/$LinuxKernel.*\//c\\\t$LinuxKernel\\t\/boot\/vmlinuz $BOOT_OPTION" /tmp/grub.new;
Expand Down Expand Up @@ -589,9 +613,13 @@ $UNCOMP < /tmp/$NewIMG | cpio --extract --verbose --make-directories --no-absolu
if [[ "$linux_relese" == 'debian' ]] || [[ "$linux_relese" == 'ubuntu' ]]; then
cat >/tmp/boot/preseed.cfg<<EOF
d-i debian-installer/locale string en_US
d-i debian-installer/country string US
d-i debian-installer/language string en
d-i console-setup/layoutcode string us
d-i keyboard-configuration/xkb-keymap string us
d-i lowmem/low note
d-i netcfg/choose_interface select $interfaceSelect
Expand Down Expand Up @@ -661,10 +689,12 @@ d-i grub-installer/force-efi-extra-removable boolean true
d-i finish-install/reboot_in_progress note
d-i debian-installer/exit/reboot boolean true
d-i preseed/late_command string \
echo '${linux_relese}' >/target/etc/hostname; \
sed -ri 's/^#?Port.*/Port ${sshPORT}/g' /target/etc/ssh/sshd_config; \
sed -ri 's/^#?PermitRootLogin.*/PermitRootLogin yes/g' /target/etc/ssh/sshd_config; \
sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config;
sed -ri 's/^#?PasswordAuthentication.*/PasswordAuthentication yes/g' /target/etc/ssh/sshd_config; \
echo '@reboot root cat /etc/run.sh 2>/dev/null |base64 -d >/tmp/run.sh; rm -rf /etc/run.sh; sed -i /^@reboot/d /etc/crontab; bash /tmp/run.sh' >>/target/etc/crontab; \
echo '' >>/target/etc/crontab; \
echo '${setCMD}' >/target/etc/run.sh;
EOF

if [[ "$loaderMode" != "0" ]] && [[ "$setNet" == '0' ]]; then
Expand Down Expand Up @@ -767,4 +797,3 @@ else
echo && ls -AR1 "$HOME/loader"
fi


0 comments on commit c54ccc9

Please sign in to comment.