First commit

This commit is contained in:
Clayton Voges 2020-09-16 18:11:36 +00:00
commit 450ab53d74
2 changed files with 144 additions and 0 deletions

135
main.sh Normal file
View file

@ -0,0 +1,135 @@
#!/usr/bin/env ash
format_disk(){
echo "===FORMATTING DISK==="
apk add parted e2fsprogs
ram="8" # in whole number GiB (round up)
table="EFI-GPT" # EFI-GPT or MBR or BIOS-GPT
[ "$table" == "MBR" ] && \
parted -s /dev/sda \
mklabel msdos \
mkpart primary linux-swap 2MiB ${ram}GiB \
mkpart primary ext4 ${ram}GiB 100% \
set 2 boot on \
&& mkswap -L SWAP /dev/sda1 \
&& swapon /dev/sda1 \
&& mkfs.ext4 -n ROOT /dev/sda2
[ "$table" == "EFI-GPT" ] && \
parted -s /dev/sda \
mklabel gpt \
mkpart primary fat32 1MiB +260MiB \
mkpart primary linux-swap 260MiB +${ram}GiB \
mkpart primary ext4 ${ram}GiB 100% \
set 1 esp on \
set 3 boot on \
&& mkdosfs -n EFI /dev/sda1 \
&& mkswap -L SWAP /dev/sda2 \
&& swapon /dev/sda2 \
&& mkfs.ext4 -n ROOT /dev/sda3
[ "$table" == "BIOS-GPT" ] && \
parted -s /dev/sda \
mklabel gpt \
mkpart primary fat32 1MiB 2MiB \
mkpart primary linux-swap 100MiB ${ram}GiB \
mkpart primary ext4 ${ram}GiB 100% \
set 1 bios_grub on \
set 3 boot on \
&& mkdosfs -n EFI /dev/sda1 \
&& mkswap -L SWAP /dev/sda2 \
&& swapon /dev/sda2 \
&& mkfs.ext4 -n ROOT /dev/sda3
echo -e "\n\n"
}
chroot_dir=""
arch=""
mirror=""
branch="latest-stable"
version=""
set_chroot_dir(){
echo "===CHROOT DIRECTORY==="
mkdir -p /mnt/chroot
chroot_dir="/mnt/chroot"
}
set_arch(){
arch=`uname -m`
}
set_mirror(){
echo "===SETTING MIRROR==="
data=""
for s in $(wget -qO - \
http://rsync.alpinelinux.org/alpine/MIRRORS.txt)
do
t=$(time -f "%E" wget -q $s/MIRRORS.txt -T 2 -O /dev/null 2>&1)
echo "$s was $t"
data="$data$t $s\n"
done
mirror=`echo -e $data \
| sort \
| grep "http" \
| head -n 1 \
| awk '{print $3}'`
echo "${mirror}/${branch}/main" >> /etc/apk/repositories
apk upgrade && apk upgrade
echo "==RESULTS=="
echo -e "${mirror}\n\n"
}
set_version(){
version=`wget -O - -o /dev/null \
${mirror}/${branch}/main/${arch}/ \
| grep "apk-tools-static" \
| sed -e 's/.*apk-tools-static-//' \
| sed -e 's/\.apk.*//'`
}
get_alpine(){
wget \
${mirror}/${branch}/main/${arch}\
/apk-tools-static-${version}.apk
tar -xzf apk-tools-static-*.apk
./sbin/apk.static -X ${mirror}/${branch}/main -U \
--allow-untrusted --root ${chroot_dir} --initdb add alpine-base
}
mk_chroot(){
# dev mounts
mount /dev/ ${chroot_dir}/dev/ --bind
mount -o remount,ro,bind ${chroot_dir}/dev
# proc and sysfs
mount -t proc none ${chroot_dir}/proc
mount -o bind /sys ${chroot_dir}/sys
# dns
cp -L /etc/resolv.conf ${chroot_dir}/etc/
mkdir -p ${chroot_dir}/root
# apk sources
mkdir -p ${chroot_dir}/etc/apk
echo "${mirror}/${branch}/main" > \
${chroot_dir}/etc/apk/repositories
}
set_mirror && \
# fix the start and end
format_disk && \
set_chroot_dir #&& \
#set_arch && \
#set_version && \
#get_alpine && \
#mk_chroot
#cat << EOF | chroot ${chroot_dir} ash -l
#mkdir boop
#echo "did it work?"
#EOF

9
startup.sh Normal file
View file

@ -0,0 +1,9 @@
apk add wireless-tools wpa_supplicant openssh
ip link set wlan0 up
iwconfig wlan0 essid "TheFoundry"
wpa_passphrase "TheFoundry" "somethingclever" > /etc/wpa_supplicant/wpa_supplicant.conf
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
udhcpc -i wlan0
# change /etc/ssh/sshd_config to have "PermitRootLogin yes"
passwd #t
rc-service sshd restart