mirror of
https://github.com/bohanyang/debi.git
synced 2026-09-27 06:26:15 +00:00
Update
This commit is contained in:
+273
-191
@@ -1,18 +1,18 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
# Copyright 2018-present Brent, Yang Bohan
|
# Copyright 2018-present Bohan Yang (Brent)
|
||||||
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
#
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
#
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
@@ -23,27 +23,55 @@ echo_stderr() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
command_exists() {
|
command_exists() {
|
||||||
_PATH="$PATH"
|
|
||||||
PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin"
|
|
||||||
set +e
|
|
||||||
command -v "$@" >/dev/null 2>&1
|
command -v "$@" >/dev/null 2>&1
|
||||||
command_exit_status=$?
|
}
|
||||||
set -e
|
|
||||||
PATH="$_PATH"
|
read_secret()
|
||||||
unset _PATH
|
{
|
||||||
return $command_exit_status
|
stty -echo
|
||||||
|
trap 'stty echo' EXIT
|
||||||
|
read "$@"
|
||||||
|
stty echo
|
||||||
|
trap - EXIT
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--template)
|
--preset)
|
||||||
DEBI_TEMPLATE=$2
|
DEBI_PRESET=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--ip)
|
||||||
|
DEBI_IP=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--netmask)
|
||||||
|
DEBI_NETMASK=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--gateway)
|
||||||
|
DEBI_GATEWAY=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--ns)
|
||||||
|
DEBI_NS=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--hostname)
|
--hostname)
|
||||||
DEBI_HOSTNAME=$2
|
DEBI_HOSTNAME=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--ssh-password)
|
||||||
|
DEBI_SSH=true
|
||||||
|
DEBI_SSH_PASSWORD=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--ssh-keys)
|
||||||
|
DEBI_SSH=true
|
||||||
|
DEBI_SSH_KEYS=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--protocol)
|
--protocol)
|
||||||
DEBI_PROTOCOL=$2
|
DEBI_PROTOCOL=$2
|
||||||
shift
|
shift
|
||||||
@@ -60,6 +88,9 @@ while [ $# -gt 0 ]; do
|
|||||||
DEBI_SUITE=$2
|
DEBI_SUITE=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
--skip-user)
|
||||||
|
DEBI_SKIP_USER=true
|
||||||
|
;;
|
||||||
--username)
|
--username)
|
||||||
DEBI_USERNAME=$2
|
DEBI_USERNAME=$2
|
||||||
shift
|
shift
|
||||||
@@ -72,169 +103,99 @@ while [ $# -gt 0 ]; do
|
|||||||
DEBI_TIMEZONE=$2
|
DEBI_TIMEZONE=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--ntp-server)
|
--ntp)
|
||||||
DEBI_NTP_SERVER=$2
|
DEBI_NTP=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--security-mirror)
|
--skip-part)
|
||||||
DEBI_SECURITY_MIRROR=$2
|
DEBI_SKIP_PART=true
|
||||||
|
;;
|
||||||
|
--disk)
|
||||||
|
DEBI_DISK=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--part)
|
||||||
|
DEBI_PART=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--fs)
|
||||||
|
DEBI_FS=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--security)
|
||||||
|
DEBI_SECURITY=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--install)
|
||||||
|
DEBI_INSTALL=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--upgrade)
|
--upgrade)
|
||||||
DEBI_UPGRADE=$2
|
DEBI_UPGRADE=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--ip)
|
--poweroff)
|
||||||
DEBI_IP=$2
|
DEBI_POWEROFF=true
|
||||||
shift
|
|
||||||
;;
|
;;
|
||||||
--netmask)
|
--arch)
|
||||||
DEBI_NETMASK=$2
|
DEBI_ARCH=$2
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--gateway)
|
|
||||||
DEBI_GATEWAY=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--dns)
|
|
||||||
DEBI_DNS=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--include)
|
|
||||||
DEBI_INCLUDE=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--ssh-password)
|
|
||||||
DEBI_SSH=true
|
|
||||||
DEBI_SSH_PASSWORD=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--ssh-keys)
|
|
||||||
DEBI_SSH=true
|
|
||||||
DEBI_SSH_KEYS=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--filesystem)
|
|
||||||
DEBI_FILESYSTEM=$2
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--dry-run)
|
|
||||||
DEBI_DRY_RUN=true
|
|
||||||
;;
|
|
||||||
--disk-encryption)
|
|
||||||
DEBI_DISK_ENCRYPTION="crypto"
|
|
||||||
;;
|
|
||||||
--manual)
|
|
||||||
DEBI_MANUAL=true
|
|
||||||
;;
|
|
||||||
--architecture)
|
|
||||||
DEBI_ARCHITECTURE=$2
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--boot-partition)
|
--boot-partition)
|
||||||
DEBI_BOOT_PARTITION=true
|
DEBI_BOOT_PARTITION=true
|
||||||
;;
|
;;
|
||||||
--poweroff)
|
--gpt)
|
||||||
DEBI_POWEROFF=true
|
DEBI_PARTITION_TYPE=gpt
|
||||||
|
;;
|
||||||
|
--dry-run)
|
||||||
|
DEBI_DRY_RUN=true
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo_stderr "Illegal option $1"
|
echo_stderr "Error: Illegal option $1"
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
case "$DEBI_TEMPLATE" in
|
case "$DEBI_PRESET" in
|
||||||
china)
|
china)
|
||||||
|
DEBI_NS=${DEBI_NS:-156.154.70.5 156.154.71.5}
|
||||||
DEBI_PROTOCOL=${DEBI_PROTOCOL:-https}
|
DEBI_PROTOCOL=${DEBI_PROTOCOL:-https}
|
||||||
DEBI_MIRROR=${DEBI_MIRROR:-chinanet.mirrors.ustc.edu.cn}
|
DEBI_MIRROR=${DEBI_MIRROR:-chinanet.mirrors.ustc.edu.cn}
|
||||||
DEBI_TIMEZONE=${DEBI_TIMEZONE:-Asia/Shanghai}
|
DEBI_TIMEZONE=${DEBI_TIMEZONE:-Asia/Shanghai}
|
||||||
DEBI_NTP_SERVER=${DEBI_NTP_SERVER:-cn.ntp.org.cn}
|
DEBI_NTP=${DEBI_NTP:-cn.ntp.org.cn}
|
||||||
DEBI_SECURITY_MIRROR=${DEBI_SECURITY_MIRROR:-true}
|
DEBI_SECURITY=${DEBI_SECURITY:-true}
|
||||||
DEBI_DNS=${DEBI_DNS:-156.154.70.5 156.154.71.5}
|
|
||||||
;;
|
;;
|
||||||
cloud)
|
cloud)
|
||||||
DEBI_PROTOCOL=${DEBI_PROTOCOL:-https}
|
DEBI_PROTOCOL=${DEBI_PROTOCOL:-https}
|
||||||
DEBI_MIRROR=${DEBI_MIRROR:-cdn-aws.deb.debian.org}
|
DEBI_MIRROR=${DEBI_MIRROR:-cdn-aws.deb.debian.org}
|
||||||
DEBI_NTP_SERVER=${DEBI_NTP_SERVER:-time.google.com}
|
DEBI_NTP=${DEBI_NTP:-time.google.com}
|
||||||
DEBI_SECURITY_MIRROR=${DEBI_SECURITY_MIRROR:-true}
|
DEBI_SECURITY=${DEBI_SECURITY:-true}
|
||||||
|
*)
|
||||||
|
echo_stderr "Error: No such preset $DEBI_PRESET"
|
||||||
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
DEBI_PROTOCOL=${DEBI_PROTOCOL:-http}
|
|
||||||
DEBI_MIRROR=${DEBI_MIRROR:-deb.debian.org}
|
|
||||||
DEBI_DIRECTORY=${DEBI_DIRECTORY:-/debian}
|
|
||||||
|
|
||||||
if [ -z "$DEBI_ARCHITECTURE" ]; then
|
|
||||||
if command_exists dpkg; then
|
|
||||||
DEBI_ARCHITECTURE=$(dpkg --print-architecture)
|
|
||||||
else
|
|
||||||
DEBI_ARCHITECTURE=amd64
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
DEBI_SUITE=${DEBI_SUITE:-stretch}
|
DEBI_SUITE=${DEBI_SUITE:-stretch}
|
||||||
DEBI_USERNAME=${DEBI_USERNAME:-debian}
|
|
||||||
DEBI_TIMEZONE=${DEBI_TIMEZONE:-UTC}
|
|
||||||
DEBI_NTP_SERVER=${DEBI_NTP_SERVER:-pool.ntp.org}
|
|
||||||
DEBI_UPGRADE=${DEBI_UPGRADE:-full-upgrade}
|
|
||||||
DEBI_DNS=${DEBI_DNS:-1.1.1.1 1.0.0.1}
|
|
||||||
DEBI_FILESYSTEM=${DEBI_FILESYSTEM:-ext4}
|
|
||||||
DEBI_DISK_ENCRYPTION=${DEBI_DISK_ENCRYPTION:-regular}
|
|
||||||
|
|
||||||
if [ -z "$DEBI_SECURITY_MIRROR" ]; then
|
save_preseed=cat
|
||||||
DEBI_SECURITY_MIRROR=http://security.debian.org/debian-security
|
|
||||||
else
|
|
||||||
if [ "$DEBI_SECURITY_MIRROR" = true ]; then
|
|
||||||
DEBI_SECURITY_MIRROR=$DEBI_PROTOCOL://$DEBI_MIRROR${DEBI_DIRECTORY%/*}/debian-security
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$DEBI_MANUAL" != true ]; then
|
|
||||||
if [ -z "$DEBI_PASSWORD" ]; then
|
|
||||||
DEBI_PASSWORD=$(mkpasswd -m sha-512)
|
|
||||||
else
|
|
||||||
DEBI_PASSWORD=$(mkpasswd -m sha-512 "$DEBI_PASSWORD")
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
DEBI_TARGET="debian-$DEBI_SUITE"
|
|
||||||
if [ "$DEBI_BOOT_PARTITION" = true ]; then
|
|
||||||
DEBI_BOOT_DIRECTORY=/
|
|
||||||
else
|
|
||||||
DEBI_BOOT_DIRECTORY=/boot/
|
|
||||||
fi
|
|
||||||
DEBI_TARGET_PATH="$DEBI_BOOT_DIRECTORY$DEBI_TARGET"
|
|
||||||
|
|
||||||
echo='cat'
|
|
||||||
if [ "$DEBI_DRY_RUN" != true ]; then
|
if [ "$DEBI_DRY_RUN" != true ]; then
|
||||||
user="$(id -un 2>/dev/null || true)"
|
user="$(id -un 2>/dev/null || true)"
|
||||||
|
|
||||||
sudo=''
|
if [ "$user" != root ]; then
|
||||||
if [ "$user" != 'root' ]; then
|
echo_stderr 'Error: Require root.'
|
||||||
if command_exists sudo; then
|
|
||||||
sudo='sudo'
|
|
||||||
else
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
DEBI_WORKDIR="/boot/$DEBI_TARGET"
|
DEBI_NEW="debian-$DEBI_SUITE"
|
||||||
DEBI_BASE_URL=$DEBI_PROTOCOL://$DEBI_MIRROR$DEBI_DIRECTORY/dists/$DEBI_SUITE/main/installer-$DEBI_ARCHITECTURE/current/images/netboot/debian-installer/$DEBI_ARCHITECTURE
|
DEBI_NEW_DIR="/boot/$DEBI_NEW"
|
||||||
if command_exists update-grub; then
|
|
||||||
$sudo update-grub
|
rm -rf "$DEBI_NEW_DIR"
|
||||||
DEBI_GRUB_CONFIG=/boot/grub/grub.cfg
|
mkdir -p "$DEBI_NEW_DIR"
|
||||||
else
|
save_preseed="tee -a $DEBI_NEW_DIR/preseed.cfg"
|
||||||
DEBI_GRUB_CONFIG=/boot/grub2/grub.cfg
|
|
||||||
$sudo grub2-mkconfig -o "$DEBI_GRUB_CONFIG"
|
|
||||||
fi
|
|
||||||
$sudo rm -rf "$DEBI_WORKDIR"
|
|
||||||
$sudo mkdir -p "$DEBI_WORKDIR"
|
|
||||||
cd "$DEBI_WORKDIR"
|
|
||||||
$sudo rm -f preseed.cfg
|
|
||||||
echo="$sudo tee -a preseed.cfg"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$echo << 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
|
||||||
@@ -245,34 +206,36 @@ 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:-1.1.1.1 1.0.0.1}
|
||||||
|
|
||||||
if [ -n "$DEBI_IP" ]; then
|
if [ -n "$DEBI_IP" ]; then
|
||||||
echo "d-i netcfg/disable_autoconfig boolean true" | $echo
|
echo 'd-i netcfg/disable_autoconfig boolean true' | $save_preseed
|
||||||
echo "d-i netcfg/get_ipaddress string $DEBI_IP" | $echo
|
echo "d-i netcfg/get_ipaddress string $DEBI_IP" | $save_preseed
|
||||||
if [ -n "$DEBI_NETMASK" ]; then
|
if [ -n "$DEBI_NETMASK" ]; then
|
||||||
echo "d-i netcfg/get_netmask string $DEBI_NETMASK" | $echo
|
echo "d-i netcfg/get_netmask string $DEBI_NETMASK" | $save_preseed
|
||||||
fi
|
fi
|
||||||
if [ -n "$DEBI_GATEWAY" ]; then
|
if [ -n "$DEBI_GATEWAY" ]; then
|
||||||
echo "d-i netcfg/get_gateway string $DEBI_GATEWAY" | $echo
|
echo "d-i netcfg/get_gateway string $DEBI_GATEWAY" | $save_preseed
|
||||||
fi
|
fi
|
||||||
if [ -n "$DEBI_DNS" ]; then
|
if [ -n "$DEBI_NS" ]; then
|
||||||
echo "d-i netcfg/get_nameservers string $DEBI_DNS" | $echo
|
echo "d-i netcfg/get_nameservers string $DEBI_NS" | $save_preseed
|
||||||
fi
|
fi
|
||||||
echo "d-i netcfg/confirm_static boolean true" | $echo
|
echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$echo << 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
|
||||||
|
|
||||||
if [ -n "$DEBI_HOSTNAME" ]; then
|
if [ -n "$DEBI_HOSTNAME" ]; then
|
||||||
echo "d-i netcfg/hostname string $DEBI_HOSTNAME" | $echo
|
echo "d-i netcfg/hostname string $DEBI_HOSTNAME" | $save_preseed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "d-i hw-detect/load_firmware boolean true" | $echo
|
echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed
|
||||||
|
|
||||||
if [ "$DEBI_SSH" = true ]; then
|
if [ "$DEBI_SSH" = true ]; then
|
||||||
$echo << EOF
|
$save_preseed << EOF
|
||||||
|
|
||||||
# Network console
|
# Network console
|
||||||
|
|
||||||
@@ -280,16 +243,20 @@ 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 "$DEBI_SSH_PASSWORD" ]; then
|
||||||
echo "d-i network-console/password password $DEBI_SSH_PASSWORD" | $echo
|
echo "d-i network-console/password password $DEBI_SSH_PASSWORD" | $save_preseed
|
||||||
echo "d-i network-console/password-again password $DEBI_SSH_PASSWORD" | $echo
|
echo "d-i network-console/password-again password $DEBI_SSH_PASSWORD" | $save_preseed
|
||||||
fi
|
fi
|
||||||
if [ -n "$DEBI_SSH_KEYS" ]; then
|
if [ -n "$DEBI_SSH_KEYS" ]; then
|
||||||
echo "d-i network-console/authorized_keys_url string $DEBI_SSH_KEYS" | $echo
|
echo "d-i network-console/authorized_keys_url string $DEBI_SSH_KEYS" | $save_preseed
|
||||||
fi
|
fi
|
||||||
echo "d-i network-console/start select Continue" | $echo
|
echo 'd-i network-console/start select Continue' | $save_preseed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$echo << EOF
|
DEBI_PROTOCOL=${DEBI_PROTOCOL:-http}
|
||||||
|
DEBI_MIRROR=${DEBI_MIRROR:-deb.debian.org}
|
||||||
|
DEBI_DIRECTORY=${DEBI_DIRECTORY:-/debian}
|
||||||
|
|
||||||
|
$save_preseed << EOF
|
||||||
|
|
||||||
# Mirror settings
|
# Mirror settings
|
||||||
|
|
||||||
@@ -300,70 +267,155 @@ d-i mirror/$DEBI_PROTOCOL/directory string $DEBI_DIRECTORY
|
|||||||
d-i mirror/$DEBI_PROTOCOL/proxy string
|
d-i mirror/$DEBI_PROTOCOL/proxy string
|
||||||
d-i mirror/suite string $DEBI_SUITE
|
d-i mirror/suite string $DEBI_SUITE
|
||||||
d-i mirror/udeb/suite string $DEBI_SUITE
|
d-i mirror/udeb/suite string $DEBI_SUITE
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ "$DEBI_SKIP_USER" != true ]; then
|
||||||
|
DEBI_USERNAME=${DEBI_USERNAME:-debian}
|
||||||
|
|
||||||
|
if command_exists mkpasswd; then
|
||||||
|
if [ -z "$DEBI_PASSWORD" ]; then
|
||||||
|
DEBI_PASSWORD="$(mkpasswd -m sha-512)"
|
||||||
|
else
|
||||||
|
DEBI_PASSWORD="$(mkpasswd -m sha-512 "$DEBI_PASSWORD")"
|
||||||
|
fi
|
||||||
|
elif command_exists python3; then
|
||||||
|
if [ -z "$DEBI_PASSWORD" ]; then
|
||||||
|
DEBI_PASSWORD="$(python3 -c 'import crypt, getpass; print(crypt.crypt(getpass.getpass(), crypt.mksalt(crypt.METHOD_SHA512)))')"
|
||||||
|
else
|
||||||
|
DEBI_PASSWORD="$(python3 -c "import crypt; print(crypt.crypt(\"$DEBI_PASSWORD\", crypt.mksalt(crypt.METHOD_SHA512)))")"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
DEBI_CLEARTEXT=true
|
||||||
|
if [ -z "$DEBI_PASSWORD" ]; then
|
||||||
|
printf 'Password: '
|
||||||
|
read_secret DEBI_PASSWORD
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
$save_preseed << EOF
|
||||||
|
|
||||||
|
# Account setup
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ "$DEBI_USERNAME" = root ]; then
|
||||||
|
echo 'd-i passwd/make-user boolean false' | $save_preseed
|
||||||
|
if [ "$DEBI_CLEARTEXT" = true ]; then
|
||||||
|
$save_preseed << EOF
|
||||||
|
d-i passwd/root-password password $DEBI_PASSWORD
|
||||||
|
d-i passwd/root-password-again password $DEBI_PASSWORD
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
echo "d-i passwd/root-password-crypted password $DEBI_PASSWORD" | $save_preseed
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
$save_preseed << EOF
|
||||||
|
d-i passwd/root-login boolean false
|
||||||
|
d-i passwd/user-fullname string
|
||||||
|
d-i passwd/username string $DEBI_USERNAME
|
||||||
|
EOF
|
||||||
|
if [ "$DEBI_CLEARTEXT" = true ]; then
|
||||||
|
$save_preseed << EOF
|
||||||
|
d-i passwd/user-password password $DEBI_PASSWORD
|
||||||
|
d-i passwd/user-password-again password $DEBI_PASSWORD
|
||||||
|
EOF
|
||||||
|
else
|
||||||
|
echo "d-i passwd/user-password-crypted password $DEBI_PASSWORD"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEBI_TIMEZONE=${DEBI_TIMEZONE:-UTC}
|
||||||
|
DEBI_NTP=${DEBI_NTP:-pool.ntp.org}
|
||||||
|
|
||||||
|
$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 $DEBI_TIMEZONE
|
||||||
d-i clock-setup/ntp boolean true
|
d-i clock-setup/ntp boolean true
|
||||||
d-i clock-setup/ntp-server string $DEBI_NTP_SERVER
|
d-i clock-setup/ntp-server string $DEBI_NTP
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ "$DEBI_MANUAL" != true ]; then
|
if [ "$DEBI_SKIP_PART" != true ]; then
|
||||||
$echo << EOF
|
DEBI_FS=${DEBI_FS:-ext4}
|
||||||
|
DEBI_PART=${DEBI_PART:-regular}
|
||||||
|
|
||||||
# Account setup
|
$save_preseed << EOF
|
||||||
|
|
||||||
d-i passwd/root-login boolean false
|
|
||||||
d-i passwd/user-fullname string
|
|
||||||
d-i passwd/username string $DEBI_USERNAME
|
|
||||||
d-i passwd/user-password-crypted password $DEBI_PASSWORD
|
|
||||||
|
|
||||||
# Partitioning
|
# Partitioning
|
||||||
|
|
||||||
d-i partman/default_filesystem string $DEBI_FILESYSTEM
|
EOF
|
||||||
d-i partman-auto/method string $DEBI_DISK_ENCRYPTION
|
|
||||||
|
if [ -n "$DEBI_DISK" ]; then
|
||||||
|
echo "d-i partman-auto/disk string $DEBI_DISK" | $save_preseed
|
||||||
|
fi
|
||||||
|
|
||||||
|
$save_preseed << EOF
|
||||||
|
d-i partman-auto/method string $DEBI_PART
|
||||||
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_DISK_ENCRYPTION" = "regular" ]; then
|
if [ "$DEBI_PART" = "regular" ]; then
|
||||||
$echo << EOF
|
$save_preseed << EOF
|
||||||
|
d-i partman/default_filesystem string $DEBI_FS
|
||||||
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
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$echo << EOF
|
$save_preseed << EOF
|
||||||
d-i partman-partitioning/confirm_write_new_label boolean true
|
d-i partman-partitioning/confirm_write_new_label boolean true
|
||||||
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
|
||||||
d-i partman/confirm_nooverwrite boolean true
|
d-i partman/confirm_nooverwrite boolean true
|
||||||
d-i partman/mount_style select uuid
|
d-i partman/mount_style select uuid
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
$save_preseed << EOF
|
||||||
|
|
||||||
# Base system installation
|
# Base system installation
|
||||||
|
|
||||||
d-i base-installer/install-recommends boolean false
|
d-i base-installer/install-recommends boolean false
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ -z "$DEBI_SECURITY" ]; then
|
||||||
|
DEBI_SECURITY=http://security.debian.org/debian-security
|
||||||
|
else
|
||||||
|
if [ "$DEBI_SECURITY" = true ]; then
|
||||||
|
DEBI_SECURITY=$DEBI_PROTOCOL://$DEBI_MIRROR${DEBI_DIRECTORY%/*}/debian-security
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
$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_MIRROR $DEBI_SUITE/updates main
|
d-i apt-setup/local0/repository string $DEBI_SECURITY $DEBI_SUITE/updates main
|
||||||
d-i apt-setup/local0/source boolean true
|
d-i apt-setup/local0/source boolean true
|
||||||
|
EOF
|
||||||
|
|
||||||
|
DEBI_UPGRADE=${DEBI_UPGRADE:-full-upgrade}
|
||||||
|
|
||||||
|
$save_preseed << EOF
|
||||||
|
|
||||||
# Package selection
|
# Package selection
|
||||||
|
|
||||||
tasksel tasksel/first multiselect ssh-server
|
tasksel tasksel/first multiselect ssh-server
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -n "$DEBI_INCLUDE" ]; then
|
if [ -n "$DEBI_INSTALL" ]; then
|
||||||
echo "d-i pkgsel/include string $DEBI_INCLUDE" | $echo
|
echo "d-i pkgsel/include string $DEBI_INSTALL" | $save_preseed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$echo << EOF
|
$save_preseed << EOF
|
||||||
d-i pkgsel/upgrade select $DEBI_UPGRADE
|
d-i pkgsel/upgrade select $DEBI_UPGRADE
|
||||||
popularity-contest popularity-contest/participate boolean false
|
popularity-contest popularity-contest/participate boolean false
|
||||||
|
|
||||||
@@ -377,34 +429,64 @@ d-i grub-installer/bootdev string default
|
|||||||
d-i finish-install/reboot_in_progress note
|
d-i finish-install/reboot_in_progress note
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ "$DEBI_POWEROFF" = true ]; then
|
if [ "$DEBI_POWEROFF" = true ]; then
|
||||||
echo 'd-i debian-installer/exit/poweroff boolean true' | $echo
|
echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo2='cat'
|
save_grubcfg=cat
|
||||||
if [ "$DEBI_DRY_RUN" != true ]; then
|
if [ "$DEBI_DRY_RUN" != true ]; then
|
||||||
if command_exists wget; then
|
if [ -z "$DEBI_ARCH" ]; then
|
||||||
$sudo wget "$DEBI_BASE_URL/linux" "$DEBI_BASE_URL/initrd.gz"
|
if command_exists dpkg; then
|
||||||
elif command_exists curl; then
|
DEBI_ARCH="$(dpkg --print-architecture)"
|
||||||
$sudo curl -O "$DEBI_BASE_URL/linux" -O "$DEBI_BASE_URL/initrd.gz"
|
|
||||||
else
|
else
|
||||||
echo_stderr 'wget/curl not found'
|
DEBI_ARCH=amd64
|
||||||
|
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"
|
||||||
|
|
||||||
|
if command_exists wget; then
|
||||||
|
wget -P "$DEBI_NEW_DIR" "$DEBI_BASE_URL/linux" "$DEBI_BASE_URL/initrd.gz"
|
||||||
|
elif command_exists curl; then
|
||||||
|
curl "$DEBI_BASE_URL/linux" -o "$DEBI_NEW_DIR/linux" "$DEBI_BASE_URL/initrd.gz" -o "$DEBI_NEW_DIR/initrd.gz"
|
||||||
|
else
|
||||||
|
echo_stderr 'Error: wget/curl not found.'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$sudo gunzip initrd.gz
|
gunzip initrd.gz
|
||||||
echo preseed.cfg | $sudo cpio -H newc -o -A -F initrd
|
echo preseed.cfg | cpio -H newc -o -A -F initrd
|
||||||
$sudo gzip initrd
|
gzip initrd
|
||||||
echo2="$sudo tee -a $DEBI_GRUB_CONFIG"
|
|
||||||
|
if command_exists update-grub; then
|
||||||
|
DEBI_GRUBCFG=/boot/grub/grub.cfg
|
||||||
|
update-grub
|
||||||
|
elif command_exists grub2-mkconfig; then
|
||||||
|
DEBI_GRUBCFG=/boot/grub2/grub.cfg
|
||||||
|
grub2-mkconfig -o "$DEBI_GRUBCFG"
|
||||||
|
else
|
||||||
|
echo_stderr 'Error: Command update-grub/grub2-mkconfig not found.'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
save_grubcfg="tee -a $DEBI_GRUBCFG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$echo2 << EOF
|
if [ "$DEBI_BOOT_PARTITION" = true ]; then
|
||||||
|
DEBI_BOOT_DIR=/
|
||||||
|
else
|
||||||
|
DEBI_BOOT_DIR=/boot/
|
||||||
|
fi
|
||||||
|
|
||||||
|
DEBI_NEW_DIR="$DEBI_BOOT_DIR$DEBI_NEW"
|
||||||
|
DEBI_PARTITION_TYPE=${DEBI_PARTITION_TYPE:-msdos}
|
||||||
|
|
||||||
|
$save_grubcfg << EOF
|
||||||
menuentry 'Debian Installer' --id debi {
|
menuentry 'Debian Installer' --id debi {
|
||||||
insmod part_msdos
|
insmod part_$DEBI_PARTITION_TYPE
|
||||||
insmod ext2
|
insmod ext2
|
||||||
set root='(hd0,msdos1)'
|
set root='(hd0,${DEBI_PARTITION_TYPE}1)'
|
||||||
linux $DEBI_TARGET_PATH/linux
|
linux $DEBI_NEW_DIR/linux
|
||||||
initrd $DEBI_TARGET_PATH/initrd.gz
|
initrd $DEBI_NEW_DIR/initrd.gz
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
Reference in New Issue
Block a user