通过Shell脚本安装ArchLinux-持续更新中

x33g5p2x  于2022-08-17 转载在 Linux  
字(4.5k)|赞(0)|评价(0)|浏览(758)

启动系统后,按顺序运行boot.bash域setup.bash即可,需进行配置
config.bash

# ACTUAL/VIRTUAL
SYS_ENV='VIRTUAL'
# DEFAULT
DISK_NAME="DEFAULT"
# default: 512M
BOOT_SIZE="512M"
# default: 32G
SWAP_SIZE="32G"
# default: 150G
HOME_SIZE="150G"
# default: 300G
ROOT_SIZE="300G"

utils/bash.bash

#!/bin/bash
# check system network status
function network() {
  local timeout=1
  local target=www.baidu.com
  local ret_code=`curl -I -s --connect-timeout ${timeout} ${target} -w %{http_code} | tail -n1`
  if [ "x$ret_code" = "x200" ]; then
    return 1
  else
    return 0
  fi
  return 0
}

boot.bash

# import system variables
source config.bash
source utils/base.bash

network
if [ $? != "1" ]; then
# @TODO: try to connnect network
echo "please connect to network first"
exit 0
fi

fdisk -l | grep "^Disk /dev/[sh]d[a-z]" | awk  '{print $2}' | sed "s@:@@g"
read -p "Your choice PARTDISK above:" PARTDISK
if [ $PARTDISK == quit ];then
  echo "quit..."
  exit 0
fi
echo "select the method you want to use to format disk:
1:use config file, 
2:use the system portion-BOOT:512M, SWAP:memory capacity, HOME:70% remaning, ROOT:30% remaining):"
read FORMAT_SELECTION

case $FORMAT_SELECTION in
    1)
        echo "you choose 1, continue"
        ;;
    2)
        BOOT_SIZE="512M"
        MemTotal=$(cat /proc/meminfo |grep 'MemTotal' |awk -F : '{print $2}' |sed 's/^[ \t]*//g')
        SWAP_SIZE=$MemTotal
        DISK_SIZE=$(fdisk -l | grep 'Disk /dev/sda' | awk -F , '{print $1}' | awk -F : '{print $2}' | sed 's/[ ]*//g' | awk -F G '{print $1}')
        DISK_INFO=$(fdisk -l | grep 'Disk /dev/sda' | awk -F , '{print $1}' | awk -F : '{print $2}' | sed 's/[ ]*//g')
        echo "disk_size: $DISK_SIZE, disk_unit: $DISK_UNIT"
        HOME_SIZE=`echo "$DISK_SIZE * 0.7" | bc`${DISK_INFO:0-3}
        ROOT_SIZE=`echo "$DISK_SIZE * 0.3" | bc`${DISK_INFO:0-3}
        echo "BOOT_SIZE: $BOOT_SIZE,"
        echo "SWAP_SIZE: $SWAP_SIZE,"
        echo "HOME_SIZE: $HOME_SIZE,"
        echo "ROOT_SIZE: $ROOT_SIZE,"
        sleep 3
        ;;
    *)
        echo "error"
esac
until fdisk -l | grep -o "^Disk /dev/[sh]d[a-z]" | grep "^Disk ${PARTDISK}$" &> /dev/null ;do
  read -p "wrong choice Your choice again:" PARTDISK
done
  read -p "Will destroy all data continue[y/n]:" CHOICE
until [ $CHOICE == "y" -o $CHOICE == "n" ];do
  read -p "Will destroy all data continue[y/n]:" CHOICE
done
[ $CHOICE == n ] && echo "quit..." && exit 0;
for DISK in `mount | grep "/dev/[sh]d[a-z]" | awk '{print $1}'`;do
fuser -km $DISK
umount $DISK && echo "$DISK umount ok"
done
swapoff $PARTDISK2

dd if=/dev/zero of=$PARTDISK bs=512 count=1&>/dev/null
partprobe $PARTDISK
sync&>/dev/null
sleep 2
# BOOT_SIZE,SWAP_SIZE,HOME_SIZE,ROOT_SIZE
echo "n
p
1

+512M
n
p
2

+8G
n
p
3

+70G
n
p
3

t
3
82
w"|fdisk $PARTDISK &>/dev/null
partprobe $PARTDISK

# partition format
mkfs.fat -F32 ${PARTDISK}1
mkswap ${PARTDISK}2
swapon ${PARTDISK}2
echo Y | mkfs.ext4 ${PARTDISK}3
echo Y | mkfs.ext4 ${PARTDISK}4
# mount partition
mount ${PARTDISK}4 /mnt
if [ -d /mnt/boot/EFI  ];then
  echo /mnt/boot/EFI exist
else
  mkdir -p /mnt/boot/EFI
fi
mount ${PARTDISK}1 /mnt/boot/EFI
if [ -d /mnt/home  ];then
  echo /mnt/home exist
else
  mkdir /mnt/home
fi
mount ${PARTDISK}3 /mnt/home
# replace domestic image
reflector -c China -a 5 --sort rate --save /etc/pacman.d/mirrorlist
echo Y | sudo pacman -Sy archlinux-keyring
pacstrap /mnt base base-devel linux linux-firmware

genfstab -U /mnt >> /mnt/etc/fstab
# enter the new system
cp setup.bash /mnt
arch-chroot /mnt

setup.bash

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc
echo Y | sudo pacman -Sy vim expect
sed -i 's/#en_US.UTF-8/en_US.UTF-8/g' /etc/locale.gen
sed -i 's/#zh_CN.UTF-8/zh_CN.UTF-8/g' /etc/locale.gen
locale-gen
echo "LANG=en_US.UTF-8" > /etc/locale.conf
echo "input the hostname you want to use:"
read HOST_NAME
echo $HOST_NAME > /etc/lcoale.conf
# set hosts
echo "
127.0.0.1 localhost
::1 localhost
127.0.0.1 $HOST_NAME.localdomain $HOST_NAME
" > /etc/hosts
echo "input the root password you want to use:"
read ROOT_PASSWORD
expect<<-EOF
passwd
expect "New password" {send "${ROOT_PASSWORD}\n";exp_continue}
expect "Retype new password" {send "${ROOT_PASSWORD}\n";}
EOF
echo "set root password successfully"
echo "input the group name you want to use:"
read GROUP_NAME
groupadd $GROUP_NAME
echo "add group successfully"
echo "input the user name you want to use:"
read USER_NAME
useradd $USER_NAME -g $GROUP_NAME -m
echo "input the user password you want to use:"
read USER_PASSWORD
expect<<-EOF
passwd $USER_NAME
expect "New password" {send "${USER_PASSWORD}\n";exp_continue}
expect "Retype new password" {send "${USER_PASSWORD}\n";}
EOF

未来计划加入的内容如下:

  • awesome wm 及其详细配置
  • neovim 及其详细配置
  • rime
  • alacritty
  • linux系统下软件存在问题及其解决方案

相关文章

最新文章

更多