Skip to content

Instantly share code, notes, and snippets.

@alicavus
Last active June 29, 2022 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alicavus/9f6736d57992eb6c7560b7a3da812f05 to your computer and use it in GitHub Desktop.
Save alicavus/9f6736d57992eb6c7560b7a3da812f05 to your computer and use it in GitHub Desktop.
Archman BTRFS kurucu
#!/bin/bash
die(){
msg=$*
echo -e "\e[1;31m${msg}\033[0m"
rm -f /tmp/archman.*
umount /mnt/boot /mnt/home /mnt/efi /mnt
exit
}
ask (){
msg=$*
echo -e "\n"
read -p "${msg} [e/H]" -n 1 -r
echo -e "\n"
}
notice (){
msg=$*
echo -e "\e[1;37m :: ${msg}\033[0m"
}
success (){
[[ $? -ne 0 ]] && die "\e[1;31mBir hata oluştu\033[0m" || echo -e "\e[1;32mİşlem başarılı\033[0m \n"
}
lsblk="/usr/bin/lsblk -rn -o "
[[ `whoami` != "root" ]] && die "Yetkisiz kullanıcı"
tmpfile=`mktemp /tmp/archman.XXXXXX`
${lsblk} "NAME,TYPE,FSTYPE" | while read ln; do
line=($ln)
[[ ${#line[@]} -ge 3 ]] && [[ ${line[1]} == "part" ]] && [[ ${line[2]} == "btrfs" ]] && btrfs_parts+=("${line[0]}")
echo "${btrfs_parts[@]}" > $tmpfile
done
parts=(`cat $tmpfile`)
rm $tmpfile
target=""
[[ ${#parts[@]} -eq 0 ]] && die "BTRFS bölümü bulunamadı"
for part in "${parts[@]}"; do
echo -e "\e[1;32mBTRFS bölümü bulundu:\033[0m /dev/${part}\n"
ask "Bölüm kurulum için kullanılsın mı?"
[[ $REPLY =~ ^[Ee]$ ]] && target="/dev/${part}" && break
done
[[ -z "${target}" ]] && die "Kurulumu gerçekleştirmek için bölüm seçmelisiniz"
while :; do
mountp=`${lsblk} "MOUNTPOINTS" ${target}`
[[ -z ${mountp} ]] && break
[[ -n ${mountp} ]] && ask "${target} bölümü bağlama noktası: ${mountp}. Ayırılsın mı?"
[[ $REPLY != "e" ]] && [[ $REPLY != "E" ]] && die "Devam etmek için ayırmalısınız."
umount -f "${target}"
done
mountopt=""
ask "BTRFS için zstd sıkıştırması uygulansın mı?"
[[ $REPLY =~ ^[Ee]$ ]] && mountopt=",compress-force=zstd"
notice "BTRFS bölümü /mnt dizinine bağlanıyor" && mount -v ${target} /mnt && success
[[ -e "/mnt/archman" ]] && rm -Rfv "/mnt/archman"
mkdir "/mnt/archman"
notice "Altbirimler oluşturuluyor" && btrfs subvolume create "/mnt/archman/@" && btrfs subvolume create "/mnt/archman/@home" && success
notice "BTRFS bölümünün altbirimleri bağlanıyor"
umount /mnt && mount -vo "subvol=archman/@${mountopt}" ${target} /mnt && mkdir -v /mnt/boot /mnt/home && mount -vo "subvol=archman/@home${mountopt}" ${target} /mnt/home && success
notice "airootfs.sfs imajı açılıyor"
unsquashfs -f -d /mnt /run/archiso/bootmnt/arch/x86_64/airootfs.sfs
success
[[ -h /mnt/etc/localtime ]] && unlink /mnt/etc/localtime
notice "systemd yapılandırması" && systemd-firstboot --force --root=/mnt --locale=tr_TR.UTF-8 --keymap=trq --timezone=Europe/Istanbul && success
platform="bios"
[[ -d /sys/firmware/efi/efivars ]] && platform="uefi"
if [[ ${platform} == "uefi" ]]; then
[[ ! -e /mnt/efi ]] && mkdir -v /mnt/efi
tmpfile=`mktemp /tmp/archman.XXXXXX`
${lsblk} "NAME,TYPE,FSTYPE,PARTTYPE,MOUNTPOINTS" | while read ln; do
line=($ln)
[[ ${#line[@]} -eq 4 ]] && [[ ${line[1]} == "part" ]] && [[ ${line[2]} == "vfat" ]] && [[ ${line[3]} == "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" ]] && esp_parts+=("${line[0]}")
echo "${esp_parts[@]}" > $tmpfile
done
parts=(`cat $tmpfile`)
rm $tmpfile
esp_target=""
[[ ${#parts[@]} -eq 0 ]] && die "EFI bölümü bulunamadı"
for part in "${parts[@]}"; do
echo -e "\e[1;32mEFI bölümü bulundu:\033[0m /dev/${part}\n"
ask "Bölüm kurulum için kullanılsın mı?"
[[ $REPLY =~ ^[Ee]$ ]] && esp_target="/dev/${part}" && break
done
[[ -z "${esp_target}" ]] && die "Kurulumu gerçekleştirmek için bölüm seçmelisiniz"
mount -v ${esp_target} /mnt/efi && success
fi
notice "İşlemci microcode dosyaları kopyalanıyor" && cp -v /run/archiso/bootmnt/arch/boot/*.img /mnt/boot && success
notice "linux çekirdeği kopyalanıyor" && cp -v /run/archiso/bootmnt/arch/boot/x86_64/vmlinuz* /mnt/boot && success
notice "fstab dosyası oluşturuluyor"
genfstab -t PARTUUID /mnt | tee /mnt/etc/fstab
success
notice "varsayılan mkinitcpio dosyası oluşturuluyor"
cat << EOF | tee /mnt/etc/mkinitcpio.conf
# vim:set ft=sh
# MODULES
# The following modules are loaded before any boot hooks are
# run. Advanced users may wish to specify all system modules
# in this array. For instance:
# MODULES=(piix ide_disk reiserfs)
MODULES=()
# BINARIES
# This setting includes any additional binaries a given user may
# wish into the CPIO image. This is run last, so it may be used to
# override the actual binaries included by a given hook
# BINARIES are dependency parsed, so you may safely ignore libraries
BINARIES=()
# FILES
# This setting is similar to BINARIES above, however, files are added
# as-is and are not parsed in any way. This is useful for config files.
FILES=()
# HOOKS
# This is the most important setting in this file. The HOOKS control the
# modules and scripts added to the image, and what happens at boot time.
# Order is important, and it is recommended that you do not change the
# order in which HOOKS are added. Run 'mkinitcpio -H <hook name>' for
# help on a given hook.
# 'base' is _required_ unless you know precisely what you are doing.
# 'udev' is _required_ in order to automatically load modules
# 'filesystems' is _required_ unless you specify your fs modules in MODULES
# Examples:
## This setup specifies all modules in the MODULES setting above.
## No raid, lvm2, or encrypted root is needed.
# HOOKS=(base)
#
## This setup will autodetect all modules for your system and should
## work as a sane default
# HOOKS=(base udev autodetect block filesystems)
#
## This setup will generate a 'full' image which supports most systems.
## No autodetection is done.
# HOOKS=(base udev block filesystems)
#
## This setup assembles a pata mdadm array with an encrypted root FS.
## Note: See 'mkinitcpio -H mdadm' for more information on raid devices.
# HOOKS=(base udev block mdadm encrypt filesystems)
#
## This setup loads an lvm2 volume group on a usb device.
# HOOKS=(base udev block lvm2 filesystems)
#
## NOTE: If you have /usr on a separate partition, you MUST include the
# usr, fsck and shutdown hooks.
HOOKS=(base udev autodetect modconf block filesystems keyboard fsck)
# COMPRESSION
# Use this to compress the initramfs image. By default, zstd compression
# is used. Use 'cat' to create an uncompressed image.
#COMPRESSION="zstd"
#COMPRESSION="gzip"
#COMPRESSION="bzip2"
#COMPRESSION="lzma"
#COMPRESSION="xz"
#COMPRESSION="lzop"
#COMPRESSION="lz4"
# COMPRESSION_OPTIONS
# Additional options for the compressor
#COMPRESSION_OPTIONS=()
EOF
success
notice "initramfs oluşturuluyor" && arch-chroot /mnt mkinitcpio -p linux && success
def_user="liveuser"
user_name=""
while [[ -z ${user_name} ]]; do
read -rp "Kullanıcı adı giriniz: [a-z0..9]"
[[ $REPLY =~ ^[[:lower:]_][[:lower:][:digit:]_-]{2,15}$ ]] && user_name=$REPLY
done
notice "Kullanıcı adı (login): ${user_name}"
notice "Varsayılan kullanıcı ${def_user} siliniyor" && arch-chroot /mnt userdel -rf ${def_user} && success
notice "Yeni kullanıcı ${user_name} oluşturuluyor" && arch-chroot /mnt useradd -mUG users,sys,adm,wheel,network,storage,power,audio,video,scanner,optical,rfkill -s /bin/zsh ${user_name} && success
notice "${user_name} kullanıcı şifresi siliniyor" && arch-chroot /mnt passwd -du ${user_name} && success
notice "sudo ayarlaması yapılıyor" && chmod +w /mnt/etc/sudoers.d/g_wheel && echo "%wheel ALL=(ALL:ALL) ALL" | tee /mnt/etc/sudoers.d/g_wheel && chmod -w /mnt/etc/sudoers.d/g_wheel && success
notice "Otomatik giriş ayarlanıyor" && sed "s/User=${def_user}/User=${user_name}/" /run/archiso/airootfs/etc/sddm.conf | tee /mnt/etc/sddm.conf && success
notice "Türkçe yerel ayarlaması yapılıyor" && sed "s/#tr_TR/tr_TR/g" /run/archiso/airootfs/etc/locale.gen | tee /mnt/etc/locale.gen && arch-chroot /mnt locale-gen && success
notice "hostname: " && echo "${user_name}-pc" | tee /mnt/etc/hostname && success
cat << EOF | tee /mnt/etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 localdomain.${user_name}-pc ${user_name}-pc
EOF
success
notice "Calamares kaldırılıyor" && arch-chroot /mnt pacman -Rsn --noconfirm calamares
grub_dev=`${lsblk} PKNAME ${target}`
grub_efi=""
grub_bios=""
[[ ${platform} == "uefi" ]] && grub_efi="--efi-directory=/efi --bootloader-id=Archman" || grub_bios="/dev/${grub_dev}"
notice "Önyükleyici kuruluyor" && arch-chroot /mnt grub-install --boot-directory=/boot ${grub_efi} ${grub_bios} && success
#os prober kurulumlarda hata verebiliyor
notice "os-prober devre dışı bırakılıyor" && sed "s|GRUB_DISABLE_OS_PROBER=false|GRUB_DISABLE_OS_PROBER=true|" /run/archiso/airootfs/etc/default/grub | tee /mnt/etc/default/grub
notice "Önyükleyici yapılandırma dosyası oluşturuluyor" && arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg && success
notice "os-prober tekrar etkinleştiriliyor" && cp -v /run/archiso/airootfs/etc/default/grub /mnt/etc/default/grub && success
umount -v /mnt/boot /mnt/home /mnt/efi /mnt && success
ask "Kurulum tamamlandı. Sistem tekrar başlatılsın mı?"
[[ $REPLY =~ ^[Ee]$ ]] && systemctl reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment