260 lines
6.6 KiB
Bash
Executable File
260 lines
6.6 KiB
Bash
Executable File
#!/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/>.
|
|
|
|
qemu_install_user() {
|
|
fn qemu_install_user
|
|
local cputype="$1"
|
|
|
|
[[ -n $enable_qemu ]] && {
|
|
act "installing qemu-arm-static"
|
|
sudo cp -vf /usr/bin/qemu-arm-static $strapdir/usr/bin/
|
|
}
|
|
|
|
[[ -n $cputype ]] && {
|
|
act "compiling qemu wrapper"
|
|
cp $R/src/qemu-wrapper.c /tmp/qemu-wrapper.c
|
|
sed -i -e 's/cortex-a8/'$cputype'/' /tmp/qemu-wrapper.c
|
|
gcc -static /tmp/qemu-wrapper.c -O3 -s /tmp/qemu-wrapper
|
|
sudo mv -vf /tmp/qemu-wrapper $strapdir/usr/bin/
|
|
|
|
print ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-wrapper:' | sudo tee /proc/sys/fs/binfmt_misc/register
|
|
}
|
|
}
|
|
|
|
qemu_make_img() {
|
|
|
|
fn qemu_make_img $@
|
|
local imgfile=${1:-"$H/builds/${name_default}_${arch}.img"}
|
|
local imgsize=${2:-2G}
|
|
local imgformat=${3:-raw}
|
|
req=(strapdir os release version arch imgfile imgsize)
|
|
root=$strapdir
|
|
freq=($root/.done)
|
|
reqck || return 1
|
|
|
|
local blockskip=2050
|
|
|
|
## create the qemu image
|
|
notice "Creating qemu image: $imgfile"
|
|
|
|
qemu-img create -f ${imgformat} ${imgfile} ${imgsize}
|
|
[[ $? = 0 ]] || {
|
|
error "failed: qemu-img create -f ${imgformat} ${imgfile} ${imgsize}"
|
|
zsherr; zshexit }
|
|
|
|
sudo parted ${imgfile} --script -- mklabel msdos &&
|
|
sudo parted ${imgfile} --script -- mkpart primary ${blockskip}s -1s &&
|
|
sudo parted ${imgfile} --script -- set 1 boot on
|
|
[[ $? = 0 ]] || {
|
|
error "failed: parted $imgfile scripts (mklabel, mkpart and setboot)"
|
|
zsherr; zshexit }
|
|
|
|
## setup the loop device
|
|
loop1=`sudo losetup -f`
|
|
sudo losetup ${loop1} ${imgfile}
|
|
[[ $? = 0 ]] || {
|
|
error "failed: losetup $loop2 $imgfile"
|
|
zsherr; zshexit }
|
|
|
|
loop2=`sudo losetup -f`
|
|
sudo losetup -o $((${blockskip} * 512)) ${loop2} ${loop1}
|
|
[[ $? = 0 ]] || {
|
|
sudo losetup -d ${loop1}
|
|
error "failed: losetup -o $((${blockskip} * 512)) ${loop2} ${loop1}"
|
|
zsherr; zshexit }
|
|
|
|
## now we create the fs
|
|
act "creating filesystem"
|
|
sudo mkfs.ext4 ${loop2}
|
|
[[ $? = 0 ]] || {
|
|
sudo losetup -d ${loop2}
|
|
sudo losetup -d ${loop1}
|
|
error "failed: mkfs.ext4 $loop2"
|
|
zsherr; zshexit }
|
|
|
|
## and we loop-mount it
|
|
|
|
ztmpd
|
|
mntdir=$ztmpdir
|
|
sudo mount -o loop ${loop2} ${mntdir}
|
|
[[ $? = 0 ]] || {
|
|
sudo losetup -d ${loop2}
|
|
sudo losetup -d ${loop1}
|
|
error "failed: mount -o loop ${loop2} ${mntdir}"
|
|
zsherr; zshexit }
|
|
|
|
func "mntdir: $mntdir"
|
|
func "strapdir: $strapdir"
|
|
|
|
# now we rsync everything
|
|
notice "Copying filesystem into image"
|
|
# ztmp
|
|
# excludefile=${ztmp}
|
|
# qemu_config_exclude | sudo tee ${excludefile}
|
|
# sudo rsync -raX --exclude-from=${excludefile} ${strapdir}/ ${mntdir}
|
|
sudo rsync -raX ${strapdir}/ ${mntdir}
|
|
[[ $? = 0 ]] || {
|
|
umount $mntdir
|
|
sudo losetup -d ${loop2}
|
|
sudo losetup -d ${loop1}
|
|
error "failed: rsync -raX ${strapdir}/ ${mntdir}"
|
|
zsherr; zshexit }
|
|
|
|
# we now install the grub bootloader
|
|
mountdevprocsys ${mntdir}
|
|
grub_install_target_dev ${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
|
|
}
|
|
|
|
qemu_config_esclude(){
|
|
fn qemu_config_exclude
|
|
|
|
cat <<EOF
|
|
- /proc/*
|
|
- /sys/*
|
|
- /dev/*
|
|
- /tmp/*
|
|
- /mnt/*
|
|
- /live
|
|
- /persistence.conf
|
|
- /boot/grub/grub.cfg
|
|
- /boot/grub/menu.lst
|
|
- /boot/grub/device.map
|
|
- /boot/*.bak
|
|
- /boot/*.old-dkms
|
|
- /etc/udev/rules.d/70-persistent-cd.rules
|
|
- /etc/udev/rules.d/70-persistent-net.rules
|
|
- /etc/fstab
|
|
- /etc/fstab.d/*
|
|
- /etc/mtab
|
|
- /etc/blkid.tab
|
|
- /etc/blkid.tab.old
|
|
- /etc/apt/sources.list~
|
|
- /etc/crypttab
|
|
- /etc/initramfs-tools/conf.d/resume # see remove-cryptroot and nocrypt.sh
|
|
- /etc/initramfs-tools/conf.d/cryptroot # see remove-cryptroot and nocrypt.sh
|
|
- /home/snapshot
|
|
- /var/log/*
|
|
- /var/log/[a-b,A-Z]*
|
|
- /var/log/[d-f]*
|
|
- /var/log/[h-z]*
|
|
- /var/log/*gz
|
|
|
|
- /var/cache/apt/archives/*.deb
|
|
- /var/cache/apt/pkgcache.bin
|
|
- /var/cache/apt/srcpkgcache.bin
|
|
- /var/cache/apt/apt-file/*
|
|
- /var/cache/debconf/*~old
|
|
- /var/lib/apt/lists/*
|
|
- /var/lib/apt/*~
|
|
- /var/lib/apt/cdroms.list
|
|
- /var/lib/aptitude/*.old
|
|
- /var/lib/dhcp/*
|
|
- /var/lib/dpkg/*~old
|
|
- /var/spool/mail/*
|
|
- /var/mail/*
|
|
- /var/backups/*.gz
|
|
#- /var/backups/*.bak
|
|
- /var/lib/dbus/machine-id
|
|
- /var/lib/live/config/*
|
|
|
|
- /usr/share/icons/*/icon-theme.cache
|
|
|
|
- /root/.aptitude
|
|
- /root/.bash_history
|
|
- /root/.disk-manager.conf
|
|
- /root/.fstab.log
|
|
- /root/.lesshst
|
|
- /root/*/.log
|
|
- /root/.local/share/*
|
|
- /root/.nano_history
|
|
- /root/.synaptic
|
|
- /root/.VirtualBox
|
|
- /root/.ICEauthority
|
|
- /root/.Xauthority
|
|
- /root/.links2
|
|
|
|
- /root/.ssh
|
|
- /root/[a-zA-Z0-9]*
|
|
|
|
- /home/*/.Trash*
|
|
- /home/*/.local/share/Trash/*
|
|
- /home/*/.mozilla/*/Cache/*
|
|
- /home/*/.mozilla/*/urlclassifier3.sqlite
|
|
- /home/*/.mozilla/*/places.sqlite
|
|
- /home/*/.mozilla/*/cookies.sqlite
|
|
- /home/*/.mozilla/*/signons.sqlite
|
|
- /home/*/.mozilla/*/formhistory.sqlite
|
|
- /home/*/.mozilla/*/downloads.sqlite
|
|
- /home/*/.adobe
|
|
- /home/*/.aptitude
|
|
- /home/*/.bash_history
|
|
- /home/*/.cache
|
|
- /home/*/.dbus
|
|
- /home/*/.gksu*
|
|
- /home/*/.gvfs
|
|
- /home/*/.lesshst
|
|
- /home/*/.log
|
|
- /home/*/.macromedia
|
|
- /home/*/.nano_history
|
|
- /home/*/.pulse*
|
|
- /home/*/.recently-used
|
|
- /home/*/.recently-used.xbel
|
|
- /home/*/.local/share/recently-used.xbel
|
|
- /home/*/.thumbnails/large/*
|
|
- /home/*/.thumbnails/normal/*
|
|
- /home/*/.thumbnails/fail/*
|
|
- /home/*/.vbox*
|
|
- /home/*/.VirtualBox
|
|
- /home/*/VirtualBox\ VMs
|
|
#- /home/*/.wine
|
|
- /home/*/.xsession-errors*
|
|
- /home/*/.ICEauthority
|
|
- /home/*/.Xauthority
|
|
|
|
# You might want to comment these out if you're making a snapshot for
|
|
# your own personal use, not to be shared with others.
|
|
- /home/*/.gnupg
|
|
- /home/*/.ssh
|
|
- /home/*/.xchat2
|
|
|
|
### ignore all non-hidden files in /home/devuan -- KatolaZ -- 2016-05-21
|
|
|
|
- /home/devuan/[a-zA-Z0-9]*
|
|
|
|
|
|
EOF
|
|
}
|