arch_script/install/linux/linux.sh

112 lines
4.9 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
loadkeys jp106
#キーボードを日本語配列へ変更
printf "\nPlease enter your username\n"
read -r home_username
printf "Please enter your password\n"
read -sr home_password
printf "Please enter Hostname\n"
read -r hostname1
fdisk -l
#ディスク一覧表示
printf "\nWhat disk do you want to install to? example:/dev/sda \n"
read -r installdisk
printf "Choose the file system to use for your root partition. (ext4, btrfs)\n"
read -r filesystem
printf "Choose the kernel you want to use. (linux, zen, lts)\n"
read -r kernel
#インストールするディスクを入力
printf "%s (%s) is selected as the disk to install. Are you sure you want to perform the partition operation? (yes or no) \n" "$installdisk" "$filesystem"
read -r check1
#インストールするディスクを確認
if [ "$check1" == "yes" ]; then
printf "%s" "$installdisk" >> ./installdisk.txt
if [ "$(grep "nvme" -rl ./installdisk.txt)" == "./installdisk.txt" ]; then
d1="${installdisk}p1"
d2="${installdisk}p2"
elif [ "$(grep "mmcblk" -rl ./installdisk.txt)" == "./installdisk.txt" ]; then
d1="${installdisk}p1"
d2="${installdisk}p2"
else
d1="${installdisk}1"
d2="${installdisk}2"
fi
#1,2の番号をつけるのとディスクの種類を判断
sgdisk -o "$installdisk" -g
sgdisk -n 1:0:+1024M -t 1:ef00 -c 1:"EFI System" "$installdisk"
sgdisk -n 2:0: -t 2:8300 -c 2:"Linux filesystem" "$installdisk"
#パーティション操作
mkfs.vfat -F32 "$d1"
if [ "$filesystem" == "ext4" ]; then
mkfs.ext4 "$d2"
mount "$d2" /mnt
elif [ "$filesystem" == "btrfs" ]; then
mkfs.btrfs -f "$d2"
mount "$d2" /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@swap
umount "$d2"
mount "$d2" /mnt -o subvol=@
mkdir /mnt/home
mkdir /mnt/swap
mount "$d2" /mnt/home -o subvol=@home
mount "$d2" /mnt/swap -o subvol=@swap
else
mkfs.ext4 "$d2"
mount "$d2" /mnt
fi
#フォーマット
mkdir /mnt/boot
mount "$d1" /mnt/boot
#マウント
reflector --sort rate --country jp --latest 10 --save /etc/pacman.d/mirrorlist
#ミラーリストかえたい!!
pacman -Sy
pacman -S --noconfirm archlinux-keyring
if [ "$kernel" == "linux" ]; then
pacstrap /mnt base base-devel linux linux-firmware linux-headers btrfs-progs ntfs-3g exfatprogs grub dosfstools efibootmgr networkmanager dialog vi nano intel-ucode
elif [ "$kernel" == "zen" ]; then
pacstrap /mnt base base-devel linux-zen linux-firmware linux-zen-headers btrfs-progs ntfs-3g exfatprogs grub dosfstools efibootmgr networkmanager dialog vi nano intel-ucode
elif [ "$kernel" == "lts" ]; then
pacstrap /mnt base base-devel linux-lts linux-firmware linux-lts-headers btrfs-progs ntfs-3g exfatprogs grub dosfstools efibootmgr networkmanager dialog vi nano intel-ucode
else
pacstrap /mnt base base-devel linux linux-firmware linux-headers btrfs-progs ntfs-3g exfatprogs grub dosfstools efibootmgr networkmanager dialog vi nano intel-ucode
fi
#パッケージインストール
genfstab -U /mnt >> /mnt/etc/fstab
#fstab作成
arch-chroot /mnt /usr/bin/sed -i -e 's/#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen
arch-chroot /mnt /usr/bin/sed -i -e 's/#ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/g' /etc/locale.gen
#localeの設定
arch-chroot /mnt /usr/bin/locale-gen
#localeの設定適用
printf "LANG=en_US.UTF-8" > /mnt/etc/locale.conf
#LANG環境変数設定
printf "[Time]\nNTP=ntp.nict.jp" > /mnt/etc/systemd/timesyncd.conf
#NTPサーバー書き込み
arch-chroot /mnt /usr/bin/grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=arch --recheck
arch-chroot /mnt /usr/bin/grub-mkconfig -o /boot/grub/grub.cfg
#grubインストール
arch-chroot /mnt /usr/bin/systemctl enable NetworkManager.service
#NetworkManager有効化
printf "KEYMAP=jp106" > /mnt/etc/vconsole.conf
#日本語配列の設定
printf "%s" "$hostname1" > /mnt/etc/hostname
#ホストネームを変更
arch-chroot /mnt /usr/bin/useradd -d /home/"$home_username" -m "$home_username"
printf "%s" "$home_password" | arch-chroot /mnt /usr/bin/passwd --stdin "$home_username"
#ユーザー作成とパスワード設定
arch-chroot /mnt /usr/bin/usermod -aG wheel "$home_username"
#wheelグループへ所属
arch-chroot /mnt /usr/bin/sed -i -e 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/g' /etc/sudoers
curl -Lk 'https://192.168.1.64:8443/www/suti7/arch/initial.sh' -o "/mnt/home/$home_username/initial.sh"
chown 1000:1000 "/mnt/home/$home_username/initial.sh"
chmod 700 "/mnt/home/$home_username/initial.sh"
#visudo設定
printf "\n\nInstallation is complete. Please reboot.\n"
else
printf "Installation canceled. \n"
fi