Last active
April 19, 2022 07:48
-
-
Save sulincix/82561e7162224e9697398029f1d77121 to your computer and use it in GitHub Desktop.
replace your existing os with archlinux server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is experimental and may damage your system. | |
# Please backup files before run this script. | |
set -e -x | |
umount -lf /boot/efi || true | |
mkdir -p /work ; cd /work | |
wget -c https://gitlab.com/tearch-linux/applications-and-tools/archstrap/-/raw/master/archstrap.sh -O /bin/archstrap | |
chmod +x /bin/archstrap | |
apt update | |
apt install busybox-static zstd -y | |
archstrap /rootfs | |
sed -i 's/^CheckSpace/#&/g' /rootfs/etc/pacman.conf | |
mount --bind /dev/ /rootfs/dev | |
mount --bind /sys/ /rootfs/sys | |
mount --bind /proc/ /rootfs/proc | |
mount --bind /run/ /rootfs/run | |
chroot /rootfs pacman-key --init | |
chroot /rootfs pacman-key --populate archlinux | |
chroot /rootfs pacman -S networkmanager linux openssh grub --noconfirm | |
chroot /rootfs systemctl enable NetworkManager | |
chroot /rootfs systemctl enable sshd | |
set +e -x | |
cp /etc/fstab /rootfs/etc/fstab | |
grep "^[a-z]*:x:[0-9][0-9][0-9][0-9]:" /etc/passwd >> /rootfs/etc/passwd | |
grep "^[a-z]*:x:[0-9][0-9][0-9][0-9]:" /etc/passwd | cut -f 1 -d ":" | while read line ; do | |
grep "^$line:" /etc/shadow >> /rootfs/etc/shadow | |
user=$(echo "$line" | cut -f 1 -d ":") | |
chroot /rootfs usermod -aG wheel "$user" | |
done | |
sed -i "/^root:.*/d" /rootfs/etc/shadow | |
grep -e "^root:.*" /etc/shadow >> /rootfs/etc/shadow | |
sync | |
busybox mkdir -p /debian | |
cp $(which busybox) /debian/busybox | |
for dir in $(ls / | grep -v rootfs| grep -v debian | grep -v dev| grep -v sys| grep -v proc| grep -v run| grep -v tmp| grep -v home) ; do | |
/debian/busybox mv /$dir /debian/$dir | |
/debian/busybox cp -prf /rootfs/$dir / | |
done | |
/debian/busybox cp -prf /debian/boot/grub /boot/grub | |
grub-mkconfig -o /boot/grub/grub.cfg | |
sync | |
reboot -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment