Skip to content

Commit

Permalink
Added initial work in progress scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
basukon committed Oct 8, 2019
1 parent 3508ef1 commit 1e643ee
Show file tree
Hide file tree
Showing 25 changed files with 1,903 additions and 0 deletions.
155 changes: 155 additions & 0 deletions LoDGenerator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#!/bin/bash

# Script with the future idea of adapting it to generate any
# linux distro image.
#
# Notes to remember:
# blkid image_name.img to view the image details.
#
# To edit the image arm image on x86_64:
# ================================================================
# This provides the qemu-aarch64-static binary
# yay -S qemu-arm-static
#
# Mount my target filesystem on /mnt
# mount -o loop fs.img loddir
#
# Copy the static ARM binary that provides emulation
# cp $(which qemu-aarch64-static) loddir/usr/bin
# Or, more simply: cp /usr/bin/qemu-aarch64-static loddir/usr/bin
#
# Finally chroot into loddir, then run 'qemu-aarch64-static bash'
# This chroots; runs the emulator; and the emulator runs bash
#
# cp /etc/resolv.conf loddir/etc/
# chroot loddir qemu-arm-static /bin/bash
# ================================================================

if [ ! -e "/usr/bin/arch-chroot" ]; then
echo "Please install arch-chroot to continue."
exit
fi

if [ ! -e "/usr/bin/qemu-aarch64-static" ]; then
echo "Please install qemu-arm-static for qemu-aarch64-static support."
exit
fi

if [ ! -e "FileSystems" ]; then
mkdir FileSystems
fi

function make_archlinux {
distro="ArchLinux"
url="http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz"
directory=archlinux
filesystem=ArchLinuxARM-aarch64-latest.tar.gz
image_name=ArchLinux_LoD.img
image_size=3076
setup_file=archlinux_setup.sh

if [ ! -d "${directory}" ]; then
mkdir $directory
fi

if [ "$(ls $directory)" != "" ]; then
echo "Umounting previous image."
umount $directory/proc > /dev/null 2>&1
umount $directory/sys/firmware/efi/efivars > /dev/null 2>&1
umount $directory/sys > /dev/null 2>&1
umount $directory/dev/pts > /dev/null 2>&1
umount $directory/dev/shm > /dev/null 2>&1
umount $directory/dev > /dev/null 2>&1
umount $directory/run > /dev/null 2>&1
umount $directory/tmp > /dev/null 2>&1
umount $directory/etc/resolv.conf > /dev/null 2>&1
umount $directory > /dev/null 2>&1
sleep 3
fi

echo "Creating ${distro} disk image..."
if [ -e "${image_name}" ]; then
rm $image_name
fi

dd if=/dev/zero of=$image_name bs=1M count=$image_size

mkfs.ext4 -L cloudimg-rootfs \
-U 455a35d3-488b-4c5e-89b0-883ef8e77f68 \
$image_name

mount -o loop $image_name $directory

echo "Downloading ${distro}..."
if [ ! -e "FileSystems/${filesystem}" ]; then
wget -O "FileSystems/${filesystem}" "${url}"
fi

echo "Decompressing ${distro}..."
bsdtar -xpf FileSystems/$filesystem -C $directory

echo "Preparing image for chroot with qemu..."
cp /usr/bin/qemu-aarch64-static $directory/usr/bin/

echo "Starting distro setup..."
cp -av Setup/$setup_file $directory/
arch-chroot $directory qemu-aarch64-static /bin/bash $setup_file

rm $directory/$setup_file
rm $directory/usr/bin/qemu-aarch64-static

sleep 3

umount $directory/proc > /dev/null 2>&1
umount $directory/sys/firmware/efi/efivars > /dev/null 2>&1
umount $directory/sys > /dev/null 2>&1
umount $directory/dev/pts > /dev/null 2>&1
umount $directory/dev/shm > /dev/null 2>&1
umount $directory/dev > /dev/null 2>&1
umount $directory/run > /dev/null 2>&1
umount $directory/tmp > /dev/null 2>&1
umount $directory/etc/resolv.conf > /dev/null 2>&1
umount $directory/proc > /dev/null 2>&1

# Wait for proper umount
sleep 3

echo "Setting directory permissions..."
chown -R 1638400000:1638400000 $directory/bin
chown -R 1638400000:1638400000 $directory/boot
chown -R 1638400000:1638400000 $directory/etc
chown 1638400000:1638400000 $directory/home
chown -R 1638400000:1638400000 $directory/lib
chown -R 1638400000:1638400000 $directory/lost+found
chown 1638400000:1638400000 $directory/mnt
chown 1638400000:1638400000 $directory/opt
chown -R 1638400000:1638400000 $directory/root
chown -R 1638400000:1638400000 $directory/run
chown -R 1638400000:1638400000 $directory/sbin
chown -R 1638400000:1638400000 $directory/share
chown -R 1638400000:1638400000 $directory/srv
chown -R 1638400000:1638400000 $directory/sys
chown -R 1638400000:1638400000 $directory/usr
chown -R 1638400000:1638400000 $directory/var
chown -R 1638400000:1638400000 $directory/proc

echo "Copying LinuxOnDex dependencies..."
cp -av Template/usr $directory/
cp -av Template/devro $directory/
cp -av Template/share $directory/
cp -av Template/ext_sd $directory/
cp -av Template/home/dextop $directory/home/
cp -av Template/tmp $directory/
rm -rf $directory/dev
cp -av Template/dev $directory/
cp -av Template/proc $directory/
cp -av Template/media $directory/

chmod u+s $directory/usr/bin/sudo

echo "Copyng final configurations..."
mv $directory/etc/resolv.conf $directory/etc/resolv.conf.systemd
cp -av Template/etc $directory/
}

make_archlinux
64 changes: 64 additions & 0 deletions Setup/archlinux_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

# This file is to properly setup the archlinuxarm from within the
# arch-chroot.

# to prevent mmap errors due to qemu and proper mount...
sleep 3

# since network isnt't working with plain resolv.conf we add some hosts
cp /etc/hosts /etc/hosts.original
echo "50.116.36.110 mirror.archlinuxarm.org" >> /etc/hosts
echo "216.155.157.40 fl.us.mirror.archlinuxarm.org" >> /etc/hosts

cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.original
echo 'Server = http://fl.us.mirror.archlinuxarm.org/$arch/$repo' \
> /etc/pacman.d/mirrorlist

# Init archlinuxarm packages keyring
pacman-key --init
pacman-key --populate archlinuxarm

# Remove kernel
pacman --noconfirm -Rcs linux-aarch64 linux-firmware

# Update the base system
pacman --noconfirm -Suy

# Install additional packages
pacman --noconfirm -S sudo pulseaudio xorg-server xorg-apps \
ttf-liberation ttf-opensans ttf-hack \
tigervnc fluxbox

# Clean downloaded packages
pacman --noconfirm -Scc

# Enable sudo on all user accounts
echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel

# Fix Xtightvnc missing dependency
ln -s /usr/lib/libXfont2.so.2.0.0 /usr/lib/libXfont.so.1

# Remove default user
userdel -f -r alarm

useradd -m dextop

usermod -a -G network,wheel,audio,input,video,storage dextop

echo "Please enter the dextop user password:"
passwd dextop

echo "Please enter the root password:"
passwd root

mv /etc/hosts.original /etc/hosts

mv /etc/pacman.d/mirrorlist.original /etc/pacman.d/mirrorlist

# Enable networking on the container
groupadd -g 53003 inet
usermod -a -G inet dextop
usermod -a -G inet root

exit
1 change: 1 addition & 0 deletions Template/etc/LoDVersion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version : GI016
Loading

0 comments on commit 1e643ee

Please sign in to comment.