initial work been done... base.py is WIP

This commit is contained in:
brent s 2016-11-14 03:40:28 -05:00
parent a75cff05b7
commit 6d611da615
38 changed files with 78 additions and 510 deletions

1
TODO Normal file
View File

@ -0,0 +1 @@
- maybe use ZConfig? https://pypi.python.org/pypi/ZConfig

61
bdisk/base.py Executable file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env python3

import os
import re
import hashlib
import gnupg
from urllib.request import urlopen

def download_tarball(arch, dlpath):
# arch - should be i686 or x86_64
# returns path/filename e.g. /some/path/to/file.tar.gz
# we use .gnupg since we'll need it later.
try:
os.makedirs(dlpath + '/.gnupg')
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
#mirror = 'http://mirrors.kernel.org/archlinux'
mirror = 'https://mirror.us.leaseweb.net/archlinux'
rlsdir = mirror + '/iso/latest'
sha_in = urlopen(rlsdir + '/sha1sums.txt')
sha1sums = sha_in.read()
sha_in.close()
sha1_list = sha1sums.decode("utf-8")
sha_list = list(filter(None, sha1_list.split('\n')))
sha_dict = {x.split()[1]: x.split()[0] for x in sha_list}
pattern = re.compile('^archlinux-bootstrap-[0-9]{4}\.[0-9]{2}\.[0-9]{2}-' + arch + '\.tar\.gz$')
tarball = [filename.group(0) for l in list(sha_dict.keys()) for filename in [pattern.search(l)] if filename][0]
sha1 = sha_dict[tarball]
# all that lousy work just to get a sha1 sum. okay. so.
if os.path.isfile(dlpath + '/latest.' + arch + '.tar.gz'):
pass
else:
# fetch the tarball...
print("Fetching the tarball for {0} architecture, please wait...".format(arch))
tarball_dl = urlopen(rlsdir + tarball)
with open(dlpath + '/latest.' + arch + '.tar.gz', 'wb') as f:
f.write(tarball_dl)
tarball_dl.close()
tarball_hash = hashlib.sha1(open(dlpath + '/latest.' + arch + '.tar.gz', 'rb').read()).hexdigest()
if tarball_hash != sha1:
exit("There was a failure fetching the tarball and the wrong version exists on the filesystem.\nPlease try again later.")
else:
# okay, so the sha1 matches. let's verify the signature.
# we don't want to futz with the users normal gpg.
gpg = gnupg.GPG(gnupghome=dlpath + '/.gnupg')
input_data = gpg.gen_key_input(name_email='tempuser@nodomain.tld',passphrase='placeholder_passphrase')
key = gpg.gen_key(input_data)
keyid = '7F2D434B9741E8AC'
gpg_sig = tarball + '.sig'
sig_dl = urlopen(rlsdir + gpg_sig)
with open(dlpath + '/latest.' + arch + '.tar.gz.sig', 'wb') as f:
f.write(sig_dl)
sig_dl.close()
sig = dlpath + '/latest.' + arch + '.tar.gz.sig'
gpg.verify_file(dlpath + '/latest.' + arch + '.tar.gz', sig_file = sig)


return(sha1sum)

print(download_tarball('x86_64'))

16
bdisk/host.py Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python3

import os
import sys
import platform

def getOS():
# Returns one of: SuSE, debian, fedora, redhat, centos, mandrake,
# mandriva, rocks, slackware, yellowdog, gentoo, UnitedLinux,
# turbolinux, arch, mageia
distro = list(platform.linux_distribution())[0].lower()
return(distro)

def getBits():
bits = list(platform.architecture())[0]
return(bits)

0
default.cfg Normal file
View File

View File

@ -1,27 +0,0 @@
NAME='Antergos'
SUPPORTED='yes'
CHECK_METHOD='egrep "^NAME=\"Antergos Linux\"$" /etc/os-release'
PKG_MGR='pacman -S --needed --noconfirm ${pkgname}'
PRE_RUN='pacman -Syyy'
PKG_CHK='pacman -Q ${pkgname}'
URL='http://antergos.com/'

function distro_specific_tweaks {
# For some reason, I can't get "yes y | " to parse correctly with eval. And Arch isn't smart enough
# to figure out that if I enable the multilib repos, *I want multilib gcc*. Fuck it. We'll just remove it first.

pacman -S --needed --noconfirm haveged >> "${LOGFILE}.${FUNCNAME}" 2>&1
haveged

set +e
for pkg_override in gcc gcc-libs;
do
pacman -Q ${pkg_override} >> "${LOGFILE}.${FUNCNAME}" 2>&1
if [[ "${?}" == "0" ]];
then
pacman -Rdd --noconfirm ${pkg_override} >> "${LOGFILE}.${FUNCNAME}" 2>&1
fi
done
set -e

}

View File

@ -1 +0,0 @@
../Arch/pkgs

View File

@ -1,27 +0,0 @@
NAME='Arch'
SUPPORTED='yes'
CHECK_METHOD='egrep "^NAME=\"Arch Linux\"$" /etc/os-release'
PKG_MGR='pacman -S --needed --noconfirm ${pkgname}'
PRE_RUN='pacman -Syyy'
PKG_CHK='pacman -Q ${pkgname}'
URL='https://www.archlinux.org/'

function distro_specific_tweaks {
# For some reason, I can't get "yes y | " to parse correctly with eval. And Arch isn't smart enough
# to figure out that if I enable the multilib repos, *I want multilib gcc*. Fuck it. We'll just remove it first.

pacman -S --needed --noconfirm haveged >> "${LOGFILE}.${FUNCNAME}" 2>&1
haveged

set +e
for pkg_override in gcc gcc-libs;
do
pacman -Q ${pkg_override} >> "${LOGFILE}.${FUNCNAME}" 2>&1
if [[ "${?}" == "0" ]];
then
pacman -Rdd --noconfirm ${pkg_override} >> "${LOGFILE}.${FUNCNAME}" 2>&1
fi
done
set -e

}

View File

@ -1,19 +0,0 @@
binutils
curl
dosfstools
findutils
gcc-libs-multilib
gcc-multilib
git
libisoburn
lynx
make
mtools
patch
perl
rsync
sed
squashfs-tools
syslinux
xz
zlib

View File

@ -1,17 +0,0 @@
NAME='CentOS'
# Currently fails on installing software *inside* the chroot. Will troubleshoot and restore when figured out.
SUPPORTED='yes'
CHECK_METHOD='egrep "^CentOS" /etc/redhat-release'
PKG_MGR='yum -y install ${pkgname}'
PRE_RUN='none'
PKG_CHK='rpm -q ${pkgname} | egrep "^${pkgname}-[0-9]"'
URL='http://centos.org/'

function distro_specific_tweaks {
# NOTE: we handle installing of squashfs-tools (maybe) and xorriso in centos_is_stupid function.
# because they *suck*. Seriously. I need to install tk just to install xorriso. I mean, what?
# You need EPEL enabled, by the way.

echo "No tweaks found."

}

View File

@ -1 +0,0 @@
../RHEL/pkgs

View File

@ -1,13 +0,0 @@
NAME='Debian'
SUPPORTED='yes'
CHECK_METHOD='egrep "^NAME=\"Debian\ GNU/Linux\"$" /etc/os-release'
PKG_MGR='apt-get -y install ${pkgname}'
PRE_RUN='apt-get update'
PKG_CHK='dpkg-query -l ${pkgname} | egrep "^ii[[:space:]]*${pkgname}"'
URL='http://www.debian.org/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1,26 +0,0 @@
binutils
binutils-dev
curl
dosfstools
gcc
gcc-multilib
git
isolinux
libiberty-dev
libisoburn1
lynx
liblzma5
liblzma-dev
make
mtools
patch
perl
rsync
sed
squashfs-tools
syslinux
syslinux-efi
xorriso
xz-utils
zlib1g
zlib1g-dev

View File

@ -1,14 +0,0 @@
NAME='Devuan'
SUPPORTED='no'
CHECK_METHOD='egrep "^NAME=\"Devuan\ GNU/Linux\"$" /etc/os-release'
PKG_MGR='apt-get -y install ${pkgname}'
PRE_RUN='apt-get update'
PKG_CHK='dpkg-query -l ${pkgname} | egrep "^ii[[:space:]]*${pkgname}"'
URL='http://www.debian.org/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1 +0,0 @@
../Debian/pkgs

View File

@ -1,14 +0,0 @@
NAME='Fedora'
SUPPORTED='yes'
CHECK_METHOD='egrep '^Fedora' /etc/redhat-release'
PKG_MGR='dnf -y install ${pkgname}'
PRE_RUN='none'
PKG_CHK='rpm -q ${pkgname} | egrep "^${pkgname}-[0-9]"'
URL='https://getfedora.org/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1,23 +0,0 @@
binutils
binutils-devel
curl
dosfstools
gcc
git
libisofs
lynx
make
mtools
patch
perl
rsync
sed
squashfs-tools
syslinux
syslinux-devel
tar
xorriso
xz
xz-devel
zlib
zlib-devel

View File

@ -1,20 +0,0 @@
NAME='Gentoo'
SUPPORTED='yes'
CHECK_METHOD='egrep "^Gentoo\ Base\ System" /etc/gentoo-release'
PKG_MGR='emerge -q1Dn ${pkgname}'
PRE_RUN='emerge -q --sync'
PKG_CHK='emerge -qp @installed 2>/dev/null | egrep -E "/${pkgname}-[0-9.]+"'
URL='https://www.gentoo.org/'

function distro_specific_tweaks {
# WHY IS THIS EVEN MASKED?!

set +e
grep -q 'app-arch/lzma' /etc/portage/package.accept_keywords
if [[ "${?}" != "0" ]];
then
echo 'app-arch/lzma' >> /etc/portage/package.accept_keywords
fi
set -e

}

View File

@ -1,18 +0,0 @@
sys-devel/binutils
net-misc/curl
sys-fs/dosfstools
sys-devel/gcc
dev-vcs/git
dev-libs/libisoburn
www-client/lynx
app-arch/lzma
sys-devel/make
sys-fs/mtools
sys-devel/patch
dev-lang/perl
net-misc/rsync
sys-apps/sed
sys-fs/squashfs-tools
sys-boot/syslinux
app-arch/xz-utils
sys-libs/zlib

View File

@ -1,19 +0,0 @@
This directory is used to enable cross-distro support and set baseline ISO packages needed for it to boot. A list of packages is needed for the *host* to build the ISO as well, which you'll find detailed below. Adding distro support is easy; there simply needs to be the following added:

<basedir>/lib/prereqs/<Distro>/{meta,pkgs}

"pkgs" should contain a list of the specific package names needed to install for that specific distro (as this isn't always standardized).

"meta" is a file consisting of the following variables (enclosed in single or double quotes, please:

NAME=<Distro - this should match the name of the directory this file is in!>
SUPPORTED=<yes or no- yes by default>
CHECK_METHOD=<a command that will be run that should return '0' (success) on *only* this specific distro
(or fully compatible derivatives, i.e. CentOS/RHEL)>
PKG_MGR=<a command used to prefix installation of packages e.g. for RHEL, "yum -y install">
PRE_RUN=<a command to be run before PKG_MGR (e.g. on Ubuntu, "apt-get update"). commonly used to update package caches/metadata.
if your distro does not require this, set PRE_RUN=none >
PKG_CHK=<a command that will be run that should return '0' (success) *only* if any given package in the pkgs file is installed. e.g. for RHEL, "rpm -q">
URL=<the URL for the distro. optional, as it isn't really used as any active part of the scripts- at least not presently.>

Oh- and your distro *must be able to install the package*. That means if you need to enable/add additional repositories, be sure to do so ahead of time.

View File

@ -1,14 +0,0 @@
NAME='Mageia'
SUPPORTED='yes'
CHECK_METHOD='egrep "^Mageia\ release\ " /etc/mageia-release'
PKG_MGR='urpmi --force --auto ${pkgname}'
PRE_RUN='urpmi.update -a'
PKG_CHK='rpm -q ${pkgname} | egrep "^${pkgname}-[0-9]"'
URL='https://www.mageia.org/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1,27 +0,0 @@
binutils
binutils-devel
curl
gcc
git
lib64isofs6
lib64apr1_0
lib64apr-util1_0
lib64lzma5
lib64lzma-devel
lib64lzmalib1
lib64lzmalib-devel
libstdc++-devel
lynx
make
mtools
patch
perl
rsync
sed
squashfs-tools
syslinux
syslinux-devel
xorriso
xz
zlib
zlib-devel

View File

@ -1,28 +0,0 @@
NAME='Manjaro'
SUPPORTED='yes'
CHECK_METHOD='egrep "^NAME=\"Manjaro Linux\"$" /etc/os-release'
PKG_MGR='pacman -S --needed --noconfirm ${pkgname}'
PRE_RUN='pacman -Syyy --noconfirm'
PKG_CHK='pacman -Q ${pkgname}'
URL='https://manjaro.org/'

function distro_specific_tweaks {
# For some reason, I can't get "yes y | " to parse correctly with eval. And Arch isn't smart enough
# to figure out that if I enable the multilib repos, *I want multilib gcc*. Fuck it. We'll just remove it first.

pacman -S --needed --noconfirm haveged >> "${LOGFILE}.${FUNCNAME}" 2>&1
haveged

set +e
for pkg_override in gcc gcc-libs;
do
pacman -Q ${pkg_override} >> "${LOGFILE}.${FUNCNAME}" 2>&1
if [[ "${?}" == "0" ]];
then
pacman -Rdd --noconfirm ${pkg_override} >> "${LOGFILE}.${FUNCNAME}" 2>&1
pacman -S --noconfirm ${pkg_override}-multilib >> "${LOGFILE}.${FUNCNAME}" 2>&1
fi
done
set -e

}

View File

@ -1 +0,0 @@
../Arch/pkgs

View File

@ -1,14 +0,0 @@
NAME='Mint'
SUPPORTED='no'
# Needs non-systemd chroot method
CHECK_METHOD='egrep "^DESCRIPTION=\"Linux\ Mint" /etc/linuxmint/info'
PKG_MGR='apt-get -y install ${pkgname}'
PRE_RUN='apt-get -y update'
PKG_CHK='dpkg-query -l ${pkgname}'
URL='http://www.linuxmint.com/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1 +0,0 @@
../Ubuntu/pkgs

View File

@ -1,15 +0,0 @@
NAME='RHEL'
SUPPORTED='yes'
# Red Hat Enterprise Linux Server release 6.5 (Santiago)
CHECK_METHOD='egrep "^Red\ Hat\ Enterprise\ Linux" /etc/redhat-release'
PKG_MGR='yum -y install'
PRE_RUN='none'
PKG_CHK='rpm -q ${pkgname} | egrep "^${pkgname}-[0-9]"'
URL='http://www.redhat.com/en/technologies/linux-platforms/enterprise-linux'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1,21 +0,0 @@
binutils
binutils-devel
curl
dosfstools
gcc
git
libisofs
lynx
make
mtools
patch
perl
rsync
sed
squashfs-tools
syslinux
syslinux-devel
xz
xz-devel
zlib
zlib-devel

View File

@ -1,16 +0,0 @@
NAME='SUSE'
SUPPORTED='yes'
# Both SLED and SLES. We can probably safely combine them.
CHECK_METHOD='egrep "^NAME=\"SLE(D|S)\"$" /etc/os-release'
PKG_MGR='zypper install --no-confirm -l ${pkgname}'
PRE_RUN='zypper refresh'
PKG_CHK='rpm -q ${pkgname} | egrep "^${pkgname}-[0-9]"'
URL='https://www.suse.com/'

function distro_specific_tweaks {
# See the centos_is_stupid function. we do some tweaks there since -devel pkgs require the SDK on SLES/SLED.

echo "No tweaks found."

}

View File

@ -1 +0,0 @@
../openSUSE/pkgs

View File

@ -1,14 +0,0 @@
NAME='Ubuntu'
SUPPORTED='yes'
CHECK_METHOD='egrep "^DISTRIB_ID=Ubuntu$" /etc/lsb-release'
PKG_MGR='apt-get -y install ${pkgname}'
PRE_RUN='apt-get -y update'
PKG_CHK='dpkg-query -l ${pkgname} | egrep "^ii[[:space:]]*${pkgname}"'
URL='http://www.ubuntu.com/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1,25 +0,0 @@
binutils
binutils-dev
curl
dosfstools
gcc
gcc-multilib
git
isolinux
libiberty-dev
libisoburn1
lynx
liblzma5
liblzma-dev
make
mtools
patch
perl
rsync
sed
squashfs-tools
syslinux
xorriso
xz-utils
zlib1g
zlib1g-dev

View File

@ -1,14 +0,0 @@
NAME='elementaryOS'
SUPPORTED='no'
CHECK_METHOD='egrep "^DISTRIB_ID=\"elementary OS\"$" /etc/lsb-release'
PKG_MGR='apt-get -y install ${pkgname}'
PRE_RUN='apt-get -y update'
PKG_CHK='dpkg-query -l ${pkgname} | egrep "^ii[[:space:]]*${pkgname}"'
URL='https://elementary.io/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1 +0,0 @@
../Ubuntu/pkgs

View File

@ -1,39 +0,0 @@
arch-install-scripts
archiso
bzip2
coreutils
cronie
dhclient
dhcp
dhcpcd
dosfstools
efibootmgr
efivar
ethtool
file
findutils
iproute2
iputils
libisoburn
localepurge
lz4
lzo
lzop
mkinitcpio-nfs-utils
ms-sys
mtools
net-tools
netctl
networkmanager
openssh
openvpn
prebootloader
pv
rsync
sed
shorewall
squashfs-tools
sudo
sysfsutils
syslinux
traceroute

View File

@ -1 +0,0 @@
# This can be used for 32-bit only packages

View File

@ -1 +0,0 @@
# This can be used for 64-bit only packages

View File

@ -1,15 +0,0 @@
NAME='openSUSE'
SUPPORTED='yes'
# Default doesn't have the quotes around the value, but I have a feeling that's a bug that will get "fixed" soon.
CHECK_METHOD='egrep "^NAME=\"?openSUSE\"?$" /etc/os-release'
PKG_MGR='zypper install --no-confirm -l ${pkgname}'
PRE_RUN='zypper refresh'
PKG_CHK='rpm -q ${pkgname} | egrep "^${pkgname}-[0-9]"'
URL='https://www.opensuse.org/'

function distro_specific_tweaks {

echo "No tweaks found."

}

View File

@ -1,22 +0,0 @@
binutils
binutils-devel
binutils-devel-32bit
curl
dosfstools
gcc
gcc-32bit
git
libisoburn1
libisofs6
lynx
make
mtools
patch
perl
rsync
sed
squashfs
syslinux
xz
xz-devel
xz-devel-32bit