NoPaste

debian preseed early script

von heisenberg

SNIPPET_TEXT:
  1. #!/bin/sh
  2.  
  3. target_ready() {
  4.  
  5.         [ -r /target/bin/apt-get ]              \
  6.         && [ -r /target/bin/bash ]
  7.  
  8. }
  9.  
  10. cacerts_installed() {
  11.  
  12.         [ -r /target/var/lib/dpkg/info/ca-certificates.list ]
  13.  
  14. }
  15.  
  16. install_cacerts() {
  17.  
  18.         mkdir /target/mycd
  19.         mount -o ro /dev/cdrom /target/mycd
  20.         cd /target
  21.  
  22.         OPENSSL_PKG=$(find mycd -iname openssl_*.deb)
  23.         if [ -f $OPENSSL_PKG ] ; then
  24.                 in-target /bin/apt install -y /$OPENSSL_PG
  25.         fi
  26.  
  27.         CACERTS_PKG=$(find mycd -iname ca-certificates_*all.deb)
  28.         if [ -f $CACERTS_PKG ] ; then
  29.                 in-target /bin/apt install -y /$CACERTS_PKG
  30.         fi
  31.  
  32.         umount /target/mycd
  33. }
  34.  
  35. mylog() {
  36.         /usr/bin/logger -t cacert_install "$1"
  37. }
  38.  
  39. main() {
  40.  
  41.         for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ;do
  42.                 mylog "checking if /target is ready"
  43.                 if target_ready ; then
  44.                         mylog "/target is ready"
  45.                         if ! cacerts_installed ; then
  46.                                 mylog "ca-certificates not installed, trying to install (try: $i)"
  47.                                 install_cacerts
  48.                                 mylog "ca-certificates installed. Verfiying."
  49.                                 cacerts_installed && exit 0
  50.                                 mylog "ca-certificates still not installed"
  51.                         else
  52.                                 exit 0
  53.                         fi
  54.                 else
  55.                         mylog "/target not ready so far"
  56.                 fi
  57.                 sleep 10
  58.         done
  59.         mylog "could not install ca-certificates after 20 tries. giving up."
  60.  
  61. }
  62.  
  63. main >/tmp/cacertinstall.log 2>&1 &

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN