我正在尝试为我自己的基于 Arch Linux 发行版构建自己的安装程序,但我无法摆脱这个错误!!!!
我知道它可以是一个开放的 if 或 while 或 do 或其他东西,但我找不到它!!!!我尝试使用 notepad++ 和 dos2unix 进行转换,但仍然出现相同的错误!
install.sh: line 185: syntax error: unexpected end of file
这是代码:
#!/bin/bash
echo -e "Hello there. So, you want to install DogOS...\nWell, thats my job.\nMy name is Captain Install, and im going to help install your new home and move your best friend. Doggy Linux!"
sleep 2
echo "Lets begin!"
read -p "Press enter to continue"
clear
echo "So, first i need your keyboard layout, will display a loooooonnnnnggggggg list of all layouts, and search your layout, then write it in this terminal in the input 'Layout> '."
read -p "Press enter to continue"
ls /usr/share/kbd/keymaps/**/*
read -p "Layout> " layout
loadkeys $layout
clear
sleep 1
echo "Verifying if your system is booted in EFI or BIOS/CSM."
sleep 1
echo "Verifying if your system is booted in EFI or BIOS/CSM.."
sleep 1
echo "Verifying if your system is booted in EFI or BIOS/CSM..."
sleep 1
if [ -d "/sys/firmware/efi/efivars" ]
then
EFI="True"
else
EFI="False"
fi
echo "RESULT: EFI=$EFI"
sleep 2
clear
echo "Now it's the network step, please configure the network in KDE and then press enter to move on..."
read -p "Press enter to check the internet connection..."
echo "Testing internet please standby..."
ping www.google.com -c 5
if [ "$?" = "0" ]
then
echo "Connected with sucess, with code $?"
else
echo "ERROR: NOT CONNECTED, CODE EXIT $?"
exit 1
fi
timedatectl set-ntp true
fdisk -l
read -p "Disk (exemple: /dev/sda)> " disk_to_part
while true:
echo "1 - Entire disk (WILL BE ERASE ALL OF DATA)"
echo "2 - Manual (using fdisk)"
read -p "Option> " part_mode
if [ "$part_mode" = "1" ]
then
if [ "$EFI" = "True" ]
then
parted $disk_to_part -- mklabel gpt
parted $disk_to_part -- mkpart primary 512Mib -1Gib
parted $disk_to_part -- mkpart primary linux-swap -1Gib 100%
parted $disk_to_part -- mkpart ESP fat32 1Mib 512Mib
parted $disk_to_part -- set 3 esp on
mkfs.ext4 -L dogos {$disk_to_part}1
mkswap -L swap {$disk_to_part}2
mkfs.fat -F 32 -n boot {$disk_to_part}3
fi
if [ "$EFI" = "False" ]
then
parted $disk_to_part -- mklabel msdos
parted $disk_to_part -- mkpart primary 1Mib -1Gib
parted $disk_to_part -- mkpart primary linux-swap -1Gib 100%
mkfs.ext4 -L dogos {$disk_to_part}1
mkswap -L swap {$disk_to_part}2
fi
break
fi
if [ "$part_mode" = "2" ]
then
fdisk $disk_to_part
read -p "ROOT_PART=" root_part
read -p "SWAP_PART=" swap_part
if [ "$EFI" = "True" ]
then
read -p "UEFI_PART=" uefi_part
fi
if [ "$EFI" = "True" ]
then
mkfs.ext4 -L dogos $root_part
mkswap -L swap $swap_part
mkfs.fat -F 32 -n boot $uefi_part
fi
if [ "$EFI" = "False" ]
then
mkfs.ext4 -L dogos $root_part
mkswap -L swap $swap_part
fi
break
else
echo "Not a option"
fi
echo "Partition done"
sleep 2
fdisk -l
#ROOT=dogos
#SWAP=swap
#UEFI=boot
if [ "$EFI" = "True" ]
then
mount /dev/disk/by-label/dogos /mnt
mkdir -p /mnt/boot
mount /dev/disk/by-label/boot /mnt/boot
swapon /dev/disk/by-label/swap
fi
if [ "$EFI" = "False" ]
then
mount /dev/disk/by-label/dogos /mnt
swapon /dev/disk/by-label/swap
fi
pacman -Syy --noconfirm
pacman -Syy --noconfirm archlinux-keyring
until pacstrap /mnt base linux linux-firmware
do
pacman -Syy --noconfirm
echo "Trying again..."
done
genfstab -U /mnt >> /mnt/etc/fstab
read -p "Region: " region
ls /usr/share/zoneinfo/$region/
read -p "City: " city
arch-chroot /mnt ln -sf /usr/share/zoneinfo/$region/$city /etc/localtime
arch-chroot /mnt hwclock --systohc
echo "KEYMAP=$layout" > /mnt/etc/vconsole.conf
read -p "Hostname> " hostname
echo "$hostname" > /mnt/etc/hostname
echo "root:root" | chpasswd
arch-chroot /mnt pacman -S dosfstools os-prober mtools network-manager-applet networkmanager wpa_supplicant wireless_tools dialog sudo nano vim ed
if [ "$EFI" = "True" ]
then
arch-chroot /mnt pacman -S grub efibootmgr
arch-chroot /mnt grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB --recheck
arch-chroot /mnt cp /etc/default/grub /etc/default/.grub.bak
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
fi
if ["$EFI" = "False" ]
then
arch-chroot /mnt pacman -S grub
arch-chroot /mnt grub-install --target=i386-pc $disk_to_part --recheck
arch-chroot /mnt cp /etc/default/grub /etc/default/.grub.bak
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
fi
echo "The installation is done!"
sleep 5
arch-chroot /mnt exit
umount -R /mnt
reboot
PS:我对 bash 脚本有点陌生,有人可以帮助我吗?
答案1
网站https://www.shellcheck.net/是处理这类事情的一个很好的工具。
就您而言,您的此处格式错误while
:
while true:
echo "1 - Entire disk (WILL BE ERASE ALL OF DATA)"
echo "2 - Manual (using fdisk)"
read -p "Option> " part_mode
你可以做任何一个,while true; do ...
或者你可以做,while :; do ...
因为两者true
都是:
真正的命令,总是成功的。但你不能这样做,while true:
因为true:
这不是一个真正的命令,并且在任何情况下, while 的语法都需要do
:
while condition; do something; done