mirror of
https://github.com/bohanyang/debi.git
synced 2026-09-26 22:16:11 +00:00
Refactor
This commit is contained in:
@@ -18,33 +18,38 @@ This script is used to re-install VPS to **Debian 9 (stretch) or 10 (buster)** w
|
|||||||
|
|
||||||
## Available Options
|
## Available Options
|
||||||
|
|
||||||
- `--preset` [`china`, `cloud`]
|
- `--preset` (`china`/`cloud`)
|
||||||
- `--ip`
|
- `--ip`
|
||||||
- `--netmask`
|
- `--netmask`
|
||||||
- `--gateway`
|
- `--gateway`
|
||||||
- `--dns "8.8.8.8 8.8.4.4"`
|
- `--dns '8.8.8.8 8.8.4.4'`
|
||||||
- `--hostname debian`
|
- `--hostname debian`
|
||||||
- `--eth` Disable Consistent Network Device Naming
|
|
||||||
- `--installer-password`
|
- `--installer-password`
|
||||||
- `--authorized-keys-url`
|
- `--authorized-keys-url`
|
||||||
- `--mirror-protocol http` [`http`, `https`, `ftp`]
|
- `--suite buster`
|
||||||
|
- `--mirror-protocol http` (`http`/`https`/`ftp`)
|
||||||
- `--mirror-host deb.debian.org`
|
- `--mirror-host deb.debian.org`
|
||||||
- `--mirror-directory /debian`
|
- `--mirror-directory /debian`
|
||||||
- `--suite buster`
|
- `--security-repository http://security.debian.org/debian-security`
|
||||||
- `--skip-account-setup`
|
- `--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-partitioning`
|
- `--skip-partitioning`
|
||||||
|
- `--partitioning-method regular`
|
||||||
- `--disk`
|
- `--disk`
|
||||||
- `--partitioning-method`
|
- `--gpt`
|
||||||
|
- `--efi`
|
||||||
- `--filesystem ext4`
|
- `--filesystem ext4`
|
||||||
|
- `--kernel` Choose an package for the kernel image
|
||||||
|
- `--cloud-kernel` Choose `linux-image-cloud-amd64` as the kernel image
|
||||||
- `--no-install-recommends`
|
- `--no-install-recommends`
|
||||||
- `--kernel` Specify another package for kernel image, e.g. `linux-image-cloud-amd64`
|
|
||||||
- `--security-repository http://security.debian.org/debian-security`
|
|
||||||
- `--install`
|
- `--install`
|
||||||
- `--upgrade full-upgrade` [`none`, `safe-upgrade`, `full-upgrade`]
|
- `--safe-upgrade`
|
||||||
|
- `--full-upgrade`
|
||||||
|
- `--eth` Disable *Consistent Network Device Naming* to get `eth0`, `eth1`, etc. back
|
||||||
|
- `--bbr`
|
||||||
- `--power-off`
|
- `--power-off`
|
||||||
- `--architecture`
|
- `--architecture`
|
||||||
- `--boot-partition`
|
- `--boot-partition`
|
||||||
@@ -54,7 +59,7 @@ This script is used to re-install VPS to **Debian 9 (stretch) or 10 (buster)** w
|
|||||||
|
|
||||||
### `china`
|
### `china`
|
||||||
|
|
||||||
- `--dns "223.5.5.5 223.6.6.6"`
|
- `--dns '223.5.5.5 223.6.6.6'`
|
||||||
- `--protocol https`
|
- `--protocol https`
|
||||||
- `--mirror mirrors.aliyun.com`
|
- `--mirror mirrors.aliyun.com`
|
||||||
- `--security true`
|
- `--security true`
|
||||||
@@ -62,6 +67,8 @@ This script is used to re-install VPS to **Debian 9 (stretch) or 10 (buster)** w
|
|||||||
|
|
||||||
### `cloud`
|
### `cloud`
|
||||||
|
|
||||||
|
- `--dns '1.1.1.1 1.0.0.1'`
|
||||||
- `--protocol https`
|
- `--protocol https`
|
||||||
- `--mirror deb.debian.org`
|
- `--mirror deb.debian.org`
|
||||||
- `--security true`
|
- `--security true`
|
||||||
|
- `--ntp 0.debian.pool.ntp.org`
|
||||||
|
|||||||
+139
-184
@@ -1,62 +1,82 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
_err() {
|
_err() {
|
||||||
printf 'Error: %s.\n' "$1" 1>&2
|
printf 'Error: %s.\n' "$1" 1>&2
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
command_exists() {
|
_command_exists() {
|
||||||
command -v "$1" >/dev/null 2>&1
|
command -v "$1" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
late_command=
|
||||||
_late_command() {
|
_late_command() {
|
||||||
[ -z "$late_command" ] && late_command='true'
|
[ -z "$late_command" ] && late_command='true'
|
||||||
late_command="$late_command; $1"
|
late_command="$late_command; $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
late_command=
|
_prompt_password() {
|
||||||
preset=
|
[ -z "$password" ] && read -rs -p 'Password: ' password
|
||||||
|
}
|
||||||
|
|
||||||
ip=
|
ip=
|
||||||
netmask=
|
netmask=
|
||||||
gateway=
|
gateway=
|
||||||
dns=
|
dns='8.8.8.8 8.8.4.4'
|
||||||
hostname=
|
hostname=
|
||||||
kernel_params=
|
installer_ssh=false
|
||||||
installer_ssh=
|
|
||||||
installer_password=
|
installer_password=
|
||||||
authorized_keys_url=
|
authorized_keys_url=
|
||||||
mirror_protocol=
|
suite=buster
|
||||||
mirror_host=
|
mirror_protocol=http
|
||||||
mirror_directory=
|
mirror_host=deb.debian.org
|
||||||
suite=
|
mirror_directory=/debian
|
||||||
skip_account_setup=
|
security_repository=http://security.debian.org/debian-security
|
||||||
username=
|
skip_account_setup=false
|
||||||
|
username=debian
|
||||||
password=
|
password=
|
||||||
timezone=
|
cleartext_password=false
|
||||||
ntp=
|
timezone=UTC
|
||||||
skip_partitioning=
|
ntp=0.debian.pool.ntp.org
|
||||||
disk=
|
skip_partitioning=false
|
||||||
partitioning_method=regular
|
partitioning_method=regular
|
||||||
|
disk=
|
||||||
|
gpt=false
|
||||||
|
efi=false
|
||||||
filesystem=ext4
|
filesystem=ext4
|
||||||
kernel=
|
kernel=
|
||||||
security_repository=
|
install_recommends=true
|
||||||
install=
|
install=
|
||||||
upgrade=
|
upgrade=
|
||||||
power_off=
|
kernel_params=
|
||||||
|
bbr=false
|
||||||
|
power_off=false
|
||||||
architecture=
|
architecture=
|
||||||
boot_partition=
|
boot_directory=/boot/
|
||||||
dry_run=
|
dry_run=false
|
||||||
bbr=
|
|
||||||
cleartext_password=
|
|
||||||
gpt=
|
|
||||||
install_recommends=true
|
|
||||||
efi=false
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--preset)
|
--preset)
|
||||||
preset=$2
|
case "$2" in
|
||||||
|
china)
|
||||||
|
dns='223.5.5.5 223.6.6.6'
|
||||||
|
mirror_protocol=https
|
||||||
|
mirror_host=mirrors.aliyun.com
|
||||||
|
ntp=ntp.aliyun.com
|
||||||
|
security_repository=true
|
||||||
|
;;
|
||||||
|
cloud)
|
||||||
|
dns='1.1.1.1 1.0.0.1'
|
||||||
|
mirror_protocol=https
|
||||||
|
mirror_host=deb.debian.org
|
||||||
|
security_repository=true
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
_err "No such preset $2"
|
||||||
|
esac
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--ip)
|
--ip)
|
||||||
@@ -79,9 +99,6 @@ while [ $# -gt 0 ]; do
|
|||||||
hostname=$2
|
hostname=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--eth)
|
|
||||||
kernel_params=' net.ifnames=0 biosdevname=0'
|
|
||||||
;;
|
|
||||||
--installer-password)
|
--installer-password)
|
||||||
installer_ssh=true
|
installer_ssh=true
|
||||||
installer_password=$2
|
installer_password=$2
|
||||||
@@ -92,6 +109,10 @@ while [ $# -gt 0 ]; do
|
|||||||
authorized_keys_url=$2
|
authorized_keys_url=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--suite)
|
||||||
|
suite=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--mirror-protocol)
|
--mirror-protocol)
|
||||||
mirror_protocol=$2
|
mirror_protocol=$2
|
||||||
shift
|
shift
|
||||||
@@ -104,8 +125,8 @@ while [ $# -gt 0 ]; do
|
|||||||
mirror_directory=${2%/}
|
mirror_directory=${2%/}
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--suite)
|
--security-repository)
|
||||||
suite=$2
|
security_repository=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--skip-account-setup)
|
--skip-account-setup)
|
||||||
@@ -130,13 +151,19 @@ while [ $# -gt 0 ]; do
|
|||||||
--skip-partitioning)
|
--skip-partitioning)
|
||||||
skip_partitioning=true
|
skip_partitioning=true
|
||||||
;;
|
;;
|
||||||
|
--partitioning-method)
|
||||||
|
partitioning_method=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--disk)
|
--disk)
|
||||||
disk=$2
|
disk=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--partitioning-method)
|
--gpt)
|
||||||
partitioning_method=$2
|
gpt=true
|
||||||
shift
|
;;
|
||||||
|
--efi)
|
||||||
|
efi=true
|
||||||
;;
|
;;
|
||||||
--filesystem)
|
--filesystem)
|
||||||
filesystem=$2
|
filesystem=$2
|
||||||
@@ -146,18 +173,30 @@ while [ $# -gt 0 ]; do
|
|||||||
kernel=$2
|
kernel=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--security-repository)
|
--cloud-kernel)
|
||||||
security_repository=$2
|
kernel=linux-image-cloud-amd64
|
||||||
shift
|
;;
|
||||||
|
--no-install-recommends)
|
||||||
|
install_recommends=false
|
||||||
;;
|
;;
|
||||||
--install)
|
--install)
|
||||||
install=$2
|
install=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--upgrade)
|
--safe-upgrade)
|
||||||
upgrade=$2
|
upgrade=safe-upgrade
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--full-upgrade)
|
||||||
|
upgrade=full-upgrade
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--eth)
|
||||||
|
kernel_params=' net.ifnames=0 biosdevname=0'
|
||||||
|
;;
|
||||||
|
--bbr)
|
||||||
|
bbr=true
|
||||||
|
;;
|
||||||
--power-off)
|
--power-off)
|
||||||
power_off=true
|
power_off=true
|
||||||
;;
|
;;
|
||||||
@@ -166,62 +205,25 @@ while [ $# -gt 0 ]; do
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--boot-partition)
|
--boot-partition)
|
||||||
boot_partition=true
|
boot_directory=/
|
||||||
;;
|
;;
|
||||||
--dry-run)
|
--dry-run)
|
||||||
dry_run=true
|
dry_run=true
|
||||||
;;
|
;;
|
||||||
--bbr)
|
|
||||||
bbr=true
|
|
||||||
;;
|
|
||||||
--gpt)
|
|
||||||
gpt=true
|
|
||||||
;;
|
|
||||||
--no-install-recommends)
|
|
||||||
install_recommends=false
|
|
||||||
;;
|
|
||||||
--efi)
|
|
||||||
efi=true
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
_err "Illegal option $1"
|
_err "Illegal option $1"
|
||||||
exit 1
|
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$preset" ]; then
|
|
||||||
case "$preset" in
|
|
||||||
china)
|
|
||||||
dns=${dns:-223.5.5.5 223.6.6.6}
|
|
||||||
mirror_protocol=${mirror_protocol:-https}
|
|
||||||
mirror_host=${mirror_host:-mirrors.aliyun.com}
|
|
||||||
ntp=${ntp:-ntp.aliyun.com}
|
|
||||||
security_repository=${security_repository:-true}
|
|
||||||
;;
|
|
||||||
cloud)
|
|
||||||
mirror_protocol=${mirror_protocol:-https}
|
|
||||||
mirror_host=${mirror_host:-deb.debian.org}
|
|
||||||
security_repository=${security_repository:-true}
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
_err "No such preset $preset"
|
|
||||||
exit 1
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
suite=${suite:-buster}
|
|
||||||
installer="debian-$suite"
|
installer="debian-$suite"
|
||||||
installer_directory="/boot/$installer"
|
installer_directory="/boot/$installer"
|
||||||
|
|
||||||
save_preseed="cat"
|
save_preseed='cat'
|
||||||
if [ "$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
|
[ "$user" != root ] && _err 'root privilege is required'
|
||||||
_err 'root privilege is required'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -rf "$installer_directory"
|
rm -rf "$installer_directory"
|
||||||
mkdir -p "$installer_directory"
|
mkdir -p "$installer_directory"
|
||||||
@@ -229,7 +231,7 @@ if [ "$dry_run" != true ]; then
|
|||||||
save_preseed='tee -a preseed.cfg'
|
save_preseed='tee -a preseed.cfg'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
# Localization
|
# Localization
|
||||||
|
|
||||||
d-i debian-installer/locale string en_US.UTF-8
|
d-i debian-installer/locale string en_US.UTF-8
|
||||||
@@ -240,24 +242,16 @@ d-i keyboard-configuration/xkb-keymap select us
|
|||||||
d-i netcfg/choose_interface select auto
|
d-i netcfg/choose_interface select auto
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
dns=${dns:-8.8.8.8 8.8.4.4}
|
|
||||||
|
|
||||||
if [ -n "$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 $ip" | $save_preseed
|
echo "d-i netcfg/get_ipaddress string $ip" | $save_preseed
|
||||||
if [ -n "$netmask" ]; then
|
[ -n "$netmask" ] && echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
|
||||||
echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
|
[ -n "$gateway" ] && echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
|
||||||
fi
|
[ -n "$dns" ] && echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
|
||||||
if [ -n "$gateway" ]; then
|
|
||||||
echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
|
|
||||||
fi
|
|
||||||
if [ -n "$dns" ]; then
|
|
||||||
echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
|
|
||||||
fi
|
|
||||||
echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
|
echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
d-i netcfg/get_hostname string debian
|
d-i netcfg/get_hostname string debian
|
||||||
d-i netcfg/get_domain string
|
d-i netcfg/get_domain string
|
||||||
EOF
|
EOF
|
||||||
@@ -269,13 +263,14 @@ fi
|
|||||||
echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed
|
echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed
|
||||||
|
|
||||||
if [ "$installer_ssh" = true ]; then
|
if [ "$installer_ssh" = true ]; then
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
|
|
||||||
# Network console
|
# Network console
|
||||||
|
|
||||||
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 "$authorized_keys_url" ]; then
|
if [ -n "$authorized_keys_url" ]; then
|
||||||
_late_command 'sed -ri "s/^#?PasswordAuthentication .+/PasswordAuthentication no/" /etc/ssh/sshd_config'
|
_late_command 'sed -ri "s/^#?PasswordAuthentication .+/PasswordAuthentication no/" /etc/ssh/sshd_config'
|
||||||
$save_preseed << EOF
|
$save_preseed << EOF
|
||||||
@@ -289,13 +284,10 @@ d-i network-console/password password $installer_password
|
|||||||
d-i network-console/password-again 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
|
||||||
|
|
||||||
mirror_protocol=${mirror_protocol:-http}
|
|
||||||
mirror_host=${mirror_host:-deb.debian.org}
|
|
||||||
mirror_directory=${mirror_directory:-/debian}
|
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << EOF
|
||||||
|
|
||||||
# Mirror settings
|
# Mirror settings
|
||||||
@@ -310,20 +302,16 @@ d-i mirror/udeb/suite string $suite
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ "$skip_account_setup" != true ]; then
|
if [ "$skip_account_setup" != true ]; then
|
||||||
username=${username:-debian}
|
if _command_exists mkpasswd; then
|
||||||
|
|
||||||
if command_exists mkpasswd; then
|
|
||||||
if [ -z "$password" ]; then
|
if [ -z "$password" ]; then
|
||||||
password="$(mkpasswd -m sha-512)"
|
password="$(mkpasswd -m sha-512)"
|
||||||
else
|
else
|
||||||
password="$(mkpasswd -m sha-512 "$password")"
|
password="$(mkpasswd -m sha-512 "$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 "$password" ]; then
|
_prompt_password
|
||||||
read -rs -p 'Password: ' password
|
|
||||||
fi
|
|
||||||
password="$(busybox mkpasswd -m sha512 "$password")"
|
password="$(busybox mkpasswd -m sha512 "$password")"
|
||||||
elif command_exists python3; then
|
elif _command_exists python3; then
|
||||||
if [ -z "$password" ]; then
|
if [ -z "$password" ]; then
|
||||||
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
|
||||||
@@ -331,12 +319,10 @@ if [ "$skip_account_setup" != true ]; then
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
cleartext_password=true
|
cleartext_password=true
|
||||||
if [ -z "$password" ]; then
|
_prompt_password
|
||||||
read -rs -p 'Password: ' password
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
|
|
||||||
# Account setup
|
# Account setup
|
||||||
|
|
||||||
@@ -348,10 +334,12 @@ EOF
|
|||||||
else
|
else
|
||||||
_late_command "mkdir -pm 700 /root/.ssh && busybox wget -qO /root/.ssh/authorized_keys \"$authorized_keys_url\""
|
_late_command "mkdir -pm 700 /root/.ssh && busybox wget -qO /root/.ssh/authorized_keys \"$authorized_keys_url\""
|
||||||
fi
|
fi
|
||||||
$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 [ "$cleartext_password" = true ]; then
|
if [ "$cleartext_password" = true ]; then
|
||||||
$save_preseed << EOF
|
$save_preseed << EOF
|
||||||
d-i passwd/root-password password $password
|
d-i passwd/root-password password $password
|
||||||
@@ -362,15 +350,18 @@ EOF
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
_late_command 'sed -ri "s/^#?PermitRootLogin .+/PermitRootLogin no/" /etc/ssh/sshd_config'
|
_late_command 'sed -ri "s/^#?PermitRootLogin .+/PermitRootLogin no/" /etc/ssh/sshd_config'
|
||||||
|
|
||||||
if [ -n "$authorized_keys_url" ]; then
|
if [ -n "$authorized_keys_url" ]; then
|
||||||
_late_command "sudo -u $username mkdir -pm 700 /home/$username/.ssh && sudo -u $username busybox wget -qO /home/$username/.ssh/authorized_keys \"$authorized_keys_url\""
|
_late_command "sudo -u $username mkdir -pm 700 /home/$username/.ssh && sudo -u $username busybox wget -qO /home/$username/.ssh/authorized_keys \"$authorized_keys_url\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$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 $username
|
d-i passwd/username string $username
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ "$cleartext_password" = true ]; then
|
if [ "$cleartext_password" = true ]; then
|
||||||
$save_preseed << EOF
|
$save_preseed << EOF
|
||||||
d-i passwd/user-password password $password
|
d-i passwd/user-password password $password
|
||||||
@@ -382,9 +373,6 @@ EOF
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
timezone=${timezone:-UTC}
|
|
||||||
ntp=${ntp:-0.debian.pool.ntp.org}
|
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << EOF
|
||||||
|
|
||||||
# Clock and time zone setup
|
# Clock and time zone setup
|
||||||
@@ -401,6 +389,7 @@ if [ "$skip_partitioning" != true ]; then
|
|||||||
# Partitioning
|
# Partitioning
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -n "$disk" ]; then
|
if [ -n "$disk" ]; then
|
||||||
echo "d-i partman-auto/disk string $disk" | $save_preseed
|
echo "d-i partman-auto/disk string $disk" | $save_preseed
|
||||||
fi
|
fi
|
||||||
@@ -408,21 +397,12 @@ EOF
|
|||||||
echo "d-i partman-auto/method string $partitioning_method" | $save_preseed
|
echo "d-i partman-auto/method string $partitioning_method" | $save_preseed
|
||||||
|
|
||||||
if [ "$partitioning_method" = regular ]; then
|
if [ "$partitioning_method" = regular ]; then
|
||||||
if [ "$gpt" = true ]; then
|
[ "$gpt" = true ] && $save_preseed << 'EOF'
|
||||||
$save_preseed << 'EOF'
|
|
||||||
d-i partman-partitioning/default_label string gpt
|
d-i partman-partitioning/default_label string gpt
|
||||||
EOF
|
EOF
|
||||||
fi
|
|
||||||
echo "d-i partman/default_filesystem string $filesystem" | $save_preseed
|
echo "d-i partman/default_filesystem string $filesystem" | $save_preseed
|
||||||
$save_preseed << 'EOF'
|
|
||||||
d-i partman-auto/expert_recipe string \
|
|
||||||
naive :: \
|
|
||||||
1 1 1 free \
|
|
||||||
$iflabel{ gpt } \
|
|
||||||
$reusemethod{ } \
|
|
||||||
method{ biosgrub } \
|
|
||||||
. \
|
|
||||||
EOF
|
|
||||||
if [ "$efi" = true ]; then
|
if [ "$efi" = true ]; then
|
||||||
$save_preseed << 'EOF'
|
$save_preseed << 'EOF'
|
||||||
538 538 1075 free \
|
538 538 1075 free \
|
||||||
@@ -431,8 +411,19 @@ EOF
|
|||||||
method{ efi } \
|
method{ efi } \
|
||||||
format{ } \
|
format{ } \
|
||||||
. \
|
. \
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
$save_preseed << 'EOF'
|
||||||
|
d-i partman-auto/expert_recipe string \
|
||||||
|
naive :: \
|
||||||
|
1 1 1 free \
|
||||||
|
$iflabel{ gpt } \
|
||||||
|
$reusemethod{ } \
|
||||||
|
method{ biosgrub } \
|
||||||
|
. \
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$save_preseed << 'EOF'
|
$save_preseed << 'EOF'
|
||||||
2149 2150 -1 $default_filesystem \
|
2149 2150 -1 $default_filesystem \
|
||||||
method{ format } \
|
method{ format } \
|
||||||
@@ -444,34 +435,25 @@ EOF
|
|||||||
EOF
|
EOF
|
||||||
echo "d-i partman-auto/choose_recipe select naive" | $save_preseed
|
echo "d-i partman-auto/choose_recipe select naive" | $save_preseed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$save_preseed << 'EOF'
|
$save_preseed << 'EOF'
|
||||||
d-i partman-basicfilesystems/no_swap boolean false
|
d-i partman-basicfilesystems/no_swap boolean false
|
||||||
d-i partman/choose_partition select finish
|
d-i partman/choose_partition select finish
|
||||||
d-i partman/confirm boolean true
|
d-i partman/confirm boolean true
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
|
|
||||||
# Base system installation
|
# Base system installation
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ "$install_recommends" = false ]; then
|
[ "$install_recommends" = false ] && echo "d-i base-installer/install-recommends boolean $install_recommends" | $save_preseed
|
||||||
echo "d-i base-installer/install-recommends boolean $install_recommends" | $save_preseed
|
[ -n "$kernel" ] && echo "d-i base-installer/kernel/image string $kernel" | $save_preseed
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$kernel" ]; then
|
[ "$security_repository" = true ] && security_repository=$mirror_protocol://$mirror_host${mirror_directory%/*}/debian-security
|
||||||
echo "d-i base-installer/kernel/image string $kernel" | $save_preseed
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$security_repository" ]; then
|
|
||||||
security_repository=http://security.debian.org/debian-security
|
|
||||||
else
|
|
||||||
if [ "$security_repository" = true ]; then
|
|
||||||
security_repository=$mirror_protocol://$mirror_host${mirror_directory%/*}/debian-security
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << EOF
|
||||||
|
|
||||||
@@ -482,99 +464,72 @@ 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
|
||||||
|
|
||||||
upgrade=${upgrade:-full-upgrade}
|
$save_preseed << 'EOF'
|
||||||
|
|
||||||
$save_preseed << EOF
|
|
||||||
|
|
||||||
# Package selection
|
# Package selection
|
||||||
|
|
||||||
tasksel tasksel/first multiselect ssh-server
|
tasksel tasksel/first multiselect ssh-server
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -n "$install" ]; then
|
[ -n "$install" ] && echo "d-i pkgsel/include string $install" | $save_preseed
|
||||||
echo "d-i pkgsel/include string $install" | $save_preseed
|
[ -n "$upgrade" ] && echo "d-i pkgsel/upgrade select $upgrade" | $save_preseed
|
||||||
fi
|
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
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
|
||||||
|
|
||||||
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 "$kernel_params" ]; then
|
[ -n "$kernel_params" ] && echo "d-i debian-installer/add-kernel-opts string$kernel_params" | $save_preseed
|
||||||
echo "d-i debian-installer/add-kernel-opts string$kernel_params" | $save_preseed
|
|
||||||
fi
|
|
||||||
|
|
||||||
$save_preseed << EOF
|
$save_preseed << 'EOF'
|
||||||
|
|
||||||
# Finishing up the installation
|
# Finishing up the installation
|
||||||
|
|
||||||
d-i finish-install/reboot_in_progress note
|
d-i finish-install/reboot_in_progress note
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ "$bbr" = true ]; then
|
[ "$bbr" = true ] && _late_command '{ echo "net.core.default_qdisc=fq"; echo "net.ipv4.tcp_congestion_control=bbr"; } > /etc/sysctl.d/bbr.conf'
|
||||||
_late_command '{ echo "net.core.default_qdisc=fq"; echo "net.ipv4.tcp_congestion_control=bbr"; } > /etc/sysctl.d/bbr.conf'
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$late_command" ]; then
|
[ -n "$late_command" ] && echo "d-i preseed/late_command string in-target sh -c '$late_command'" | $save_preseed
|
||||||
echo "d-i preseed/late_command string in-target sh -c '$late_command'" | $save_preseed
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$power_off" = true ]; then
|
[ "$power_off" = true ] && echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
|
||||||
echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
|
|
||||||
fi
|
|
||||||
|
|
||||||
save_grub_cfg="cat"
|
save_grub_cfg='cat'
|
||||||
if [ "$dry_run" != true ]; then
|
if [ "$dry_run" != true ]; then
|
||||||
if [ -z "$architecture" ]; then
|
[ -z "$architecture" ] && architecture=amd64 && _command_exists dpkg && architecture="$(dpkg --print-architecture)"
|
||||||
if command_exists dpkg; then
|
|
||||||
architecture="$(dpkg --print-architecture)"
|
|
||||||
else
|
|
||||||
architecture=amd64
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
base_url="$mirror_protocol://$mirror_host$mirror_directory/dists/$suite/main/installer-$architecture/current/images/netboot/debian-installer/$architecture"
|
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 "$base_url/linux" "$base_url/initrd.gz"
|
wget "$base_url/linux" "$base_url/initrd.gz"
|
||||||
elif command_exists curl; then
|
elif _command_exists curl; then
|
||||||
curl -O "$base_url/linux" -O "$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 "$base_url/linux" "$base_url/initrd.gz"
|
busybox wget "$base_url/linux" "$base_url/initrd.gz"
|
||||||
else
|
else
|
||||||
_err 'wget/curl/busybox is required to download files'
|
_err 'wget/curl/busybox is required to download files'
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gunzip initrd.gz
|
gunzip initrd.gz
|
||||||
echo preseed.cfg | cpio -H newc -o -A -F initrd
|
echo preseed.cfg | cpio -H newc -o -A -F initrd
|
||||||
gzip initrd
|
gzip initrd
|
||||||
|
|
||||||
if command_exists update-grub; then
|
if _command_exists update-grub; then
|
||||||
grub_cfg=/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
|
||||||
grub_cfg=/boot/grub2/grub.cfg
|
grub_cfg=/boot/grub2/grub.cfg
|
||||||
grub2-mkconfig -o "$grub_cfg"
|
grub2-mkconfig -o "$grub_cfg"
|
||||||
else
|
else
|
||||||
_err 'update-grub/grub2-mkconfig command not found'
|
_err 'update-grub/grub2-mkconfig command not found'
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
save_grub_cfg="tee -a $grub_cfg"
|
save_grub_cfg="tee -a $grub_cfg"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$boot_partition" = true ]; then
|
|
||||||
boot_directory=/
|
|
||||||
else
|
|
||||||
boot_directory=/boot/
|
|
||||||
fi
|
|
||||||
|
|
||||||
installer_directory="$boot_directory$installer"
|
installer_directory="$boot_directory$installer"
|
||||||
|
|
||||||
$save_grub_cfg << EOF
|
$save_grub_cfg << EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user