debi.sh 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. #!/bin/sh
  2. # shellcheck shell=dash
  3. set -eu
  4. err() {
  5. echo "Error: $1." 1>&2
  6. exit 1
  7. }
  8. command_exists() {
  9. command -v "$1" > /dev/null 2>&1
  10. }
  11. # Sets variable:
  12. late_command=
  13. in_target() {
  14. local command=
  15. for argument in "$@"; do
  16. command="$command $argument"
  17. done
  18. if [ -n "$command" ]; then
  19. [ -z "$late_command" ] && late_command='true'
  20. late_command="$late_command;$command"
  21. fi
  22. }
  23. in_target_backup() {
  24. in_target "if [ ! -e \"$1.backup\" ]; then cp \"$1\" \"$1.backup\"; fi"
  25. }
  26. configure_sshd() {
  27. # !isset($sshd_config_backup)
  28. [ -z ${sshd_config_backup+1s} ] && in_target_backup /etc/ssh/sshd_config
  29. sshd_config_backup=
  30. in_target sed -Ei \""s/^#?$1 .+/$1 $2/"\" /etc/ssh/sshd_config
  31. }
  32. prompt_password() {
  33. local prompt=
  34. if [ $# -gt 0 ]; then
  35. prompt=$1
  36. elif [ "$username" = root ]; then
  37. prompt="Choose a password for the root user: "
  38. else
  39. prompt="Choose a password for user $username: "
  40. fi
  41. stty -echo
  42. trap 'stty echo' EXIT
  43. while [ -z "$password" ]; do
  44. echo -n "$prompt" > /dev/tty
  45. read -r password < /dev/tty
  46. echo > /dev/tty
  47. done
  48. stty echo
  49. trap - EXIT
  50. }
  51. download() {
  52. if command_exists wget; then
  53. wget -O "$2" "$1"
  54. elif command_exists curl; then
  55. curl -fL "$1" -o "$2"
  56. elif command_exists busybox && busybox wget --help > /dev/null 2>&1; then
  57. busybox wget -O "$2" "$1"
  58. else
  59. err 'Cannot find "wget", "curl" or "busybox wget" to download files'
  60. fi
  61. }
  62. set_security_archive() {
  63. case $suite in
  64. stretch|oldstable|buster|stable)
  65. security_archive="$suite/updates"
  66. ;;
  67. bullseye|testing)
  68. security_archive="$suite-security"
  69. ;;
  70. sid|unstable)
  71. security_archive=''
  72. ;;
  73. *)
  74. err "Unsupported suite: $suite"
  75. esac
  76. }
  77. set_daily_d_i() {
  78. case $suite in
  79. stretch|oldstable|buster|stable)
  80. daily_d_i=false
  81. ;;
  82. bullseye|testing|sid|unstable)
  83. daily_d_i=true
  84. ;;
  85. *)
  86. err "Unsupported suite: $suite"
  87. esac
  88. }
  89. set_suite() {
  90. suite=$1
  91. set_daily_d_i
  92. set_security_archive
  93. }
  94. set_debian_version() {
  95. case $1 in
  96. 9|stretch|oldstable)
  97. set_suite stretch
  98. ;;
  99. 10|buster|stable)
  100. set_suite buster
  101. ;;
  102. 11|bullseye|testing)
  103. set_suite bullseye
  104. ;;
  105. sid|unstable)
  106. set_suite sid
  107. ;;
  108. *)
  109. err "Unsupported version: $1"
  110. esac
  111. }
  112. has_cloud_kernel() {
  113. case $suite in
  114. stretch|oldstable)
  115. [ "$architecture" = amd64 ] && [ "$bpo_kernel" = true ] && return
  116. ;;
  117. buster|stable)
  118. [ "$architecture" = amd64 ] && return
  119. [ "$architecture" = arm64 ] && [ "$bpo_kernel" = true ] && return
  120. ;;
  121. bullseye|testing|sid|unstable)
  122. [ "$architecture" = amd64 ] || [ "$architecture" = arm64 ] && return
  123. esac
  124. local tmp; tmp=''; [ "$bpo_kernel" = true ] && tmp='-backports'
  125. echo "\nWarning: No cloud kernel is available for $architecture/$suite$tmp.\nContinuing with the default..." 1>&2
  126. sleep 5
  127. return 1
  128. }
  129. has_backports() {
  130. case $suite in
  131. stretch|oldstable|buster|stable|bullseye|testing) return
  132. esac
  133. echo "\nWarning: No backports kernel is available for $suite.\nContinuing with the default..." 1>&2
  134. sleep 5
  135. return 1
  136. }
  137. ip=
  138. netmask=
  139. gateway=
  140. dns='8.8.8.8 8.8.4.4'
  141. hostname=
  142. network_console=false
  143. set_debian_version 10
  144. mirror_protocol=http
  145. mirror_host=deb.debian.org
  146. mirror_directory=/debian
  147. security_repository=http://security.debian.org/debian-security
  148. account_setup=true
  149. username=debian
  150. password=
  151. authorized_keys_url=
  152. sudo_with_password=false
  153. timezone=UTC
  154. ntp=0.debian.pool.ntp.org
  155. disk_partitioning=true
  156. disk=
  157. force_gpt=true
  158. efi=
  159. filesystem=ext4
  160. kernel=
  161. cloud_kernel=false
  162. bpo_kernel=false
  163. install_recommends=true
  164. install='ca-certificates libpam-systemd'
  165. upgrade=
  166. kernel_params=
  167. bbr=false
  168. hold=false
  169. power_off=false
  170. architecture=
  171. boot_directory=
  172. firmware=false
  173. force_efi_extra_removable=true
  174. grub_timeout=5
  175. dry_run=false
  176. while [ $# -gt 0 ]; do
  177. case $1 in
  178. --cdn|--aws)
  179. mirror_protocol=https
  180. [ "$1" = '--aws' ] && mirror_host=cdn-aws.deb.debian.org
  181. security_repository=mirror
  182. ;;
  183. --china)
  184. dns='223.5.5.5 223.6.6.6'
  185. mirror_protocol=https
  186. mirror_host=mirrors.aliyun.com
  187. ntp=ntp.aliyun.com
  188. security_repository=mirror
  189. ;;
  190. --ip)
  191. ip=$2
  192. shift
  193. ;;
  194. --netmask)
  195. netmask=$2
  196. shift
  197. ;;
  198. --gateway)
  199. gateway=$2
  200. shift
  201. ;;
  202. --dns)
  203. dns=$2
  204. shift
  205. ;;
  206. --hostname)
  207. hostname=$2
  208. shift
  209. ;;
  210. --network-console)
  211. network_console=true
  212. ;;
  213. --version)
  214. set_debian_version "$2"
  215. shift
  216. ;;
  217. --suite)
  218. set_suite "$2"
  219. shift
  220. ;;
  221. --release-d-i)
  222. daily_d_i=false
  223. ;;
  224. --daily-d-i)
  225. daily_d_i=true
  226. ;;
  227. --mirror-protocol)
  228. mirror_protocol=$2
  229. shift
  230. ;;
  231. --https)
  232. mirror_protocol=https
  233. ;;
  234. --mirror-host)
  235. mirror_host=$2
  236. shift
  237. ;;
  238. --mirror-directory)
  239. mirror_directory=${2%/}
  240. shift
  241. ;;
  242. --security-repository)
  243. security_repository=$2
  244. shift
  245. ;;
  246. --no-user|--no-account-setup)
  247. account_setup=false
  248. ;;
  249. --user|--username)
  250. username=$2
  251. shift
  252. ;;
  253. --password)
  254. password=$2
  255. shift
  256. ;;
  257. --authorized-keys-url)
  258. authorized_keys_url=$2
  259. shift
  260. ;;
  261. --sudo-with-password)
  262. sudo_with_password=true
  263. ;;
  264. --timezone)
  265. timezone=$2
  266. shift
  267. ;;
  268. --ntp)
  269. ntp=$2
  270. shift
  271. ;;
  272. --no-part|--no-disk-partitioning)
  273. disk_partitioning=false
  274. ;;
  275. --disk)
  276. disk=$2
  277. shift
  278. ;;
  279. --no-force-gpt)
  280. force_gpt=false
  281. ;;
  282. --bios)
  283. efi=false
  284. ;;
  285. --efi)
  286. efi=true
  287. ;;
  288. --filesystem)
  289. filesystem=$2
  290. shift
  291. ;;
  292. --kernel)
  293. kernel=$2
  294. shift
  295. ;;
  296. --cloud-kernel)
  297. cloud_kernel=true
  298. ;;
  299. --bpo-kernel)
  300. bpo_kernel=true
  301. ;;
  302. --no-install-recommends)
  303. install_recommends=false
  304. ;;
  305. --install)
  306. install=$2
  307. shift
  308. ;;
  309. --no-upgrade)
  310. upgrade=none
  311. ;;
  312. --safe-upgrade)
  313. upgrade=safe-upgrade
  314. ;;
  315. --full-upgrade)
  316. upgrade=full-upgrade
  317. ;;
  318. --ethx)
  319. kernel_params="$kernel_params net.ifnames=0 biosdevname=0"
  320. ;;
  321. --bbr)
  322. bbr=true
  323. ;;
  324. --hold)
  325. hold=true
  326. ;;
  327. --power-off)
  328. power_off=true
  329. ;;
  330. --architecture)
  331. architecture=$2
  332. shift
  333. ;;
  334. --boot-directory)
  335. boot_directory=$2
  336. shift
  337. ;;
  338. --firmware)
  339. firmware=true
  340. ;;
  341. --no-force-efi-extra-removable)
  342. force_efi_extra_removable=false
  343. ;;
  344. --grub-timeout)
  345. grub_timeout=$2
  346. shift
  347. ;;
  348. --dry-run)
  349. dry_run=true
  350. ;;
  351. *)
  352. err "Unknown option: \"$1\""
  353. esac
  354. shift
  355. done
  356. [ -z "$architecture" ] && {
  357. architecture=$(dpkg --print-architecture 2> /dev/null) || {
  358. case $(uname -m) in
  359. x86_64)
  360. architecture=amd64
  361. ;;
  362. aarch64)
  363. architecture=arm64
  364. ;;
  365. i386)
  366. architecture=i386
  367. ;;
  368. *)
  369. err 'No "--architecture" specified'
  370. esac
  371. }
  372. }
  373. [ -z "$kernel" ] && {
  374. kernel="linux-image-$architecture"
  375. [ "$cloud_kernel" = true ] && has_cloud_kernel && kernel="linux-image-cloud-$architecture"
  376. [ "$bpo_kernel" = true ] && has_backports && install="$kernel/$suite-backports $install"
  377. }
  378. [ -n "$authorized_keys_url" ] && ! download "$authorized_keys_url" /dev/null &&
  379. err "Failed to download SSH authorized public keys from \"$authorized_keys_url\""
  380. installer="debian-$suite"
  381. installer_directory="/boot/$installer"
  382. save_preseed='cat'
  383. [ "$dry_run" = false ] && {
  384. [ "$(id -u)" -ne 0 ] && err 'root privilege is required'
  385. rm -rf "$installer_directory"
  386. mkdir -p "$installer_directory"
  387. cd "$installer_directory"
  388. save_preseed='tee -a preseed.cfg'
  389. }
  390. if [ "$account_setup" = true ]; then
  391. prompt_password
  392. elif [ "$network_console" = true ] && [ -z "$authorized_keys_url" ]; then
  393. prompt_password "Choose a password for the installer user of the SSH network console: "
  394. fi
  395. $save_preseed << 'EOF'
  396. # Localization
  397. d-i debian-installer/language string en
  398. d-i debian-installer/country string US
  399. d-i debian-installer/locale string en_US.UTF-8
  400. d-i keyboard-configuration/xkb-keymap select us
  401. # Network configuration
  402. d-i netcfg/choose_interface select auto
  403. EOF
  404. [ -n "$ip" ] && {
  405. echo 'd-i netcfg/disable_autoconfig boolean true' | $save_preseed
  406. echo "d-i netcfg/get_ipaddress string $ip" | $save_preseed
  407. [ -n "$netmask" ] && echo "d-i netcfg/get_netmask string $netmask" | $save_preseed
  408. [ -n "$gateway" ] && echo "d-i netcfg/get_gateway string $gateway" | $save_preseed
  409. [ -z "${ip%%*:*}" ] && [ -n "${dns%%*:*}" ] && dns='2001:4860:4860::8888 2001:4860:4860::8844'
  410. [ -n "$dns" ] && echo "d-i netcfg/get_nameservers string $dns" | $save_preseed
  411. echo 'd-i netcfg/confirm_static boolean true' | $save_preseed
  412. }
  413. if [ -n "$hostname" ]; then
  414. echo "d-i netcfg/hostname string $hostname" | $save_preseed
  415. hostname=debian
  416. domain=
  417. else
  418. hostname=$(cat /proc/sys/kernel/hostname)
  419. domain=$(cat /proc/sys/kernel/domainname)
  420. if [ "$domain" = '(none)' ]; then
  421. domain=
  422. else
  423. domain=" $domain"
  424. fi
  425. fi
  426. $save_preseed << EOF
  427. d-i netcfg/get_hostname string $hostname
  428. d-i netcfg/get_domain string$domain
  429. EOF
  430. echo 'd-i hw-detect/load_firmware boolean true' | $save_preseed
  431. [ "$network_console" = true ] && {
  432. $save_preseed << 'EOF'
  433. # Network console
  434. d-i anna/choose_modules string network-console
  435. d-i preseed/early_command string anna-install network-console
  436. EOF
  437. if [ -n "$authorized_keys_url" ]; then
  438. echo "d-i network-console/authorized_keys_url string $authorized_keys_url" | $save_preseed
  439. else
  440. $save_preseed << EOF
  441. d-i network-console/password password $password
  442. d-i network-console/password-again password $password
  443. EOF
  444. fi
  445. echo 'd-i network-console/start select Continue' | $save_preseed
  446. }
  447. $save_preseed << EOF
  448. # Mirror settings
  449. d-i mirror/country string manual
  450. d-i mirror/protocol string $mirror_protocol
  451. d-i mirror/$mirror_protocol/hostname string $mirror_host
  452. d-i mirror/$mirror_protocol/directory string $mirror_directory
  453. d-i mirror/$mirror_protocol/proxy string
  454. d-i mirror/suite string $suite
  455. EOF
  456. [ "$account_setup" = true ] && {
  457. password_hash=$(mkpasswd -m sha-256 "$password" 2> /dev/null) ||
  458. password_hash=$(openssl passwd -5 "$password" 2> /dev/null) ||
  459. password_hash=$(busybox mkpasswd -m sha256 "$password" 2> /dev/null) || {
  460. for python in python3 python python2; do
  461. password_hash=$("$python" -c 'import crypt, sys; print(crypt.crypt(sys.argv[1], crypt.mksalt(crypt.METHOD_SHA256)))' "$password" 2> /dev/null) && break
  462. done
  463. }
  464. $save_preseed << 'EOF'
  465. # Account setup
  466. EOF
  467. [ -n "$authorized_keys_url" ] && configure_sshd PasswordAuthentication no
  468. if [ "$username" = root ]; then
  469. if [ -z "$authorized_keys_url" ]; then
  470. configure_sshd PermitRootLogin yes
  471. else
  472. in_target "mkdir -m 0700 -p ~root/.ssh && busybox wget -O- \"$authorized_keys_url\" >> ~root/.ssh/authorized_keys"
  473. fi
  474. $save_preseed << 'EOF'
  475. d-i passwd/root-login boolean true
  476. d-i passwd/make-user boolean false
  477. EOF
  478. if [ -z "$password_hash" ]; then
  479. $save_preseed << EOF
  480. d-i passwd/root-password password $password
  481. d-i passwd/root-password-again password $password
  482. EOF
  483. else
  484. echo "d-i passwd/root-password-crypted password $password_hash" | $save_preseed
  485. fi
  486. else
  487. configure_sshd PermitRootLogin no
  488. [ -n "$authorized_keys_url" ] &&
  489. in_target "sudo -u $username mkdir -m 0700 -p ~$username/.ssh && busybox wget -O - \"$authorized_keys_url\" | sudo -u $username tee -a ~$username/.ssh/authorized_keys"
  490. [ "$sudo_with_password" = false ] &&
  491. in_target "echo \"$username ALL=(ALL:ALL) NOPASSWD:ALL\" > \"/etc/sudoers.d/90-user-$username\""
  492. $save_preseed << EOF
  493. d-i passwd/root-login boolean false
  494. d-i passwd/make-user boolean true
  495. d-i passwd/user-fullname string
  496. d-i passwd/username string $username
  497. EOF
  498. if [ -z "$password_hash" ]; then
  499. $save_preseed << EOF
  500. d-i passwd/user-password password $password
  501. d-i passwd/user-password-again password $password
  502. EOF
  503. else
  504. echo "d-i passwd/user-password-crypted password $password_hash" | $save_preseed
  505. fi
  506. fi
  507. }
  508. $save_preseed << EOF
  509. # Clock and time zone setup
  510. d-i time/zone string $timezone
  511. d-i clock-setup/utc boolean true
  512. d-i clock-setup/ntp boolean true
  513. d-i clock-setup/ntp-server string $ntp
  514. EOF
  515. [ "$disk_partitioning" = true ] && {
  516. $save_preseed << 'EOF'
  517. # Partitioning
  518. d-i partman-auto/method string regular
  519. EOF
  520. if [ -n "$disk" ]; then
  521. echo "d-i partman-auto/disk string $disk" | $save_preseed
  522. else
  523. # shellcheck disable=SC2016
  524. echo 'd-i partman/early_command string debconf-set partman-auto/disk "$(list-devices disk | head -n 1)"' | $save_preseed
  525. fi
  526. [ "$force_gpt" = true ] && echo 'd-i partman-partitioning/default_label string gpt' | $save_preseed
  527. echo "d-i partman/default_filesystem string $filesystem" | $save_preseed
  528. [ -z "$efi" ] && {
  529. efi=false
  530. [ -d /sys/firmware/efi ] && efi=true
  531. }
  532. $save_preseed << 'EOF'
  533. d-i partman-auto/expert_recipe string \
  534. naive :: \
  535. EOF
  536. if [ "$efi" = true ]; then
  537. $save_preseed << 'EOF'
  538. 106 106 106 free \
  539. $iflabel{ gpt } \
  540. $reusemethod{ } \
  541. method{ efi } \
  542. format{ } \
  543. . \
  544. EOF
  545. else
  546. $save_preseed << 'EOF'
  547. 1 1 1 free \
  548. $iflabel{ gpt } \
  549. $reusemethod{ } \
  550. method{ biosgrub } \
  551. . \
  552. EOF
  553. fi
  554. $save_preseed << 'EOF'
  555. 1075 1076 -1 $default_filesystem \
  556. method{ format } \
  557. format{ } \
  558. use_filesystem{ } \
  559. $default_filesystem{ } \
  560. mountpoint{ / } \
  561. .
  562. EOF
  563. echo 'd-i partman-auto/choose_recipe select naive' | $save_preseed
  564. $save_preseed << 'EOF'
  565. d-i partman-basicfilesystems/no_swap boolean false
  566. d-i partman/choose_partition select finish
  567. d-i partman/confirm boolean true
  568. d-i partman/confirm_nooverwrite boolean true
  569. EOF
  570. }
  571. $save_preseed << EOF
  572. # Base system installation
  573. d-i base-installer/kernel/image string $kernel
  574. EOF
  575. [ "$install_recommends" = false ] && echo "d-i base-installer/install-recommends boolean $install_recommends" | $save_preseed
  576. [ "$security_repository" = mirror ] && security_repository=$mirror_protocol://$mirror_host${mirror_directory%/*}/debian-security
  577. # If not sid/unstable
  578. [ -n "$security_archive" ] && {
  579. $save_preseed << EOF
  580. # Apt setup
  581. d-i apt-setup/services-select multiselect updates, backports
  582. d-i apt-setup/local0/repository string $security_repository $security_archive main
  583. d-i apt-setup/local0/source boolean true
  584. EOF
  585. }
  586. $save_preseed << 'EOF'
  587. # Package selection
  588. tasksel tasksel/first multiselect ssh-server
  589. EOF
  590. [ -n "$install" ] && echo "d-i pkgsel/include string $install" | $save_preseed
  591. [ -n "$upgrade" ] && echo "d-i pkgsel/upgrade select $upgrade" | $save_preseed
  592. $save_preseed << 'EOF'
  593. popularity-contest popularity-contest/participate boolean false
  594. # Boot loader installation
  595. d-i grub-installer/bootdev string default
  596. EOF
  597. [ "$force_efi_extra_removable" = true ] && echo 'd-i grub-installer/force-efi-extra-removable boolean true' | $save_preseed
  598. [ -n "$kernel_params" ] && echo "d-i debian-installer/add-kernel-opts string$kernel_params" | $save_preseed
  599. $save_preseed << 'EOF'
  600. # Finishing up the installation
  601. EOF
  602. [ "$hold" = false ] && echo 'd-i finish-install/reboot_in_progress note' | $save_preseed
  603. [ "$bbr" = true ] && in_target '{ echo "net.core.default_qdisc=fq"; echo "net.ipv4.tcp_congestion_control=bbr"; } > /etc/sysctl.d/bbr.conf'
  604. [ -n "$late_command" ] && echo "d-i preseed/late_command string in-target sh -c '$late_command'" | $save_preseed
  605. [ "$power_off" = true ] && echo 'd-i debian-installer/exit/poweroff boolean true' | $save_preseed
  606. save_grub_cfg='cat'
  607. [ "$dry_run" = false ] && {
  608. base_url="$mirror_protocol://$mirror_host$mirror_directory/dists/$suite/main/installer-$architecture/current/images/netboot/debian-installer/$architecture"
  609. [ "$daily_d_i" = true ] && base_url="https://d-i.debian.org/daily-images/$architecture/daily/netboot/debian-installer/$architecture"
  610. firmware_url="https://cdimage.debian.org/cdimage/unofficial/non-free/firmware/$suite/current/firmware.cpio.gz"
  611. download "$base_url/linux" linux
  612. download "$base_url/initrd.gz" initrd.gz
  613. [ "$firmware" = true ] && download "$firmware_url" firmware.cpio.gz
  614. gzip -d initrd.gz
  615. # cpio reads a list of file names from the standard input
  616. echo preseed.cfg | cpio -o -H newc -A -F initrd
  617. gzip -9 initrd
  618. mkdir -p /etc/default/grub.d
  619. tee /etc/default/grub.d/zz-debi.cfg 1>&2 << EOF
  620. GRUB_DEFAULT=debi
  621. GRUB_TIMEOUT=$grub_timeout
  622. GRUB_TIMEOUT_STYLE=menu
  623. EOF
  624. if command_exists update-grub; then
  625. grub_cfg=/boot/grub/grub.cfg
  626. update-grub
  627. elif command_exists grub2-mkconfig; then
  628. tmp=$(mktemp)
  629. grep -vF zz_debi /etc/default/grub > "$tmp"
  630. cat "$tmp" > /etc/default/grub
  631. rm "$tmp"
  632. # shellcheck disable=SC2016
  633. echo 'zz_debi=/etc/default/grub.d/zz-debi.cfg; if [ -f "$zz_debi" ]; then . "$zz_debi"; fi' >> /etc/default/grub
  634. grub_cfg=/boot/grub2/grub.cfg
  635. grub2-mkconfig -o "$grub_cfg"
  636. else
  637. err 'Could not find "update-grub" or "grub2-mkconfig" command'
  638. fi
  639. save_grub_cfg="tee -a $grub_cfg"
  640. }
  641. [ -z "$boot_directory" ] && {
  642. if grep -q '\s/boot\s' /proc/mounts; then
  643. boot_directory=/
  644. else
  645. boot_directory=/boot/
  646. fi
  647. }
  648. installer_directory="$boot_directory$installer"
  649. # shellcheck disable=SC2034
  650. mem=$(grep ^MemTotal: /proc/meminfo | { read -r x y z; echo "$y"; })
  651. [ $((mem / 1024)) -le 512 ] && kernel_params="$kernel_params lowmem/low=1"
  652. initrd="$installer_directory/initrd.gz"
  653. [ "$firmware" = true ] && initrd="$initrd $installer_directory/firmware.cpio.gz"
  654. $save_grub_cfg 1>&2 << EOF
  655. menuentry 'Debian Installer' --id debi {
  656. insmod part_msdos
  657. insmod part_gpt
  658. insmod ext2
  659. linux $installer_directory/linux$kernel_params
  660. initrd $initrd
  661. }
  662. EOF