Skip to content

Instantly share code, notes, and snippets.

@pward123
Forked from takumin/debootstrap.sh
Created September 22, 2020 14:58
Show Gist options
  • Save pward123/91ee6ad2af01f347c3bbe972ac7a2d3d to your computer and use it in GitHub Desktop.
Save pward123/91ee6ad2af01f347c3bbe972ac7a2d3d to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Run Script
# wget -qO - "https://git.io/vUGQt" | sudo sh
# Edit Script
# wget -q --content-disposition "https://git.io/vUGQt"
#
set -e
DIST=debian
SUITE=jessie
ARCH=amd64
MIRROR=http://srv:3142/${DIST}/
ROOTFS=chroot
DEBOPT="--variant=minbase"
dpkg -l | grep -qs debootstrap || apt-get install debootstrap
dpkg -l | grep -qs squashfs-tools || apt-get install squashfs-tools
mount | grep -qs ${ROOTFS}/dev/pts && umount -lf ${ROOTFS}/dev/pts
mount | grep -qs ${ROOTFS}/dev/shm && umount -lf ${ROOTFS}/dev/shm
mount | grep -qs ${ROOTFS}/proc && umount -lf ${ROOTFS}/proc
mount | grep -qs ${ROOTFS}/sys && umount -lf ${ROOTFS}/sys
mount | grep -qs ${ROOTFS}/dev && umount -lf ${ROOTFS}/dev
test -d ${ROOTFS} && rm -fr ${ROOTFS}
test -f rootfs.sfs.xz && rm -fr rootfs.sfs.xz
debootstrap --arch=${ARCH} ${DEBOPT} ${SUITE} ${ROOTFS} ${MIRROR}
mount --bind /dev ${ROOTFS}/dev
mount -t sysfs sysfs ${ROOTFS}/sys
mount -t proc proc ${ROOTFS}/proc
mount -t tmpfs tmpfs ${ROOTFS}/dev/shm
mount -t devpts devpts ${ROOTFS}/dev/pts
chroot ${ROOTFS} /bin/sh << '__EOS__'
#!/bin/sh
set -e
export HOME=/root
export LC_ALL=C
export LANGUAGE=C
export LANG=C
export DEBIAN_FRONTEND=noninteractive
export DEBIAN_PRIORITY=critical
export DEBCONF_NONINTERACTIVE_SEEN=true
# no install recommends/suggests packages
echo '// no install recommends/suggests packages' > /etc/apt/apt.conf.d/99norecommends
echo 'APT::Install-Recommends "false";' >> /etc/apt/apt.conf.d/99norecommends
echo 'APT::Install-Suggests "false";' >> /etc/apt/apt.conf.d/99norecommends
# assume yes install packages
echo '// assume yes install packages' > /etc/apt/apt.conf.d/99assumeyes
echo 'APT::Get::Assume-Yes "true";' >> /etc/apt/apt.conf.d/99assumeyes
# systemd require dbus
apt-get install dbus
# dbus initilized
dbus-uuidgen > /var/lib/dbus/machine-id
# delay configuration install packages
apt-get install apt-utils
# package configuration utility
apt-get install debconf-utils
# locale
echo 'locales locales/locales_to_be_generated multiselect ja_JP.UTF-8 UTF-8' | debconf-set-selections
echo 'locales locales/default_environment_locale select ja_JP.UTF-8' | debconf-set-selections
apt-get install locales
# tzdata
echo 'Asia/Tokyo' > /etc/timezone
cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime
dpkg-reconfigure tzdata
# enable root login
echo 'root:root' | chpasswd
# adduser live
adduser --disabled-password --gecos "Debian Live User,,," user
echo 'user:live' | chpasswd
# log
dpkg -l > /packages.log
debconf-get-selections > /configs.log
# cleanup
rm /var/lib/dbus/machine-id
apt-get clean
__EOS__
umount -lf ${ROOTFS}/dev/pts
umount -lf ${ROOTFS}/dev/shm
umount -lf ${ROOTFS}/proc
umount -lf ${ROOTFS}/sys
umount -lf ${ROOTFS}/dev
mv ${ROOTFS}/packages.log .
mv ${ROOTFS}/configs.log .
mksquashfs ${ROOTFS} rootfs.sfs.xz -comp xz -e boot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment