145 lines
3.4 KiB
Bash
145 lines
3.4 KiB
Bash
#!/usr/bin/env zsh
|
|
#
|
|
# Copyright (c) 2016 Dyne.org Foundation
|
|
# libdevuansdk is written and maintained by
|
|
# Jaromil <jaromil@dyne.org>
|
|
# KatolaZ <katolaz@freaknet.org>
|
|
# parazyd <parazyd@dyne.org>
|
|
#
|
|
# This file is part of libdevuansdk
|
|
#
|
|
# This source code is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This software is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this source code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
### customise
|
|
|
|
install_default_kernel(){
|
|
fn install_default_kernel $@
|
|
req=(strapdir os release version arch)
|
|
root=$strapdir
|
|
reqck || return 1
|
|
|
|
local kernel_base=linux-image
|
|
local kernel=""
|
|
|
|
case $arch in
|
|
amd64)
|
|
kernel=${kernel_base}-amd64
|
|
;;
|
|
i386)
|
|
kernel=${kernel_base}-586
|
|
;;
|
|
*)
|
|
error "Architecture ::1 arch:: is not supported!!!" ${arch}
|
|
zerr; zshexit
|
|
;;
|
|
esac
|
|
|
|
notice "Installing stock kernel for ::1 arch:: (::2 kernel::)" $arch $kernel
|
|
|
|
|
|
mountdevprocsys ${root}
|
|
|
|
sudo chroot ${root} apt-get --yes --force-yes --no-install-recommends install $kernel
|
|
|
|
umountdevprocsys ${root}
|
|
notice "default kernel installed"
|
|
}
|
|
|
|
_install_bootloader(){
|
|
fn _install_bootloader $@
|
|
root=$1
|
|
install_dev=$2
|
|
|
|
sudo chroot ${root} apt-get install --assume-yes --no-install-recommends grub-pc
|
|
if [[ ! -d ${root}/boot/grub ]]; then
|
|
sudo mkdir ${root}/boot/grub
|
|
fi
|
|
|
|
ztmp
|
|
devicemap=$ztmpfile
|
|
|
|
|
|
cat > ${devicemap} <<EOF
|
|
(hd0) /dev/loop0
|
|
(hd0,1) /dev/loop1
|
|
EOF
|
|
sudo cp ${devicemap} ${root}/boot/grub/device.map
|
|
sudo chroot ${root} grub-mkconfig -o /boot/grub/grub.cfg
|
|
|
|
sudo grub-install --root-directory=${root} --no-floppy \
|
|
--modules="ext2 part_msdos" ${install_dev}
|
|
}
|
|
|
|
|
|
make_qemu_img(){
|
|
|
|
fn make_qemu_img $@
|
|
local imgfile=$1
|
|
local imgsize=${2:-4G}
|
|
local imgformat=${3:-raw}
|
|
req=(strapdir os release version arch imgfile imgsize)
|
|
root=$strapdir
|
|
reqck || return 1
|
|
|
|
local blockskip=2050
|
|
|
|
## create the qemu image
|
|
act "creating qemu image"
|
|
|
|
qemu-img create -f ${imgformat} ${imgfile} ${imgsize}
|
|
|
|
sudo parted ${imgfile} --script -- mklabel msdos
|
|
sudo parted ${imgfile} --script -- mkpart primary ${blockskip}s -1s
|
|
sudo parted ${imgfile} --script -- set 1 boot on
|
|
|
|
## setup the loop device
|
|
loop1=`sudo losetup -f`
|
|
sudo losetup ${loop1} ${imgfile}
|
|
loop2=`sudo losetup -f`
|
|
sudo losetup -o $((${blockskip} * 512)) ${loop2} ${loop1}
|
|
|
|
|
|
## now we create the fs
|
|
act "creating filesystem"
|
|
sudo mkfs.ext4 ${loop2}
|
|
|
|
## and we loop-mount it
|
|
|
|
ztmpd
|
|
mntdir=$ztmpdir
|
|
sudo mount -o loop ${loop2} ${mntdir}
|
|
|
|
echo "mntdir: $mntdir strapdir: $strapdir"
|
|
|
|
|
|
# now we rsync everything
|
|
sudo rsync -av ${strapdir}/ $mntdir
|
|
|
|
# we now install the grub bootloader
|
|
mountdevprocsys ${mntdir}
|
|
_install_bootloader $mntdir ${loop1}
|
|
umountdevprocsys ${mntdir}
|
|
|
|
sync
|
|
sudo umount ${mntdir}
|
|
|
|
sudo losetup -d ${loop2}
|
|
sudo losetup -d ${loop1}
|
|
|
|
if [[ ! -z ${imgfile} ]]; then
|
|
notice "QEMU image created in ::1 imgfile::" ${imgfile}
|
|
else
|
|
warning "Unable to create QEMU image file in ::1 imgfile::" ${imgfile}
|
|
fi
|
|
} |