Skip to content

Instantly share code, notes, and snippets.

@protonesso

protonesso/setup

Created Jul 19, 2020
Embed
What would you like to do?
#!/usr/bin/env bash
print_welcome() {
cat <<-EOF
Welcome to Ataraxia Linux/$(uname -m) installation program!
This program will install Ataraxia Linux on your computer.
Make sure your disk size is more than 5 gigabytes.
EOF
echo -e "\e[5m\e[91mWARNING!\e[39m\e[0m ALL FILES WILL BE DESTROYED!\n"
}
select_hostname() { read -p "Figure out system hostname (selected: $hostname) " -r hostname; }
select_timezone() { read -p "System timezone (selected: $timezone) " -r timezone; }
list_kmaps() {
local kmaps="$(find /usr/share/keymaps -type f -iname "*.map.gz" -printf "%f " | sed 's|.map.gz||g' | sort | uniq)"
echo "$kmaps"
}
select_kmap() {
read -p "What keyboard layout will you use? [Type 'l' to list keymaps, selected: $kmap] " -r ikmap
case $ikmap in
l) list_kmaps ;;
*) kmap="$ikmap" ;;
esac
}
select_interfaces() {
local avail="$(find /sys/class/net -type l -printf "%f " | sort | uniq)"
echo "Available network interfaces: $avail"
read -p "Which network interfaces do you want to use (Type 's' to skip, selected: $if) " -r if
case $if in
lo) echo "Cannot use following interface: $if"; select_interfaces ;;
s) ifskip="yes"; return 0 ;;
*) true ;;
esac
select_interfaces_b
}
select_interfaces_b() {
echo "Available network types: dhcp, static, wireless"
read -p "Your type of network (selected: $ifmode) " -r ifmode
case $ifmode in
dhcp)
cat > /tmp/net <<-EOF
auto lo $if
iface lo inet loopback
iface $if inet dhcp
EOF
;;
static)
read -p "Your static address (eg. '192.168.0.101') " -r iaddress
read -p "Your netmask (eg. '255.255.255.0') " -r inetmask
read -p "Your gateway (eg. '192.168.0.1') " -r igateway
cat > /tmp/net <<-EOF
auto lo $if
iface lo inet loopback
iface $if inet static
address $iaddress
netmask $inetmask
gateway $igateway
EOF
;;
wireless)
read -p "Your Wi-Fi network name " -r iessid
read -p "Your Wi-Fi password " -s -r ipsk
cat > /tmp/net <<-EOF
auto lo $if
iface lo inet loopback
iface $if inet dhcp
wpa-ssid $iessid
wpa-psk $ipsk
EOF
;;
*)
echo "Unknown network type, try again"
select_interfaces_b
esac
}
configure_password() {
read -sp "Password for root account (will not shown) " -r password
if [ -z "$password" ]; then
echo -e "\nPlease specify password for root account"
configure_password
fi
read -sp "Repeat the password " -r passwordtwo
if [ "$password" != "$passwordtwo" ]; then
echo -e "\nPassword do not match"
configure_password
fi
echo -e "\n"
export password
}
configure_users_b() {
read -sp "Password for $user (will not shown) " -r userpassword
if [ -z "$userpassword" ]; then
echo -e "\nPlease specify password for your account"
configure_users_b
fi
read -sp "Repeat the password " -r userpasswordtwo
if [ "$userpassword" != "$userpasswordtwo" ]; then
echo -e "\nPassword do not match"
cconfigure_users_b
fi
echo -e "\n"
export userpassword
}
configure_users() {
local iskip
read -p "Add new user, figure out the name (eg, 'foo') " -r user
if [ -z "$user" ]; then
read -p "Do you want to skip users creation? (yes/no) " -r iskip
case $iskip in
yes|y) userskip="yes"; return 0 ;;
no|n|*) configure_users ;;
esac
fi
export user
configure_users_b
}
select_disk() {
local avail="$(find /sys/block -type l -printf "%f " | sort | uniq)"
echo "Available disks: $avail"
read -p "Which disk do you want to use? " -r disk
if [ -z "$disk" ]; then
echo "Please select disk to use for installation"
select_disk
fi
export disk
}
install_os() {
local confirm efi efibitness filtered
echo -e "\n"
read -p "Everything needed is ready. Type 'yes' to install Ataraxia on your computer (yes/no) " -r confirm
case $confirm in
yes|y) true ;;
no|n|*) exit 0 ;;
esac
if [ -d "/sys/firmware/efi" ]; then
efi="yes"
efibitness="$(cat /sys/firmware/efi/fw_platform_size)"
else
efi="no"
fi
echo "Searching for install media"
mount -n -r -t iso9660 LABEL="ataraxialinux" /media/cdrom || \
{
sleep 3
mount -n -r /dev/disk/by-label/ataraxialinux /media/cdrom
if [ $? -ne 0 ]; then
echo "Failed to find Ataraxia Linux installation media"
exit 1
fi
}
echo "Creating partitions"
if [ "$efi" == "yes" ]; then
mklabel="gpt"
bootfs="fat"
else
mklabel="msdos"
bootfs="ext4"
fi
parted -s /dev/$disk mklabel $mklabel
parted -a optimal -s /dev/$disk mkpart primary 0mb 256mb
parted -a optimal -s /dev/$disk mkpart primary 256mb 100%
[ "$mklabel" == "msdos" ] && parted -s /dev/$disk set 1 boot on
echo "Formating partitions"
case $bootfs in
fat)
mkfs.vfat -F32 "/dev/${disk}1"
;;
ext4)
mke2fs -F -t ext4 "/dev/${disk}1"
;;
esac
mkfs.btrfs -f "/dev/${disk}2"
mount "/dev/${disk}2" /mnt
mkdir -p /mnt/boot
mount "/dev/${disk}1" /mnt/boot
echo "Installing packages"
for pkgs in $(ls /media/cdrom/packages/*.rpm); do
a="$(basename $pkgs)"
case $a in
base-files-*.rpm|netbase-*.rpm|musl-*.rpm|libsepol-*.rpm|libselinux-*.rpm|toybox-*.rpm|mksh-*.rpm) true ;;
*) filtered="$filtered $a" ;;
esac
done
for i in 'base-files-*.rpm' 'netbase-*.rpm' 'musl-*.rpm' 'libsepol-*.rpm' 'libselinux-*.rpm' 'toybox-*.rpm' 'mksh-*.rpm'; do
neko in -r /mnt /media/cdrom/packages/$i
done
for i in $filtered; do
neko in -r /mnt /media/cdrom/packages/$i
done
}
main() {
rm /tmp/net
export kmap="us"
export hostname="localhost"
export timezone="America/New_York"
export if="eth0"
export ifmode="dhcp"
export ifskip="no"
export userskip="no"
print_welcome
select_kmap
select_hostname
select_timezone
select_interfaces
configure_password
configure_users
select_disk
install_os
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.