Coding style.
- Changed test-distributions to a python script so the build functions can be used in a python AppImage build script.
This commit is contained in:
parent
110225ab7f
commit
928462f8ff
2 changed files with 159 additions and 172 deletions
|
|
@ -1,172 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Copyright (C) 2017 Andrew Hamilton. All rights reserved.
|
|
||||||
# Licensed under the Artistic License 2.0.
|
|
||||||
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
|
|
||||||
VIGIL_PATH=$(realpath $(dirname $0))
|
|
||||||
|
|
||||||
|
|
||||||
function mount_squashfs_iso {
|
|
||||||
mkdir iso && sudo mount -o loop $1 iso
|
|
||||||
mkdir lower && sudo mount -t squashfs iso/$2 lower
|
|
||||||
mkdir upper work $3 && sudo mount -t overlay \
|
|
||||||
-o lowerdir=lower,upperdir=upper,workdir=work overlay $3
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function umount_squashfs_iso {
|
|
||||||
sudo umount $1 && sudo rm -rf upper work $1
|
|
||||||
sudo umount lower && rmdir lower
|
|
||||||
sudo umount iso && rmdir iso
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function run_in_container {
|
|
||||||
CONTAINER=$1
|
|
||||||
shift
|
|
||||||
[ -f $CONTAINER ] && OPTION="--image" || OPTION="--directory"
|
|
||||||
sudo systemd-nspawn --quiet --chdir=/vigil --overlay=$VIGIL_PATH:/vigil \
|
|
||||||
$OPTION=$CONTAINER /bin/bash --login -c "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function build_ubuntu {
|
|
||||||
sudo debootstrap --components=main,restricted,universe,multiverse \
|
|
||||||
zesty ubuntu.part
|
|
||||||
run_in_container ubuntu.part \
|
|
||||||
ln -sf /lib/systemd/resolv.conf /etc/resolv.conf
|
|
||||||
run_in_container ubuntu.part apt-get update
|
|
||||||
run_in_container ubuntu.part apt-get install --yes python3-pip
|
|
||||||
mv ubuntu.part ubuntu
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_ubuntu {
|
|
||||||
sudo rm -rf ubuntu
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function build_fedora {
|
|
||||||
IMAGE="Fedora-Cloud-Base-25-1.3.x86_64.raw"
|
|
||||||
wget --continue "https://dl.fedoraproject.org/pub/fedora/linux/releases/25/CloudImages/x86_64/images/$IMAGE.xz"
|
|
||||||
unxz $IMAGE.xz
|
|
||||||
mv $IMAGE fedora
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_fedora {
|
|
||||||
sudo rm -rf fedora
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function build_debian {
|
|
||||||
sudo debootstrap --components=main,contrib,non-free \
|
|
||||||
--include=sudo jessie debian.part
|
|
||||||
run_in_container debian.part apt-get update
|
|
||||||
mv debian.part debian
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_debian {
|
|
||||||
sudo rm -rf debian
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ARCHLINUX_ISO="archlinux-2017.06.01-x86_64.iso"
|
|
||||||
|
|
||||||
|
|
||||||
function build_archlinux {
|
|
||||||
wget --continue "http://mirrors.kernel.org/archlinux/iso/2017.06.01/$ARCHLINUX_ISO"
|
|
||||||
mount_squashfs_iso $ARCHLINUX_ISO "arch/x86_64/airootfs.sfs" archlinux
|
|
||||||
run_in_container archlinux pacman-key --init
|
|
||||||
run_in_container archlinux pacman-key --populate archlinux
|
|
||||||
run_in_container archlinux pacman -Syyu --noconfirm
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_archlinux {
|
|
||||||
umount_squashfs_iso archlinux
|
|
||||||
rm $ARCHLINUX_ISO
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
OPENSUSE_ISO="openSUSE-Tumbleweed-GNOME-Live-x86_64-Current.iso"
|
|
||||||
|
|
||||||
|
|
||||||
function build_opensuse {
|
|
||||||
wget --continue "https://download.opensuse.org/tumbleweed/iso/$OPENSUSE_ISO"
|
|
||||||
mount_squashfs_iso $OPENSUSE_ISO \
|
|
||||||
"openSUSE-tumbleweed-livecd-gnome-read-only.x86_64-2.8.0" opensuse
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_opensuse {
|
|
||||||
umount_squashfs_iso opensuse
|
|
||||||
rm $OPENSUSE_ISO
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PIXEL_ISO="2016-12-13-pixel-x86-jessie.iso"
|
|
||||||
|
|
||||||
|
|
||||||
function build_pixel {
|
|
||||||
wget --continue "http://downloads.raspberrypi.org/pixel_x86/images/pixel_x86-2016-12-13/$PIXEL_ISO"
|
|
||||||
mount_squashfs_iso $PIXEL_ISO live/filesystem.squashfs pixel
|
|
||||||
sudo rm pixel/etc/resolv.conf
|
|
||||||
echo "nameserver 127.0.0.53" | sudo dd of=pixel/etc/resolv.conf
|
|
||||||
run_in_container pixel apt-get update
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_pixel {
|
|
||||||
umount_squashfs_iso pixel
|
|
||||||
rm $PIXEL_ISO
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function build_gentoo {
|
|
||||||
TAR_FILE="stage3-amd64-20170525.tar.bz2"
|
|
||||||
wget --continue "http://distfiles.gentoo.org/releases/amd64/autobuilds/20170525/$TAR_FILE"
|
|
||||||
mkdir -p gentoo.part
|
|
||||||
sudo tar --directory=gentoo.part -xjf $TAR_FILE
|
|
||||||
rm $TAR_FILE
|
|
||||||
run_in_container gentoo.part emerge --sync
|
|
||||||
run_in_container gentoo.part emerge sudo
|
|
||||||
mv gentoo.part gentoo
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function remove_gentoo {
|
|
||||||
sudo rm -rf gentoo
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[ $# -eq 0 ] && WORK_PATH=$(mktemp -d --suffix=-vigil) || WORK_PATH="$1"
|
|
||||||
sudo apt-get install -y systemd-container debootstrap xz-utils wget
|
|
||||||
cd $WORK_PATH
|
|
||||||
# FIX: Reenable: fedora debian archlinux opensuse pixel gentoo
|
|
||||||
for DISTRIBUTION in ubuntu; do
|
|
||||||
if [ -e $DISTRIBUTION ]; then
|
|
||||||
echo "$DISTRIBUTION container already exists."
|
|
||||||
else
|
|
||||||
echo "Building $DISTRIBUTION container..."
|
|
||||||
build_$DISTRIBUTION
|
|
||||||
fi
|
|
||||||
echo "Installing vigil's dependencies in $DISTRIBUTION..."
|
|
||||||
run_in_container $DISTRIBUTION ./install-dependencies
|
|
||||||
echo "Installing vigil in $DISTRIBUTION..."
|
|
||||||
run_in_container $DISTRIBUTION pip3 install .
|
|
||||||
echo "Testing vigil in $DISTRIBUTION..."
|
|
||||||
run_in_container $DISTRIBUTION ./test-all
|
|
||||||
echo "Running vigil in $DISTRIBUTION..."
|
|
||||||
run_in_container $DISTRIBUTION vigil --help
|
|
||||||
echo "Successfully installed vigil in $DISTRIBUTION."
|
|
||||||
echo "Removing $DISTRIBUTION container..."
|
|
||||||
remove_$DISTRIBUTION
|
|
||||||
done
|
|
||||||
rmdir $WORK_PATH
|
|
||||||
echo "Finished."
|
|
||||||
159
test_distributions.py
Executable file
159
test_distributions.py
Executable file
|
|
@ -0,0 +1,159 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
# Copyright (C) 2017 Andrew Hamilton. All rights reserved.
|
||||||
|
# Licensed under the Artistic License 2.0.
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
VIGIL_PATH = os.path.realpath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
def cmd(command):
|
||||||
|
subprocess.check_call(command, shell=True)
|
||||||
|
|
||||||
|
|
||||||
|
def mount_squashfs_iso(iso, squashfs_path, mount_point):
|
||||||
|
cmd("mkdir iso && sudo mount -o loop %s iso" % iso)
|
||||||
|
cmd("mkdir lower && sudo mount -t squashfs iso/%s lower" % squashfs_path)
|
||||||
|
cmd("mkdir upper work %s && sudo mount -t overlay "
|
||||||
|
"-o lowerdir=lower,upperdir=upper,workdir=work overlay %s" %
|
||||||
|
(mount_point, mount_point))
|
||||||
|
|
||||||
|
|
||||||
|
def umount_squashfs_iso(mount_point):
|
||||||
|
cmd("sudo umount %s && sudo rm -rf upper work %s" %
|
||||||
|
(mount_point, mount_point))
|
||||||
|
cmd("sudo umount lower && rmdir lower")
|
||||||
|
cmd("sudo umount iso && rmdir iso")
|
||||||
|
|
||||||
|
|
||||||
|
def run_in_container(container, command):
|
||||||
|
option = "--directory" if os.path.isdir(container) else "--image"
|
||||||
|
cmd("sudo systemd-nspawn --quiet --chdir=/vigil --overlay=%s:/vigil "
|
||||||
|
'%s=%s /bin/bash --login -c "%s"' %
|
||||||
|
(VIGIL_PATH, option, container, command))
|
||||||
|
|
||||||
|
|
||||||
|
def build_ubuntu():
|
||||||
|
cmd("sudo debootstrap --components=main,restricted,universe,multiverse "
|
||||||
|
"zesty ubuntu.part")
|
||||||
|
run_in_container("ubuntu.part",
|
||||||
|
"ln -sf /lib/systemd/resolv.conf /etc/resolv.conf")
|
||||||
|
run_in_container("ubuntu.part", "apt-get update")
|
||||||
|
run_in_container("ubuntu.part", "apt-get install --yes python3-pip")
|
||||||
|
os.rename("ubuntu.part", "ubuntu")
|
||||||
|
|
||||||
|
|
||||||
|
def build_fedora():
|
||||||
|
image = "Fedora-Cloud-Base-25-1.3.x86_64.raw"
|
||||||
|
cmd("wget --continue https://dl.fedoraproject.org/pub/fedora/linux/"
|
||||||
|
"releases/25/CloudImages/x86_64/images/%s.xz" % image)
|
||||||
|
cmd("unxz %s.xz" % image)
|
||||||
|
os.rename(image, "fedora")
|
||||||
|
|
||||||
|
|
||||||
|
def build_debian():
|
||||||
|
cmd("sudo debootstrap --components=main,contrib,non-free "
|
||||||
|
"--include=sudo jessie debian.part")
|
||||||
|
run_in_container("debian.part", "apt-get update")
|
||||||
|
os.rename("debian.part", "debian")
|
||||||
|
|
||||||
|
|
||||||
|
ARCHLINUX_ISO = "archlinux-2017.06.01-x86_64.iso"
|
||||||
|
|
||||||
|
|
||||||
|
def build_archlinux():
|
||||||
|
cmd("wget --continue http://mirrors.kernel.org/archlinux/iso/2017.06.01/"
|
||||||
|
+ ARCHLINUX_ISO)
|
||||||
|
mount_squashfs_iso(ARCHLINUX_ISO, "arch/x86_64/airootfs.sfs", "archlinux")
|
||||||
|
run_in_container("archlinux", "pacman-key --init")
|
||||||
|
run_in_container("archlinux", "pacman-key --populate archlinux")
|
||||||
|
run_in_container("archlinux", "pacman -Syyu --noconfirm")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_archlinux():
|
||||||
|
umount_squashfs_iso("archlinux")
|
||||||
|
os.remove(ARCHLINUX_ISO)
|
||||||
|
|
||||||
|
|
||||||
|
OPENSUSE_ISO="openSUSE-Tumbleweed-GNOME-Live-x86_64-Current.iso"
|
||||||
|
|
||||||
|
|
||||||
|
def build_opensuse():
|
||||||
|
cmd("wget --continue https://download.opensuse.org/tumbleweed/iso/"
|
||||||
|
+ OPENSUSE_ISO)
|
||||||
|
mount_squashfs_iso(OPENSUSE_ISO, "openSUSE-tumbleweed-livecd-gnome"
|
||||||
|
"-read-only.x86_64-2.8.0", "opensuse")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_opensuse():
|
||||||
|
umount_squashfs_iso("opensuse")
|
||||||
|
os.remove(OPENSUSE_ISO)
|
||||||
|
|
||||||
|
|
||||||
|
PIXEL_ISO = "2016-12-13-pixel-x86-jessie.iso"
|
||||||
|
|
||||||
|
|
||||||
|
def build_pixel():
|
||||||
|
cmd("wget --continue http://downloads.raspberrypi.org/pixel_x86/images/"
|
||||||
|
"pixel_x86-2016-12-13/" + PIXEL_ISO)
|
||||||
|
mount_squashfs_iso(PIXEL_ISO, "live/filesystem.squashfs", "pixel")
|
||||||
|
cmd("sudo rm pixel/etc/resolv.conf")
|
||||||
|
cmd("echo 'nameserver 127.0.0.53' | sudo dd of=pixel/etc/resolv.conf")
|
||||||
|
run_in_container("pixel", "apt-get update")
|
||||||
|
|
||||||
|
|
||||||
|
def remove_pixel():
|
||||||
|
umount_squashfs_iso("pixel")
|
||||||
|
os.remove(PIXEL_ISO)
|
||||||
|
|
||||||
|
|
||||||
|
def build_gentoo():
|
||||||
|
tar_file = "stage3-amd64-20170525.tar.bz2"
|
||||||
|
cmd("wget --continue http://distfiles.gentoo.org/releases/amd64/"
|
||||||
|
"autobuilds/20170525/" + tar_file)
|
||||||
|
cmd("mkdir -p gentoo.part")
|
||||||
|
cmd("sudo tar --directory=gentoo.part -xjf " + tar_file)
|
||||||
|
os.remove(tar_file)
|
||||||
|
run_in_container("gentoo.part", "emerge --sync")
|
||||||
|
run_in_container("gentoo.part", "emerge sudo")
|
||||||
|
os.rename("gentoo.part", "gentoo")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
WORK_PATH = (tempfile.mkdtemp(prefix="vigil-") if len(sys.argv) == 1
|
||||||
|
else sys.argv[1])
|
||||||
|
os.chdir(WORK_PATH)
|
||||||
|
cmd("sudo apt-get install -y systemd-container debootstrap xz-utils wget")
|
||||||
|
# FIX: Reenable: fedora debian archlinux opensuse pixel gentoo
|
||||||
|
for distribution in ["ubuntu"]:
|
||||||
|
if os.path.exists(distribution):
|
||||||
|
print("%s container already exists." % distribution)
|
||||||
|
else:
|
||||||
|
print("Building %s container..." % distribution)
|
||||||
|
globals()["build_" + distribution]()
|
||||||
|
print("Installing vigil's dependencies in %s..." % distribution)
|
||||||
|
run_in_container(distribution, "./install-dependencies")
|
||||||
|
print("Installing vigil in %s..." % distribution)
|
||||||
|
run_in_container(distribution, "pip3 install .")
|
||||||
|
print("Testing vigil in %s..." % distribution)
|
||||||
|
run_in_container(distribution, "./test-all")
|
||||||
|
print("Running vigil in %s..." % distribution)
|
||||||
|
run_in_container(distribution, "vigil --help")
|
||||||
|
print("Successfully installed vigil in %s." % distribution)
|
||||||
|
print("Removing %s container..." % distribution)
|
||||||
|
try:
|
||||||
|
globals()["remove_" + distribution]()
|
||||||
|
except KeyError:
|
||||||
|
cmd("sudo rm -rf " + distribution)
|
||||||
|
os.rmdir(WORK_PATH)
|
||||||
|
print("Finished.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue