Debian 9 base system (amd64)

by sanvila
1 deployments · 1 still active · last rev. 5 months ago

This script tries to emulate a Debian install in which you only install the "base system" and python.

Compatible with: Debian 9
						#!/bin/sh
# Script to install packages in the "base system", and only those.
# Originally written by Santiago Vila <sanvila@debian.org>. 2018-05-16.
# This script is in the public domain.
#
# The list of packages in the base system was created by doing this:
#
# Install Debian 9 for amd64 on a qemu virtual machine, using debian-installer.
#
# Only the base system was installed:
#
# [*] Install the base system
# [ ] Configure the package manager
# [ ] Select and install software
# [*] Install the GRUB boot loader on a hard disk
#
# Then install the following two packages without their Recommends:
#
# - openssh-server
# - python
#
# Then purge the following packages:
#
# - libgdbm3
# - libxapian30
# - libpipeline1
#
# That's all.
#
# It would be possible to purge more unneeded packages
# but we have to draw the line somewhere.
#
#####################################################################
#
# Support functions
#

lines_in_2_not_in_1() {
  awk '{ if (FILENAME == ARGV[1]) { a[$0] = 1 } else if (! ($0 in a)) { print $0 } }' $1 $2
}

installed_packages() {
  cd /var/lib/dpkg/info
  ls *.list | sed -e 's/\.list//' | sed -e 's/:.*//' | LC_ALL=C sort
}

install_wanted_packages() {
  apt-get -y -o APT::Install-Recommends="0" install $(cat /root/packages.txt)
}

remove_unwanted_packages() {
  list=$(tempfile)
  installed_packages > ${list}
  purge=$(lines_in_2_not_in_1 /root/packages.txt ${list})
  rm -f ${list}
  if [ "${purge}" != "" ]; then
    dpkg --purge ${purge}
  fi
}

#
# First the script parses itself to create /root/packages.txt
#
splitscript=$(tempfile)
tail -n 14 $0 > ${splitscript}
awk -f ${splitscript} $0
rm -f ${splitscript}

#
# Then it does what it's supposed to do
#
(
apt-get update
echo debconf debconf/frontend select Noninteractive | debconf-set-selections
install_wanted_packages
remove_unwanted_packages
apt-get clean
) | tee /root/StackScript.log
exit 0

# List of wanted packages
START
FILE: 644 /root/packages.txt
adduser
apt
apt-utils
base-files
base-passwd
bash
bsdmainutils
bsdutils
busybox
console-setup
console-setup-linux
coreutils
cpio
cron
dash
debconf
debconf-i18n
debian-archive-keyring
debianutils
diffutils
dmidecode
dmsetup
dpkg
e2fslibs
e2fsprogs
eject
findutils
gcc-6-base
gettext-base
gnupg
gnupg-agent
gpgv
grep
grub-common
grub-pc
grub-pc-bin
grub2-common
gzip
hostname
ifupdown
init
init-system-helpers
initramfs-tools
initramfs-tools-core
iproute2
iptables
iputils-ping
isc-dhcp-client
isc-dhcp-common
kbd
keyboard-configuration
klibc-utils
kmod
libacl1
libapparmor1
libapt-inst2.0
libapt-pkg5.0
libassuan0
libattr1
libaudit-common
libaudit1
libblkid1
libbsd0
libbz2-1.0
libc-bin
libc-l10n
libc6
libcap-ng0
libcap2
libcomerr2
libcryptsetup4
libdb5.3
libdebconfclient0
libdevmapper1.02.1
libdns-export162
libedit2
libelf1
libestr0
libexpat1
libfastjson4
libfdisk1
libffi6
libfreetype6
libfuse2
libgcc1
libgcrypt20
libgmp10
libgnutls30
libgpg-error0
libgssapi-krb5-2
libhogweed4
libidn11
libidn2-0
libip4tc0
libip6tc0
libiptc0
libisc-export160
libk5crypto3
libkeyutils1
libklibc
libkmod2
libkrb5-3
libkrb5support0
libksba8
liblocale-gettext-perl
liblogging-stdlog0
liblognorm5
liblz4-1
liblzma5
libmnl0
libmount1
libncurses5
libncursesw5
libnetfilter-conntrack3
libnettle6
libnewt0.52
libnfnetlink0
libnpth0
libp11-kit0
libpam-modules
libpam-modules-bin
libpam-runtime
libpam0g
libpci3
libpcre3
libpng16-16
libpopt0
libprocps6
libpsl5
libpython-stdlib
libpython2.7-minimal
libpython2.7-stdlib
libreadline7
libseccomp2
libselinux1
libsemanage-common
libsemanage1
libsepol1
libslang2
libsmartcols1
libsqlite3-0
libss2
libssl1.0.2
libssl1.1
libstdc++6
libsystemd0
libtasn1-6
libtext-charwidth-perl
libtext-iconv-perl
libtext-wrapi18n-perl
libtinfo5
libudev1
libunistring0
libusb-1.0-0
libustr-1.0-1
libuuid1
libwrap0
libxtables12
linux-base
linux-image-4.9.0-6-amd64
linux-image-amd64
locales
login
logrotate
lsb-base
mawk
mime-support
mount
multiarch-support
nano
ncurses-base
ncurses-bin
netbase
openssh-client
openssh-server
openssh-sftp-server
os-prober
passwd
pciutils
perl-base
pinentry-curses
procps
python
python-minimal
python2.7
python2.7-minimal
readline-common
rsyslog
sed
sensible-utils
systemd
systemd-sysv
sysvinit-utils
tar
tasksel
tasksel-data
tzdata
ucf
udev
usbutils
util-linux
vim-common
vim-tiny
wget
whiptail
xkb-data
xxd
zlib1g
STOP
#!/usr/bin/awk -f
/^STOP/ { status = 2 }
status == 1 {
  if ($0 ~ /^FILE:/) {
    mode = $2
    file = $3
    system("touch " file)
    system("chmod " mode " " file)
  }
  else {
    print $0 > file
  }
}
/^START/ { status = 1 }