Several shell scripts in a wrapper pretending to be automation. User assumes all risk.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.3 KiB

# @author: 'grufwub'
# @origin: ''
# @source: ''
debootstrap='DEBOOTSTRAP_DIR=/opt/debootstrap/usr/share/debootstrap /opt/debootstrap/usr/sbin/debootstrap'
function install_debootstrap()
local curdir tmpdir
echo "Installing debootstrap"
tmpdir=$(mktemp -d)
cd $tmpdir
curl -o debootstrap.deb "$debootstrap_url"
ar x debootstrap.deb
sudo mkdir -p /opt/debootstrap
sudo cp data.tar.gz /opt/debootstrap
cd /opt/debootstrap
sudo tar -xf data.tar.gz
sudo rm -f data.tar.gz
cd $curdir
rm -rf $tmpdir
function mount_filesystems()
sudo echo -n '' # just to ensure we still have sudo
echo -n "Mounting filesystems..."
sudo mount -t proc /proc "$1/proc"
sudo mount -t sysfs /sys "$1/sys"
sudo mount -o bind /dev "$1/dev"
sudo mount -o bind /dev/pts "$1/dev/pts"
echo " Done!"
function unmount_filesystems()
sudo echo -n '' # just to ensure we still have sudo
echo -n "Unmounting filesystems..."
sudo umount "$1/proc"
sudo umount "$1/sys"
sudo umount "$1/dev/pts"
sudo umount "$1/dev"
echo " Done!"
function install_debian()
echo "Installing Debian..."
sudo bash -c "$debootstrap --arch amd64 buster '$1'"
echo -n "Writing Debian sources file..."
sudo bash -c "cat > '$1/etc/apt/sources.list'" << EOF
deb buster main non-free contrib
deb-src buster main non-free contrib
deb buster/updates main non-free contrib
deb-src buster/updates main non-free contrib
deb buster-updates main non-free contrib
deb-src buster-updates main non-free contrib
echo " Done!"
echo -n "Copying across hostname..."
sudo cp /etc/hostname "$1/etc/hostname"
echo " Done!"
mount_filesystems "$1"
echo "Performing initial package updates within chroot..."
sudo chroot "$1" /bin/bash -c 'apt-get update && apt-get dist-upgrade -y'
sudo chroot "$1" /bin/bash -c 'apt-get install -y locales'
sudo chroot "$1" /bin/bash -c '/usr/sbin/dpkg-reconfigure locales'
sudo chroot "$1" /bin/bash -c 'apt-get install -y nano sudo ncurses-term git curl wget'
echo "Creating group wheel"
sudo chroot "$1" /bin/bash -c "/usr/sbin/groupadd wheel"
echo "Adding group wheel to sudoers"
sudo chroot "$1" /bin/bash -c "echo '%wheel ALL=(ALL) ALL' >> /etc/sudoers"
echo "Creating user: $USER"
sudo chroot "$1" /bin/bash -c "/usr/sbin/useradd -m -g users -G sudo -s /bin/bash $USER"
echo "Please enter a password for $USER..."
sudo chroot "$1" /bin/bash -c "passwd $USER"
echo "Done!"
unmount_filesystems "$1"
if [ "`id -u`" -eq 0 ] ; then
echo "Please do not run this script as root."
exit 1
if ! wget -V > /dev/null 2>&1 ; then
echo "Please install wget. Required for debootstrap"
exit 1
if ! (bash -c "$debootstrap --version" > /dev/null 2>&1) ; then
if [[ "$1" == "" ]] ; then
echo "Please supply a chroot directory!"
exit 1
if [[ ! -d "$1" ]] ; then
echo "Creating directory: $1"
mkdir -p "$1"
install_debian "$1"
mount_filesystems "$1"
sudo chroot "$1" /bin/bash -c "su $USER --login"
unmount_filesystems "$1"