init commit
This commit is contained in:
193
plct.sh
Executable file
193
plct.sh
Executable file
@@ -0,0 +1,193 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "welcome to portable linux creation tool v1.0"
|
||||
|
||||
while true; do
|
||||
read -rp "disk (e.g. /dev/sdX): " disk
|
||||
if [ -b "$disk" ]; then
|
||||
break
|
||||
fi
|
||||
echo "$disk is incorrect or is not a disk"
|
||||
done
|
||||
|
||||
read -rp "choose mountpoint (/mnt/install): " mount
|
||||
if [ ! -n "$mount" ]; then
|
||||
mount="/mnt/install"
|
||||
fi
|
||||
|
||||
while true; do
|
||||
read -rp "gpt/mbr: " table
|
||||
table=${table,,}
|
||||
if [ "$table" = "gpt" ] || [ "$table" = "mbr" ]; then
|
||||
break
|
||||
fi
|
||||
echo "pls choose gpt or mbr"
|
||||
done
|
||||
|
||||
while true; do
|
||||
read -rp "efi? (yes/no): " efi
|
||||
efi=${efi,,}
|
||||
if [ "$efi" = "yes" ] || [ "$efi" = "no" ]; then
|
||||
break
|
||||
fi
|
||||
echo "pls choose yes or no"
|
||||
done
|
||||
|
||||
if [[ $disk =~ nvme[0-9]+n[0-9]+$ ]] || [[ $disk =~ mmcblk[0-9]+$ ]] || [[ $disk =~ loop[0-9]+$ ]]; then
|
||||
prefix="p"
|
||||
else
|
||||
prefix=""
|
||||
fi
|
||||
|
||||
prepare_debian() {
|
||||
declare -A need=(
|
||||
[debootstrap --help]=debootstrap
|
||||
[parted --help]=parted
|
||||
[mkfs.fat --help]=e2fsprogs
|
||||
[which mkfs.ext4]=mkfs.ext4
|
||||
[blkid]=blkid
|
||||
)
|
||||
|
||||
missing=()
|
||||
|
||||
read -rp "choose debian mirror (https://deb.debian.org/debian): " mirror
|
||||
if [ ! -n "$mirror" ]; then
|
||||
mirror="https://deb.debian.org/debian"
|
||||
fi
|
||||
|
||||
# prompt for debian version
|
||||
read -rp "choose debian version (bookworm): " choice
|
||||
if [ ! -n "$choice" ]; then
|
||||
choice="bookworm"
|
||||
fi
|
||||
|
||||
# checking if version of debian exists
|
||||
while true; do
|
||||
if curl -sS -o /dev/null -w "%{http_code}" -L "$mirror/dists/$choice" | grep -q "200"; then
|
||||
break
|
||||
fi
|
||||
echo "debian $choice was not found at $mirror/dists/$choice"
|
||||
read -rp "choose debian version (bookworm): " choice
|
||||
done
|
||||
|
||||
if [ ! -n "$choice" ]; then
|
||||
choice="bookworm"
|
||||
fi
|
||||
|
||||
echo "found debian $choice"
|
||||
for cmd in "${!need[@]}"; do
|
||||
if ! $cmd >/dev/null 2>&1; then
|
||||
missing+=("${need[$cmd]:-$cmd}")
|
||||
fi
|
||||
done
|
||||
|
||||
if ((${#missing[@]})); then
|
||||
echo "missing this things: ${missing[*]}" >&2
|
||||
echo "pls install them or run the script as root" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while true; do
|
||||
read -rp "everything is ok, type 'no' to cancel or 'yes' to preceed installation of debian $choice to $disk with $table table (DATA ON $disk WILL BE LOST): " proceeding
|
||||
if [ "$proceeding" = "no" ]; then
|
||||
echo "ok aborting"
|
||||
exit
|
||||
fi
|
||||
if [ "$proceeding" = "yes" ]; then
|
||||
echo "ok starting the installation"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
install_debian
|
||||
}
|
||||
|
||||
install_debian() {
|
||||
echo "unmounting $disk"
|
||||
umount $disk*
|
||||
|
||||
umount -R $mount
|
||||
rm -rf $mount
|
||||
mkdir $mount
|
||||
|
||||
echo "making $table table"
|
||||
if [ $table = "mbr" ]; then
|
||||
parted $disk --script mklabel msdos
|
||||
fi
|
||||
if [ $table = "gpt" ]; then
|
||||
parted $disk --script mklabel gpt
|
||||
fi
|
||||
|
||||
echo "making partitions"
|
||||
if [ $efi = "yes" ]; then
|
||||
parted $disk --script \
|
||||
mkpart primary fat32 1MiB 513MiB \
|
||||
set 1 esp on \
|
||||
mkpart primary ext4 513MiB 100%
|
||||
|
||||
mkfs.fat -F 32 ${disk}${prefix}1
|
||||
mkfs.ext4 ${disk}${prefix}2
|
||||
|
||||
echo "mounting"
|
||||
|
||||
mount ${disk}${prefix}2 $mount
|
||||
mkdir $mount/boot
|
||||
mount ${disk}${prefix}1 $mount/boot
|
||||
fi
|
||||
if [ $efi = "no" ]; then
|
||||
parted $disk --script \
|
||||
mkpart primary ext4 1MiB 100%
|
||||
mkfs.ext4 ${disk}${prefix}1
|
||||
|
||||
mount ${disk}${prefix}1 $mount
|
||||
fi
|
||||
|
||||
debootstrap $choice $mount $mirror
|
||||
|
||||
mount --bind /dev $mount/dev
|
||||
mount --bind /dev/pts $mount/dev/pts
|
||||
mount --bind /proc $mount/proc
|
||||
mount --bind /sys $mount/sys
|
||||
|
||||
RUN="chroot $mount"
|
||||
|
||||
$RUN apt update && $RUN apt install -y locales tzdata network-manager linux-image-amd64
|
||||
$RUN dpkg-reconfigure locales
|
||||
$RUN dpkg-reconfigure tzdata
|
||||
|
||||
while true; do
|
||||
read -rp "hostname: " hostname
|
||||
if [ -n "$hostname" ]; then
|
||||
break
|
||||
fi
|
||||
echo "pls set hostname"
|
||||
done
|
||||
echo $hostname > $mount/etc/hostname
|
||||
echo "updating root password"
|
||||
$RUN passwd root
|
||||
|
||||
if [ $efi = "yes" ]; then
|
||||
$RUN apt install -y grub-efi-amd64
|
||||
mkdir $mount/boot/efi
|
||||
$RUN grub-install --target=x86_64-efi --efi-directory=/boot --removable
|
||||
$RUN update-grub
|
||||
efi_uuid=$(blkid -s UUID -o value ${disk}${prefix}1)
|
||||
root_uuid=$(blkid -s UUID -o value ${disk}${prefix}2)
|
||||
echo "UUID=$efi_uuid /boot/ vfat umask=0077 0 1" >> $mount/etc/fstab
|
||||
echo "UUID=$root_uuid / ext4 defaults,noatime 0 1" >> $mount/etc/fstab
|
||||
fi
|
||||
if [ $efi = "no" ]; then
|
||||
$RUN apt-get install -y grub-pc
|
||||
$RUN grub-install $disk
|
||||
$RUN update-grub
|
||||
root_uuid=$(blkid -s UUID -o value ${disk}${prefix}1)
|
||||
echo "UUID=$root_uuid / ext4 defaults,noatime 0 1" >> $mount/etc/fstab
|
||||
fi
|
||||
|
||||
echo 'done! chrooted you into installed system. type "exit" to finish the installation'
|
||||
$RUN /bin/bash
|
||||
|
||||
umount -R $mount
|
||||
}
|
||||
|
||||
prepare_debian
|
||||
Reference in New Issue
Block a user