pull/8/head
Bohan Yang 5 years ago
parent 24747ac060
commit 80db45099e
  1. 31
      README.md
  2. 400
      netboot.sh

@ -22,30 +22,30 @@ This script is used to re-install VPS to **Debian 9 (stretch) or 10 (buster)** w
- `--ip` - `--ip`
- `--netmask` - `--netmask`
- `--gateway` - `--gateway`
- `--ns "8.8.8.8 8.8.4.4"` - `--dns "8.8.8.8 8.8.4.4"`
- `--hostname debian` - `--hostname debian`
- `--ethn` Disable Consistent Network Device Naming - `--eth` Disable Consistent Network Device Naming
- `--ssh-password` - `--installer-password`
- `--ssh-keys` - `--authorized-keys-url`
- `--protocol http` [`http`, `https`, `ftp`] - `--mirror-protocol http` [`http`, `https`, `ftp`]
- `--mirror deb.debian.org` - `--mirror-host deb.debian.org`
- `--directory /debian` - `--mirror-directory /debian`
- `--suite stable` - `--suite stable`
- `--skip-user` - `--skip-account-setup`
- `--username debian` - `--username debian`
- `--password` - `--password`
- `--timezone UTC` https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List - `--timezone UTC` https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
- `--ntp 0.debian.pool.ntp.org` - `--ntp 0.debian.pool.ntp.org`
- `--skip-part` - `--skip-partitioning`
- `--disk` - `--disk`
- `--part` - `--partitioning-method`
- `--fs ext4` - `--filesystem ext4`
- `--kernel` Specify another kernel image, e.g. `linux-image-cloud-amd64` - `--kernel` Specify another package for kernel image, e.g. `linux-image-cloud-amd64`
- `--security http://security.debian.org/debian-security` - `--security-repository http://security.debian.org/debian-security`
- `--install` - `--install`
- `--upgrade full-upgrade` [`none`, `safe-upgrade`, `full-upgrade`] - `--upgrade full-upgrade` [`none`, `safe-upgrade`, `full-upgrade`]
- `--poweroff` - `--power-off`
- `--arch` - `--architecture`
- `--boot-partition` - `--boot-partition`
- `--dry-run` - `--dry-run`
@ -57,7 +57,6 @@ This script is used to re-install VPS to **Debian 9 (stretch) or 10 (buster)** w
- `--protocol https` - `--protocol https`
- `--mirror mirrors.aliyun.com` - `--mirror mirrors.aliyun.com`
- `--security true` - `--security true`
- `--timezone Asia/Shanghai`
- `--ntp ntp.aliyun.com` - `--ntp ntp.aliyun.com`
### `cloud` ### `cloud`

@ -1,187 +1,214 @@
#!/usr/bin/env sh #!/usr/bin/env bash
set -e set -eu
echo_stderr() { _err() {
echo "$@" 1>&2 printf 'Error: %s.' "$1" 1>&2
} }
command_exists() { command_exists() {
command -v "$@" >/dev/null 2>&1 command -v "$1" >/dev/null 2>&1
} }
read_secret() _late_command() {
{ [ -z "$late_command" ] && late_command='true'
stty -echo late_command="$late_command; $1"
trap 'stty echo' EXIT
read -r "$@"
stty echo
trap - EXIT
echo
} }
late_command=
preset=
ip=
netmask=
gateway=
dns=
hostname=
kernel_params=
installer_ssh=
installer_password=
authorized_keys_url=
mirror_protocol=
mirror_host=
mirror_directory=
suite=
skip_account_setup=
username=
password=
timezone=
ntp=
skip_partitioning=
disk=
partitioning_method=
filesystem=
kernel=
security_repository=
install=
upgrade=
power_off=
architecture=
boot_partition=
dry_run=
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
--preset) --preset)
DEBI_PRESET=$2 preset=$2
shift shift
;; ;;
--ip) --ip)
DEBI_IP=$2 ip=$2
shift shift
;; ;;
--netmask) --netmask)
DEBI_NETMASK=$2 netmask=$2
shift shift
;; ;;
--gateway) --gateway)
DEBI_GATEWAY=$2 gateway=$2
shift shift
;; ;;
--ns) --dns)
DEBI_NS=$2 dns=$2
shift shift
;; ;;
--hostname) --hostname)
DEBI_HOSTNAME=$2 hostname=$2
shift shift
;; ;;
--ethn) --eth)
DEBI_KERNEL_PARAMS=' net.ifnames=0 biosdevname=0' kernel_params=' net.ifnames=0 biosdevname=0'
;; ;;
--ssh-password) --installer-password)
DEBI_SSH=true installer_ssh=true
DEBI_SSH_PASSWORD=$2 installer_password=$2
shift shift
;; ;;
--ssh-keys) --authorized-keys-url)
DEBI_SSH=true installer_ssh=true
DEBI_SSH_KEYS=$2 authorized_keys_url=$2
shift shift
;; ;;
--protocol) --mirror-protocol)
DEBI_PROTOCOL=$2 mirror_protocol=$2
shift shift
;; ;;
--mirror) --mirror-host)
DEBI_MIRROR=$2 mirror_host=$2
shift shift
;; ;;
--directory) --mirror-directory)
DEBI_DIRECTORY=${2%/} mirror_directory=${2%/}
shift shift
;; ;;
--suite) --suite)
DEBI_SUITE=$2 suite=$2
shift shift
;; ;;
--skip-user) --skip-account-setup)
DEBI_SKIP_USER=true skip_account_setup=true
;; ;;
--username) --username)
DEBI_USERNAME=$2 username=$2
shift shift
;; ;;
--password) --password)
DEBI_PASSWORD=$2 password=$2
shift shift
;; ;;
--timezone) --timezone)
DEBI_TIMEZONE=$2 timezone=$2
shift shift
;; ;;
--ntp) --ntp)
DEBI_NTP=$2 ntp=$2
shift shift
;; ;;
--skip-part) --skip-partitioning)
DEBI_SKIP_PART=true skip_partitioning=true
;; ;;
--disk) --disk)
DEBI_DISK=$2 disk=$2
shift shift
;; ;;
--part) --partitioning-method)
DEBI_PART=$2 partitioning_method=$2
shift shift
;; ;;
--fs) --filesystem)
DEBI_FS=$2 filesystem=$2
shift shift
;; ;;
--kernel) --kernel)
DEBI_KERNEL=$2 kernel=$2
shift shift
;; ;;
--security) --security-repository)
DEBI_SECURITY=$2 security_repository=$2
shift shift
;; ;;
--install) --install)
DEBI_INSTALL=$2 install=$2
shift shift
;; ;;
--upgrade) --upgrade)
DEBI_UPGRADE=$2 upgrade=$2
shift shift
;; ;;
--poweroff) --power-off)
DEBI_POWEROFF=true power_off=true
;; ;;
--arch) --architecture)
DEBI_ARCH=$2 architecture=$2
shift shift
;; ;;
--boot-partition) --boot-partition)
DEBI_BOOT_PARTITION=true boot_partition=true
;; ;;
--dry-run) --dry-run)
DEBI_DRY_RUN=true dry_run=true
;; ;;
*) *)
echo_stderr "Error: Illegal option $1" _err "Illegal option $1"
exit 1 exit 1
esac esac
shift shift
done done
if [ -n "$DEBI_PRESET" ]; then if [ -n "$preset" ]; then
case "$DEBI_PRESET" in case "$preset" in
china) china)
DEBI_NS=${DEBI_NS:-223.5.5.5 223.6.6.6} dns=${dns:-223.5.5.5 223.6.6.6}
DEBI_PROTOCOL=${DEBI_PROTOCOL:-https} mirror_protocol=${mirror_protocol:-https}
DEBI_MIRROR=${DEBI_MIRROR:-mirrors.aliyun.com} mirror_host=${mirror_host:-mirrors.aliyun.com}
DEBI_TIMEZONE=${DEBI_TIMEZONE:-Asia/Shanghai} ntp=${ntp:-ntp.aliyun.com}
DEBI_NTP=${DEBI_NTP:-ntp.aliyun.com} security_repository=${security_repository:-true}
DEBI_SECURITY=${DEBI_SECURITY:-true}
;; ;;
cloud) cloud)
DEBI_PROTOCOL=${DEBI_PROTOCOL:-https} mirror_protocol=${mirror_protocol:-https}
DEBI_MIRROR=${DEBI_MIRROR:-deb.debian.org} mirror_host=${mirror_host:-deb.debian.org}
DEBI_SECURITY=${DEBI_SECURITY:-true} security_repository=${security_repository:-true}
;; ;;
*) *)
echo_stderr "Error: No such preset $DEBI_PRESET" _err "No such preset $preset"
exit 1 exit 1
esac esac
fi fi
DEBI_SUITE=${DEBI_SUITE:-stable} suite=${suite:-stable}
DEBI_NEW="debian-$DEBI_SUITE" installer="debian-$suite"
DEBI_NEW_DIR="/boot/$DEBI_NEW" installer_directory="/boot/$installer"
save_preseed="cat" save_preseed="cat"
if [ "$DEBI_DRY_RUN" != true ]; then if [ "$dry_run" != true ]; then
user="$(id -un 2>/dev/null || true)" user="$(id -un 2>/dev/null || true)"
if [ "$user" != root ]; then if [ "$user" != root ]; then
echo_stderr 'Error: Require root.' _err 'root privilege is required'
exit 1 exit 1
fi fi
rm -rf "$DEBI_NEW_DIR" rm -rf "$installer_directory"
mkdir -p "$DEBI_NEW_DIR" mkdir -p "$installer_directory"
cd "$DEBI_NEW_DIR" cd "$installer_directory"
save_preseed='tee -a preseed.cfg' save_preseed='tee -a preseed.cfg'
fi fi
@ -196,19 +223,19 @@ d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto d-i netcfg/choose_interface select auto
EOF EOF
DEBI_NS=${DEBI_NS:-8.8.8.8 8.8.4.4} dns=${dns:-8.8.8.8 8.8.4.4}
if [ -n "$DEBI_IP" ]; then if [ -n "$ip" ]; then
echo 'd-i netcfg/disable_autoconfig boolean true' | $save_preseed echo 'd-i netcfg/disable_autoconfig boolean true' | $save_preseed
echo "d-i netcfg/get_ipaddress string $DEBI_IP" | $save_preseed echo "d-i netcfg/get_ipaddress string $ip" | $save_preseed
if [ -n "$DEBI_NETMASK" ]; then if [ -n "$netmask" ]; then
echo "d-i netcfg/get_netmask string $DEBI_NETMASK" | $save_preseed echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
fi fi
if [ -n "$DEBI_GATEWAY" ]; then if [ -n "$gateway" ]; then
echo "d-i netcfg/get_gateway string $DEBI_GATEWAY" | $save_preseed echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
fi fi
if [ -n "$DEBI_NS" ]; then if [ -n "$dns" ]; then
echo "d-i netcfg/get_nameservers string $DEBI_NS" | $save_preseed echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
fi fi
echo 'd-i netcfg/confirm_static boolean true' | $save_preseed echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
fi fi
@ -218,13 +245,13 @@ d-i netcfg/get_hostname string debian
d-i netcfg/get_domain string d-i netcfg/get_domain string
EOF EOF
if [ -n "$DEBI_HOSTNAME" ]; then if [ -n "$hostname" ]; then
echo "d-i netcfg/hostname string $DEBI_HOSTNAME" | $save_preseed echo "d-i netcfg/hostname string $hostname" | $save_preseed
fi fi
echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed
if [ "$DEBI_SSH" = true ]; then if [ "$installer_ssh" = true ]; then
$save_preseed << EOF $save_preseed << EOF
# Network console # Network console
@ -232,64 +259,65 @@ if [ "$DEBI_SSH" = true ]; then
d-i anna/choose_modules string network-console d-i anna/choose_modules string network-console
d-i preseed/early_command string anna-install network-console d-i preseed/early_command string anna-install network-console
EOF EOF
if [ -n "$DEBI_SSH_PASSWORD" ]; then if [ -n "$authorized_keys_url" ]; then
_late_command "cd ~$username && mkdir -m 700 .ssh && wget -qO .ssh/authorized_keys $authorized_keys_url"
$save_preseed << EOF $save_preseed << EOF
d-i network-console/password-disabled boolean false d-i network-console/password-disabled boolean true
d-i network-console/password password $DEBI_SSH_PASSWORD d-i network-console/authorized_keys_url string $authorized_keys_url
d-i network-console/password-again password $DEBI_SSH_PASSWORD
EOF EOF
elif [ -n "$DEBI_SSH_KEYS" ]; then elif [ -n "$installer_password" ]; then
$save_preseed << EOF $save_preseed << EOF
d-i network-console/password-disabled boolean true d-i network-console/password-disabled boolean false
d-i network-console/authorized_keys_url string $DEBI_SSH_KEYS d-i network-console/password password $installer_password
d-i network-console/password-again password $installer_password
EOF EOF
fi fi
echo 'd-i network-console/start select Continue' | $save_preseed echo 'd-i network-console/start select Continue' | $save_preseed
fi fi
DEBI_PROTOCOL=${DEBI_PROTOCOL:-http} mirror_protocol=${mirror_protocol:-http}
DEBI_MIRROR=${DEBI_MIRROR:-deb.debian.org} mirror_host=${mirror_host:-deb.debian.org}
DEBI_DIRECTORY=${DEBI_DIRECTORY:-/debian} mirror_directory=${mirror_directory:-/debian}
$save_preseed << EOF $save_preseed << EOF
# Mirror settings # Mirror settings
d-i mirror/country string manual d-i mirror/country string manual
d-i mirror/protocol string $DEBI_PROTOCOL d-i mirror/mirror_protocol string $mirror_protocol
d-i mirror/$DEBI_PROTOCOL/hostname string $DEBI_MIRROR d-i mirror/$mirror_protocol/hostname string $mirror_host
d-i mirror/$DEBI_PROTOCOL/directory string $DEBI_DIRECTORY d-i mirror/$mirror_protocol/directory string $mirror_directory
d-i mirror/$DEBI_PROTOCOL/proxy string d-i mirror/$mirror_protocol/proxy string
d-i mirror/suite string $DEBI_SUITE d-i mirror/suite string $suite
d-i mirror/udeb/suite string $DEBI_SUITE d-i mirror/udeb/suite string $suite
EOF EOF
if [ "$DEBI_SKIP_USER" != true ]; then if [ "$skip_account_setup" != true ]; then
DEBI_USERNAME=${DEBI_USERNAME:-debian} username=${username:-debian}
if command_exists mkpasswd; then if command_exists mkpasswd; then
if [ -z "$DEBI_PASSWORD" ]; then if [ -z "$password" ]; then
DEBI_PASSWORD="$(mkpasswd -m sha512crypt)" password="$(mkpasswd -m sha512crypt)"
else else
DEBI_PASSWORD="$(mkpasswd -m sha512crypt "$DEBI_PASSWORD")" password="$(mkpasswd -m sha512crypt "$password")"
fi fi
elif command_exists busybox && busybox mkpasswd --help >/dev/null 2>&1; then elif command_exists busybox && busybox mkpasswd --help >/dev/null 2>&1; then
if [ -z "$DEBI_PASSWORD" ]; then if [ -z "$password" ]; then
DEBI_PASSWORD="$(busybox mkpasswd -m sha512)" password="$(busybox mkpasswd -m sha512)"
else else
DEBI_PASSWORD="$(busybox mkpasswd -m sha512 "$DEBI_PASSWORD")" password="$(busybox mkpasswd -m sha512 "$password")"
fi fi
elif command_exists python3; then elif command_exists python3; then
if [ -z "$DEBI_PASSWORD" ]; then if [ -z "$password" ]; then
DEBI_PASSWORD="$(python3 -c 'import crypt, getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))')" password="$(python3 -c 'import crypt, getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))')"
else else
DEBI_PASSWORD="$(python3 -c "import crypt; print(crypt.crypt(\"$DEBI_PASSWORD\", crypt.mksalt(crypt.METHOD_SHA512)))")" password="$(python3 -c "import crypt; print(crypt.crypt(\"$password\", crypt.mksalt(crypt.METHOD_SHA512)))")"
fi fi
else else
DEBI_CLEARTEXT=true cleartext_password=true
if [ -z "$DEBI_PASSWORD" ]; then if [ -z "$password" ]; then
printf 'Password: ' printf 'Password: '
read_secret DEBI_PASSWORD read -rs password
fi fi
fi fi
@ -299,53 +327,54 @@ if [ "$DEBI_SKIP_USER" != true ]; then
EOF EOF
if [ "$DEBI_USERNAME" = root ]; then if [ "$username" = root ]; then
_late_command "sed -ri 's/^#?PermitRootLogin .+/PermitRootLogin yes/' /etc/ssh/sshd_config"
$save_preseed << EOF $save_preseed << EOF
d-i passwd/root-login boolean true d-i passwd/root-login boolean true
d-i passwd/make-user boolean false d-i passwd/make-user boolean false
EOF EOF
if [ "$DEBI_CLEARTEXT" = true ]; then if [ "$cleartext_password" = true ]; then
$save_preseed << EOF $save_preseed << EOF
d-i passwd/root-password password $DEBI_PASSWORD d-i passwd/root-password password $password
d-i passwd/root-password-again password $DEBI_PASSWORD d-i passwd/root-password-again password $password
EOF EOF
else else
echo "d-i passwd/root-password-crypted password $DEBI_PASSWORD" | $save_preseed echo "d-i passwd/root-password-crypted password $password" | $save_preseed
fi fi
else else
$save_preseed << EOF $save_preseed << EOF
d-i passwd/root-login boolean false d-i passwd/root-login boolean false
d-i passwd/make-user boolean true d-i passwd/make-user boolean true
d-i passwd/user-fullname string d-i passwd/user-fullname string
d-i passwd/username string $DEBI_USERNAME d-i passwd/username string $username
EOF EOF
if [ "$DEBI_CLEARTEXT" = true ]; then if [ "$cleartext_password" = true ]; then
$save_preseed << EOF $save_preseed << EOF
d-i passwd/user-password password $DEBI_PASSWORD d-i passwd/user-password password $password
d-i passwd/user-password-again password $DEBI_PASSWORD d-i passwd/user-password-again password $password
EOF EOF
else else
echo "d-i passwd/user-password-crypted password $DEBI_PASSWORD" | $save_preseed echo "d-i passwd/user-password-crypted password $password" | $save_preseed
fi fi
fi fi
fi fi
DEBI_TIMEZONE=${DEBI_TIMEZONE:-UTC} timezone=${timezone:-UTC}
DEBI_NTP=${DEBI_NTP:-0.debian.pool.ntp.org} ntp=${ntp:-0.debian.pool.ntp.org}
$save_preseed << EOF $save_preseed << EOF
# Clock and time zone setup # Clock and time zone setup
d-i clock-setup/utc boolean true d-i clock-setup/utc boolean true
d-i time/zone string $DEBI_TIMEZONE d-i time/zone string $timezone
d-i clock-setup/ntp boolean true d-i clock-setup/ntp boolean true
d-i clock-setup/ntp-server string $DEBI_NTP d-i clock-setup/ntp-server string $ntp
EOF EOF
if [ "$DEBI_SKIP_PART" != true ]; then if [ "$skip_partitioning" != true ]; then
DEBI_FS=${DEBI_FS:-ext4} filesystem=${filesystem:-ext4}
DEBI_PART=${DEBI_PART:-regular} partitioning_method=${partitioning_method:-regular}
$save_preseed << EOF $save_preseed << EOF
@ -353,21 +382,21 @@ if [ "$DEBI_SKIP_PART" != true ]; then
EOF EOF
if [ -n "$DEBI_DISK" ]; then if [ -n "$disk" ]; then
echo "d-i partman-auto/disk string $DEBI_DISK" | $save_preseed echo "d-i partman-auto/disk string $disk" | $save_preseed
fi fi
$save_preseed << EOF $save_preseed << EOF
d-i partman-auto/method string $DEBI_PART d-i partman-auto/method string $partitioning_method
d-i partman-lvm/device_remove_lvm boolean true d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true d-i partman-lvm/confirm_nooverwrite boolean true
EOF EOF
if [ "$DEBI_PART" = "regular" ]; then if [ "$partitioning_method" = "regular" ]; then
$save_preseed << EOF $save_preseed << EOF
d-i partman/default_filesystem string $DEBI_FS d-i partman/default_filesystem string $filesystem
d-i partman-auto/expert_recipe string naive :: 0 1 -1 \$default_filesystem \$primary{ } \$bootable{ } method{ format } format{ } use_filesystem{ } \$default_filesystem{ } mountpoint{ / } . d-i partman-auto/expert_recipe string naive :: 0 1 -1 \$default_filesystem \$primary{ } \$bootable{ } method{ format } format{ } use_filesystem{ } \$default_filesystem{ } mountpoint{ / } .
d-i partman-auto/choose_recipe select naive d-i partman-auto/choose_recipe select naive
d-i partman-basicfilesystems/no_swap boolean false d-i partman-basicfilesystems/no_swap boolean false
@ -390,15 +419,15 @@ $save_preseed << EOF
d-i base-installer/install-recommends boolean false d-i base-installer/install-recommends boolean false
EOF EOF
if [ -n "$DEBI_KERNEL" ]; then if [ -n "$kernel" ]; then
echo "d-i base-installer/kernel/image string $DEBI_KERNEL" | $save_preseed echo "d-i base-installer/kernel/image string $kernel" | $save_preseed
fi fi
if [ -z "$DEBI_SECURITY" ]; then if [ -z "$security_repository" ]; then
DEBI_SECURITY=http://security.debian.org/debian-security security_repository=http://security.debian.org/debian-security
else else
if [ "$DEBI_SECURITY" = true ]; then if [ "$security_repository" = true ]; then
DEBI_SECURITY=$DEBI_PROTOCOL://$DEBI_MIRROR${DEBI_DIRECTORY%/*}/debian-security security_repository=$mirror_protocol://$mirror_host${mirror_directory%/*}/debian-security
fi fi
fi fi
@ -407,11 +436,11 @@ $save_preseed << EOF
# Apt setup # Apt setup
d-i apt-setup/services-select multiselect updates, backports d-i apt-setup/services-select multiselect updates, backports
d-i apt-setup/local0/repository string $DEBI_SECURITY $DEBI_SUITE/updates main d-i apt-setup/local0/repository string $security_repository $suite/updates main
d-i apt-setup/local0/source boolean true d-i apt-setup/local0/source boolean true
EOF EOF
DEBI_UPGRADE=${DEBI_UPGRADE:-full-upgrade} upgrade=${upgrade:-full-upgrade}
$save_preseed << EOF $save_preseed << EOF
@ -420,12 +449,12 @@ $save_preseed << EOF
tasksel tasksel/first multiselect ssh-server tasksel tasksel/first multiselect ssh-server
EOF EOF
if [ -n "$DEBI_INSTALL" ]; then if [ -n "$install" ]; then
echo "d-i pkgsel/include string $DEBI_INSTALL" | $save_preseed echo "d-i pkgsel/include string $install" | $save_preseed
fi fi
$save_preseed << EOF $save_preseed << EOF
d-i pkgsel/upgrade select $DEBI_UPGRADE d-i pkgsel/upgrade select $upgrade
popularity-contest popularity-contest/participate boolean false popularity-contest popularity-contest/participate boolean false
# Boot loader installation # Boot loader installation
@ -434,15 +463,8 @@ d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string default d-i grub-installer/bootdev string default
EOF EOF
if [ -n "$DEBI_KERNEL_PARAMS" ]; then if [ -n "$kernel_params" ]; then
echo "d-i debian-installer/add-kernel-opts string$DEBI_KERNEL_PARAMS" | $save_preseed echo "d-i debian-installer/add-kernel-opts string$kernel_params" | $save_preseed
fi
if [ "$DEBI_USERNAME" = root ]; then
$save_preseed << 'EOF'
d-i preseed/late_command string \
in-target sed -ri 's/^#?PermitRootLogin .+/PermitRootLogin yes/' /etc/ssh/sshd_config
EOF
fi fi
$save_preseed << EOF $save_preseed << EOF
@ -452,30 +474,34 @@ $save_preseed << EOF
d-i finish-install/reboot_in_progress note d-i finish-install/reboot_in_progress note
EOF EOF
if [ "$DEBI_POWEROFF" = true ]; then if [ -n "$late_command" ]; then
echo "d-i preseed/late_command string in-target sh -c '$late_command'" | $save_preseed
fi
if [ "$power_off" = true ]; then
echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
fi fi
save_grubcfg="cat" save_grub_cfg="cat"
if [ "$DEBI_DRY_RUN" != true ]; then if [ "$dry_run" != true ]; then
if [ -z "$DEBI_ARCH" ]; then if [ -z "$architecture" ]; then
if command_exists dpkg; then if command_exists dpkg; then
DEBI_ARCH="$(dpkg --print-architecture)" architecture="$(dpkg --print-architecture)"
else else
DEBI_ARCH=amd64 architecture=amd64
fi fi
fi fi
DEBI_BASE_URL="$DEBI_PROTOCOL://$DEBI_MIRROR$DEBI_DIRECTORY/dists/$DEBI_SUITE/main/installer-$DEBI_ARCH/current/images/netboot/debian-installer/$DEBI_ARCH" base_url="$mirror_protocol://$mirror_host$mirror_directory/dists/$suite/main/installer-$architecture/current/images/netboot/debian-installer/$architecture"
if command_exists wget; then if command_exists wget; then
wget "$DEBI_BASE_URL/linux" "$DEBI_BASE_URL/initrd.gz" wget "$base_url/linux" "$base_url/initrd.gz"
elif command_exists curl; then elif command_exists curl; then
curl -O "$DEBI_BASE_URL/linux" -O "$DEBI_BASE_URL/initrd.gz" curl -O "$base_url/linux" -O "$base_url/initrd.gz"
elif command_exists busybox; then elif command_exists busybox; then
busybox wget "$DEBI_BASE_URL/linux" "$DEBI_BASE_URL/initrd.gz" busybox wget "$base_url/linux" "$base_url/initrd.gz"
else else
echo_stderr 'Error: wget/curl/busybox not found.' _err 'wget/curl/busybox is required to download files'
exit 1 exit 1
fi fi
@ -484,33 +510,33 @@ if [ "$DEBI_DRY_RUN" != true ]; then
gzip initrd gzip initrd
if command_exists update-grub; then if command_exists update-grub; then
DEBI_GRUBCFG=/boot/grub/grub.cfg grub_cfg=/boot/grub/grub.cfg
update-grub update-grub
elif command_exists grub2-mkconfig; then elif command_exists grub2-mkconfig; then
DEBI_GRUBCFG=/boot/grub2/grub.cfg grub_cfg=/boot/grub2/grub.cfg
grub2-mkconfig -o "$DEBI_GRUBCFG" grub2-mkconfig -o "$grub_cfg"
else else
echo_stderr 'Error: Command update-grub/grub2-mkconfig not found.' _err 'update-grub/grub2-mkconfig command not found'
exit 1 exit 1
fi fi
save_grubcfg="tee -a $DEBI_GRUBCFG" save_grub_cfg="tee -a $grub_cfg"
fi fi
if [ "$DEBI_BOOT_PARTITION" = true ]; then if [ "$boot_partition" = true ]; then
DEBI_BOOT_DIR=/ boot_directory=/
else else
DEBI_BOOT_DIR=/boot/ boot_directory=/boot/
fi fi
DEBI_NEW_DIR="$DEBI_BOOT_DIR$DEBI_NEW" installer_directory="$boot_directory$installer"
$save_grubcfg << EOF $save_grub_cfg << EOF
menuentry 'Debian Installer' --id debi { menuentry 'Debian Installer' --id debi {
insmod part_msdos insmod part_msdos
insmod part_gpt insmod part_gpt
insmod ext2 insmod ext2
linux $DEBI_NEW_DIR/linux$DEBI_KERNEL_PARAMS linux $installer_directory/linux$kernel_params
initrd $DEBI_NEW_DIR/initrd.gz initrd $installer_directory/initrd.gz
} }
EOF EOF

Loading…
Cancel
Save