Skip to content

Commit

Permalink
flag for apt pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Nov 21, 2023
1 parent d5fefa8 commit 047239d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@ Generate customized Debian ISO images for automatic deployments.

Run `build.sh` to generate a hands-free iso image.

```
./build.sh [-u username] [-p password] [-n hostname] [-d domain] [-a package] [-i iso_url] [-s sign_key] [-o path] [-v] [-h]
```

### Requirements

The following command installs all requirements on a Debian based system:

```sh
sudo apt update
sudo apt install curl git gnupg pwgen whois xorriso
```

### Example

```sh
git clone https://github.com/nothub/debian-autoinstall.git
cd debian-autoinstall
# customize authorized ssh keys
curl -sSLo configs/authorized_keys https://github.com/nothub.keys
./build.sh -u "hub" -n "mainframe" -d "hub.lol"
# set hostname and domain
./build.sh -n 'calculon' -d 'home.arpa'
# include additional apt packages
./build.sh -a 'strace' -a 'unattended-upgrades'
```

### Flags
Expand All @@ -22,6 +39,7 @@ curl -sSLo configs/authorized_keys https://github.com/nothub.keys
-p <password> Admin password
-n <hostname> Machine hostname
-d <domain> Machine domain
-a <package> Additional apt package
-i <iso_url> ISO download URL
-s <sign_key> ISO pgp sign key
-o <out_file> ISO output file
Expand Down
14 changes: 9 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ set -o nounset
set -o pipefail

usage() {
echo "Usage: $0 [-u username] [-p password] [-n hostname] [-d domain] [-i iso_url] [-s sign_key] [-o path] [-v] [-h]"
echo "Usage: $0 [-u username] [-p password] [-n hostname] [-d domain] [-a package] [-i iso_url] [-s sign_key] [-o path] [-v] [-h]"
echo "Options:"
echo " -u <username> Admin username"
echo " -p <password> Admin password"
echo " -n <hostname> Machine hostname"
echo " -d <domain> Machine domain"
echo " -a <package> Additional apt package"
echo " -i <iso_url> ISO download URL"
echo " -s <sign_key> ISO pgp sign key"
echo " -o <out_file> ISO output file"
Expand All @@ -25,13 +26,15 @@ domain="example.org"
iso_url="https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.2.0-amd64-netinst.iso"
sign_key="DA87E80D6294BE9B"
out_file="debian-12.2.0-amd64-auto.iso"
apt_pkgs=()

while getopts u:p:n:d:i:s:o:vh opt; do
while getopts u:p:n:d:a:i:s:o:vh opt; do
case $opt in
u) username="$OPTARG" ;;
p) password="$OPTARG" ;;
n) hostname="$OPTARG" ;;
d) domain="$OPTARG" ;;
a) apt_pkgs+=("$OPTARG") ;;
i) iso_url="$OPTARG" ;;
s) sign_key="$OPTARG" ;;
o) out_file="$OPTARG" ;;
Expand Down Expand Up @@ -83,9 +86,10 @@ cp -a installer/* "${workdir}"
find "${workdir}" -type f -exec sed -i "s#@USERNAME@#${username}#" {} \;
salt="$(pwgen -ns 16 1)"
hash="$(mkpasswd -m sha-512 -S "${salt}" "${password}")"
sed -i "s#@PASSHASH@#${hash}#" "${workdir}/preseed.cfg"
sed -i "s#@HOSTNAME@#${hostname}#" "${workdir}/preseed.cfg"
sed -i "s#@DOMAIN@#${domain}#" "${workdir}/preseed.cfg"
sed -i "s#@PASSHASH@#${hash}#" "${workdir}/preseed.cfg"
sed -i "s#@HOSTNAME@#${hostname}#" "${workdir}/preseed.cfg"
sed -i "s#@DOMAIN@#${domain}#" "${workdir}/preseed.cfg"
sed -i "s#@PACKAGES@#${apt_pkgs[*]}#" "${workdir}/preseed.cfg"

# repack iso
rm -f "${iso_file//.iso/-auto.iso}"
Expand Down
5 changes: 1 addition & 4 deletions installer/preseed.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ d-i apt-setup/non-free-firmware boolean true
d-i apt-setup/disable-cdrom-entries boolean true

### Packages
# (this selection includes the unattended-upgrades package!)
tasksel tasksel/first multiselect standard
d-i pkgsel/include string \
bash \
Expand All @@ -67,9 +66,7 @@ d-i pkgsel/include string \
micro \
net-tools \
openssh-server \
openssl \
strace \
unattended-upgrades
openssl @PACKAGES@
d-i pkgsel/upgrade select full-upgrade
popularity-contest popularity-contest/participate boolean true

Expand Down

0 comments on commit 047239d

Please sign in to comment.