refactored appimg build scripts

This commit is contained in:
Bruce Leidl 2018-02-20 12:19:19 -05:00
parent 13fae562f9
commit f3a13f6e6d
2 changed files with 102 additions and 53 deletions

View File

@ -1,40 +1,56 @@
#!/bin/bash
DEBIAN_MIRROR="https://deb.debian.org/debian"
DEBIAN_RELEASE="buster"
#SCRIPT=$(realpath ${BASH_SOURCE})
SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE}))
DBS_BASE=$(realpath ${SCRIPT_DIR}/../build/debootstrap)
DBS_ROOT=${DBS_BASE}/rootfs
CACHE_DIR=${DBS_BASE}/var-cache-apt-archives
[[ -d ${DBS_ROOT} ]] && rm -rf ${DBS_ROOT}
[[ -f ${CACHE_DIR}/lock ]] && rm -f ${CACHE_DIR}/lock
mkdir -p ${CACHE_DIR} ${DBS_ROOT}/var/cache/apt/archives
mount --bind ${CACHE_DIR} ${DBS_ROOT}/var/cache/apt/archives
run_debootstrap() {
[[ -d ${DBS_ROOT} ]] && rm -rf ${DBS_ROOT}
debootstrap --verbose --merged-usr --variant=minbase --include=systemd-sysv,locales \
[[ -f ${CACHE_DIR}/lock ]] && rm -f ${CACHE_DIR}/lock
mkdir -p ${CACHE_DIR} ${DBS_ROOT}/var/cache/apt/archives
mount --bind ${CACHE_DIR} ${DBS_ROOT}/var/cache/apt/archives
debootstrap --verbose --merged-usr --variant=minbase \
--include=systemd-sysv,locales \
--exclude=sysv-rc,initscripts,startpar,lsb-base,insserv \
buster ${DBS_ROOT}
${DEBIAN_RELEASE} ${DBS_ROOT} ${DEBIAN_MIRROR}
}
mount chproc ${DBS_ROOT}/proc -t proc
mount chsys ${DBS_ROOT}/sys -t sysfs
run_chroot_stage() {
mount chproc ${DBS_ROOT}/proc -t proc
mount chsys ${DBS_ROOT}/sys -t sysfs
cp --preserve=mode ${SCRIPT_DIR}/build-user-rootfs-stage-two ${DBS_ROOT}/root/install.sh
cp --preserve=mode ${SCRIPT_DIR}/build-user-rootfs-stage-two ${DBS_ROOT}/root/install.sh
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${DBS_ROOT} /root/install.sh
rm -f ${DBS_ROOT}/root/install.sh
umount ${DBS_ROOT}/proc
umount ${DBS_ROOT}/sys
umount ${DBS_ROOT}/var/cache/apt/archives
rm -f ${DBS_ROOT}/var/cache/apt/pkgcache.bin
rm -f ${DBS_ROOT}/var/cache/apt/srcpkgcache.bin
printf "\n\n----- Generating compressed tarball (this will take a couple of minutes) -----\n\n"
tar -C ${DBS_ROOT} -c --xattrs --xattrs-include=* -f ${DBS_BASE}/user-rootfs.tar .
xz --force --threads=0 ${DBS_BASE}/user-rootfs.tar
ls -al ${DBS_BASE}/user-rootfs.tar.xz
printf "\n\n"
DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true LC_ALL=C LANGUAGE=C LANG=C chroot ${DBS_ROOT} /root/install.sh ${DEBIAN_RELEASE} ${DEBIAN_MIRROR}
rm -f ${DBS_ROOT}/root/install.sh
}
cleanup_chroot() {
umount ${DBS_ROOT}/proc
umount ${DBS_ROOT}/sys
umount ${DBS_ROOT}/var/cache/apt/archives
rm -f ${DBS_ROOT}/var/cache/apt/pkgcache.bin
rm -f ${DBS_ROOT}/var/cache/apt/srcpkgcache.bin
}
generate_tarball() {
printf "\n\n----- Generating rootfs tarball -----\n\n"
tar -C ${DBS_ROOT} -c --xattrs --xattrs-include=* -f ${DBS_BASE}/user-rootfs.tar .
#xz --force --threads=0 ${DBS_BASE}/user-rootfs.tar
ls -al ${DBS_BASE}/user-rootfs.tar
printf "\n\n"
}
run_debootstrap
run_chroot_stage
cleanup_chroot
generate_tarball

View File

@ -1,40 +1,73 @@
#!/bin/bash
PACKAGES="man manpages vim less xz-utils sudo tmux dbus libpam-systemd vifm openssh-client gnome-terminal packagekit-gtk3-module libcanberra-gtk3-module firefox fonts-roboto-hinted nautilus eog evince unzip"
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
update-locale LANG=en_US.UTF-8
export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8
setup_locale() {
echo "en_US.UTF-8 UTF-8" > /etc/locale.gen
locale-gen
update-locale LANG=en_US.UTF-8
export LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_CTYPE=en_US.UTF-8
}
mkdir -p /etc/systemd/user.conf.d
printf '[Manager]\nDefaultEnvironment="DISPLAY=:0"\n' > /etc/systemd/user.conf.d/50-display-env.conf
configure_systemd() {
mkdir -p /etc/systemd/user.conf.d
printf '[Manager]\nDefaultEnvironment="DISPLAY=:0"\n' > /etc/systemd/user.conf.d/50-display-env.conf
mkdir -p /etc/systemd/logind.conf.d
printf 'KillUserProcesses=no\n' > /etc/systemd/logind.conf.d/50-no-kill-user-processes.conf
mkdir -p /etc/systemd/logind.conf.d
printf 'KillUserProcesses=no\n' > /etc/systemd/logind.conf.d/50-no-kill-user-processes.conf
}
mkdir -p /usr/libexec
cat > /usr/libexec/launch <<- 'EOF'
#!/bin/bash
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export XDG_RUNTIME_DIR=/run/user/1000
export PULSE_SERVER=unix:/run/user/host/pulse/native
$@
write_launch_script() {
mkdir -p /usr/libexec
cat > /usr/libexec/launch <<- 'EOF'
#!/bin/bash
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
export XDG_RUNTIME_DIR=/run/user/1000
export PULSE_SERVER=unix:/run/user/host/pulse/native
$@
EOF
chmod +x /usr/libexec/launch
chmod +x /usr/libexec/launch
}
printf "127.0.0.1\tsubgraph localhost\n" > /etc/hosts
echo "subgraph" > /etc/hostname
echo "deb http://http.debian.net/debian unstable main" >> /etc/apt/sources.list
useradd -s /bin/bash -m user
echo "user:user" | chpasswd
usermod -aG sudo user
echo "export DISPLAY=:0" >> /home/user/.bashrc
generate_apt_sources() {
echo "deb ${DEBIAN_MIRROR} ${DEBIAN_RELEASE} main contrib non-free"
echo "deb ${DEBIAN_MIRROR}-security ${DEBIAN_RELEASE}/updates main contrib non-free"
echo "deb ${DEBIAN_MIRROR} unstable main"
}
apt-get update
apt-get --assume-yes upgrade
apt-get --assume-yes --no-install-recommends install ${PACKAGES}
setup_etc() {
printf "127.0.0.1\tsubgraph localhost\n" > /etc/hosts
echo "subgraph" > /etc/hostname
generate_apt_sources > /etc/apt/sources.list
}
printf "\n\nInstalled Packages\n\n"
dpkg -l
create_user() {
useradd -s /bin/bash -m user
echo "user:user" | chpasswd
usermod -aG sudo user
echo "export DISPLAY=:0" >> /home/user/.bashrc
}
install_packages() {
apt-get update
apt-get --assume-yes upgrade
apt-get --assume-yes --no-install-recommends install ${PACKAGES}
printf "\n\nInstalled Packages\n\n"
dpkg -l
}
set -u
set -e
DEBIAN_RELEASE=${1}
DEBIAN_MIRROR=${2}
setup_locale
configure_systemd
write_launch_script
setup_etc
create_user
install_packages