Advertisement
Guest User

Untitled

a guest
May 20th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 19.63 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # USB-Installer for user Live-System
  4. # Version 10.02.07 by Markus Mandalka
  5. #
  6. # Format and encrypt the choosen USB-Device and install user into it
  7.  
  8.  
  9. # print error message and abbort installing
  10.  error()
  11. {
  12.   $DIALOG --title "Error" --msgbox "$@" 0 0;
  13.   exit 1;
  14. }
  15.  
  16.  
  17. unmount_device()
  18. {
  19.   # unmount device
  20.   # FIX IT1 : 1tik 10rako bukle bat egin
  21.   # FIX IT2: udev erabili aukeratutako usb-giltza desmontatzeko.
  22.    umount $@1
  23.   umount $@2
  24.   umount $@3
  25.   umount $@4
  26. }
  27.  
  28.  
  29. if [ -e /usr/bin/Xdialog ]
  30. then
  31.     DIALOG="Xdialog"
  32. else
  33.     DIALOG="dialog"
  34. fi
  35.  
  36. installer_dir=$(dirname $0)
  37.  
  38. mount_target="/tmp/user-install-$$";
  39. mount_base="/tmp/squashfs-$$";
  40.  
  41.  
  42.  
  43. # Language and messages
  44.  
  45. title_select="Install user Live-System";
  46. msg_select="\nChoose an usb-device (usb-key or external harddisk),
  47. on which user will be installed:"
  48.  
  49. menuitem_none="None"
  50. menuitem_none_description="No device"
  51.  
  52. msg_error_password="Error: The passwords did not match!"
  53. title_password="Password";
  54.  msg_password_1="Password"
  55. msg_password_2="Checking password"
  56.  
  57. title_password_admin="Admin-Password";
  58. msg_password_admin_1="Password for software-administration:"
  59. msg_password_admin_2="Checking admin-password:"
  60.  
  61.  
  62.  
  63.  
  64. title_done="Installation done"
  65. msg_done="Installation done.
  66.  
  67. You can now boot user from the usb-device."
  68. msg_overwrite_ask_title="Overwrite old data?"
  69. msg_overwrite_ask="
  70. Overwrite old data on the device with random data?
  71.  
  72. This may take long time.
  73.  
  74. If you don't do it,
  75. - parts of the data, that were on the device before
  76. the installation could be restored by others very easy.
  77. - others can find out, how much data is saved
  78. inside the encrypted partition.
  79.  
  80. If it is not only a test installation,
  81. choose [yes] here !
  82.  
  83. Overwrite old data?";
  84. title_overwrite="Deleting old data";
  85.  msg_overwrite="\nOverwriting device with random data ...";
  86. title_are_you_sure="Danger: Data on this device will be deleted!!!";
  87. msg_are_you_sure1="Are you absoluteley sure, that data on this device
  88. should be overwritten?
  89.  
  90. "
  91. msg_are_you_sure2="
  92.  
  93. If you selected the wrong device you will loose all data
  94. on the usb-key or on the external harddisk!
  95.  
  96. If you choose < Yes >, there will be no return!
  97.  
  98. Realy continue and overwrite the selected device?";
  99.  
  100. msg_error_mounted="The selected device is mounted!
  101.  
  102. Please unmount it and start again!";
  103.  
  104.  
  105. # Messages not used by the gui
  106. # You don't have to translate them to support another language
  107.  msg_error_luksformat="Error while luksformat!";
  108. msg_error_luksopen="Error while luksopen!";
  109.  
  110. msg_overwrite_done="Overwrite done.";
  111. msg_luksformat="Encrypting device ...";
  112.  msg_luksopen="Opening encrypted device ...";
  113. msg_umount_rootcrypt="Unmounting root-filesystem ...";
  114. msg_syncing="Syncing unwritten data. Please wait ...";
  115. msg_error_mkfs_root="Error while making filesystem on /dev/mapper/root_crypt ! Abort.";
  116.  msg_error_mount_boot="Error mounting boot-partition! Abort.";
  117. msg_error_mount_root="Error mounting /dev/mapper/root_crypt ! Abort.";
  118. msg_error_copy_root="Error while copy system to target! Maybe this parts of the cd-rom are not readable or there is not enough space on your usb-device.";
  119.  msg_error_umount_boot="Error while umount boot-partition ! Abort.";
  120. msg_error_umount_root="Error while umount /dev/mapper/root_crypt ! Abort.";
  121. msg_error_luksclose="Error while closing devicemaper with luksClose! Abort.";
  122.  msg_update_grub="
  123. Writing bootmenu ...";
  124. msg_copy_root="
  125. Copy system into the encrypted partition.
  126. This may take a while. Please wait ...";
  127.  
  128. msg_mkfs_root="
  129.  
  130. Formating root-filesystem:
  131.  
  132. ";
  133. msg_sfdisk="Writing partitiontable ...";
  134. msg_mount_boot="
  135. Mount boot-partition ...";
  136. msg_mkfssetup="Setup crypttab and fstab";
  137. msg_copy_boot="
  138. Copy kernel to bootpartition. Please wait ...";
  139.  msg_grub_install="
  140. Installing bootloader ...
  141.  
  142. "
  143. msg_mkfs_boot="
  144. Formating boot filesystem:
  145. ";
  146. msg_error_copy_boot="
  147. Error while copying! Abort.
  148.  
  149. Maybe the cd-rom is not readable.
  150. ";
  151. msg_mount_proc="Mounting /proc ...";
  152. msg_mount_dev="Mounting /dev ...";
  153. msg_update_initramfs="
  154. Creating Initramdisks with cryptroot setup ...";
  155. msg_mkbootiso="
  156.  
  157. Creating boot-cd-iso ...";
  158. msg_umount_proc="Unmounting /proc ...";
  159. msg_umount_dev="Unmounting /dev ...";
  160. msg_umount_boot="Unmounting /boot ...";
  161. msg_error_grub_install="Error while grub-install! Abort.";
  162.  msg_error_update_grub="Error while update-grub ! Abort.";
  163. msg_error_update_initramfs="Error while update-initramfs! Abort.";
  164. msg_error_sfdisk="Error while writing partition table with sfdisk !
  165.  
  166. Abort.";
  167. msg_error_mount_proc="Error while mounting /proc to target! Abort.";
  168. msg_error_mount_dev="Error while mounting /dev to target. Abort.";
  169. msg_error_mount_base="Error mounting squashfs! Abort.";
  170.  msg_error_mkfs_boot="Error creating filesystem (mkfs.vfat on boot)! Abort.";
  171.  
  172. msg_mkfs_doc="Create filesystem for windows ...";
  173. msg_error_mkfs_doc="Error while formating windows-filesystem!";
  174.  msg_mount_doc="Mounting windows readable filesystem ...";
  175. msg_umount_doc="Unmounting windows readable filesystem ...";
  176. msg_error_umount_doc="Error while unmounting windows readable filesystem!";
  177.  
  178. case "$LANG" in
  179. de*|at*|ch*)
  180.  
  181. title_select="user Installation";
  182. msg_select="Wählen Sie das Gerät
  183. (Speicherkarte, USB-Stick oder externe Festplatte),
  184. auf dem user installiert werden soll:"
  185.  
  186. menuitem_none="None"
  187. menuitem_none_description="Kein Gerät"
  188.  
  189. title_done="Installation abgeschlossen"
  190. msg_done="Die Installation wurde erfolgreich abgeschlossen.
  191.  
  192. Sie können user nun vom eben eingerichteten Datenträger booten."
  193.  
  194. msg_error_password="Fehler: Das Passwort stimmt nicht überein!"
  195. title_password="Passwort";
  196. msg_password_1="Verschlüsselungspasswort eingeben:"
  197. msg_password_2="Bitte das Verschlüsselungspasswort wiederholen:"
  198.  
  199. title_password_admin="Admin-Passwort";
  200. msg_password_admin_1="Admin-Passwort für zukünftige Einstellungen eingeben:"
  201. msg_password_admin_2="Bitte das Admin-Passwort wiederholen:"
  202.  
  203.  
  204. msg_error_luksformat="Fehler beim Aufruf von luksformat!";
  205. msg_error_luksopen="Fehler beim Aufruf von luksopen!";
  206.  
  207. msg_overwrite_ask_title="Alte Daten überschreiben?"
  208. msg_overwrite_ask="
  209. Soll der Datenträger mit Zufallsdaten überschrieben werden?
  210.  
  211. Dieser Schritt dauert bei grossen Festplatten sehr lange.
  212.  
  213. Wird das Überschreiben jedoch nicht durchgeführt,
  214. - können Teile der Daten, die sich vor der Installation
  215. auf diesem Datenträger befunden haben, mit einfachsten Mitteln
  216. wieder her gestellt werden
  217. - kann evtl. herausgefunden werden, wie viel Speicherplatz
  218. im verschlüsselten Bereich tatsächlich belegt ist.
  219.  
  220. Wenn es sich nicht um eine reine Testinstallation handelt,
  221. sollten Sie unbedingt [Ja] wählen!
  222.  
  223. Sollen vor der Installation alte Daten überschrieben werden?";
  224. title_overwrite="Lösche alte Daten";
  225. msg_overwrite="\nDer Datenträger wird mit Zufallsdaten überschrieben ...";
  226.  msg_overwrite_done="Das Überschreiben ist abgeschlossen.";
  227. msg_luksformat="Verschlüssele das Gerät ...";
  228. msg_luksopen="Öffne verschlüsseltes Gerät ...";
  229. msg_umount_rootcrypt="Hänge das Root-Filesystem wieder aus ...";
  230.  msg_syncing="Synchronisiere noch ungeschriebene Daten. Bitte warten ...";
  231. msg_error_mkfs_root="Fehler beim Anlegen des Filesystems auf /dev/mapper/root_crypt ! Abbruch.";
  232. msg_error_mount_boot="Fehler beim Mounten der Boot-Partition ! Abbruch.";
  233.  msg_error_mount_root="Fehler beim Mounten von /dev/mapper/root_crypt ! Abbruch.";
  234. msg_error_copy_root="Fehler beim Kopieren auf das Ziel!
  235. Vielleicht kann die CD nicht richtig gelesen werden
  236. oder auf dem Datenträger war zu wenig
  237. freier Speicherplatz verfügbar.";
  238. msg_error_umount_boot="Fehler beim Aushängen (umount) der Boot-Partition ! Abbruch.";
  239. msg_error_umount_root="Fehler beim Aushängen (umount) von /dev/mapper/root_crypt ! Abbruch.";
  240.  msg_error_luksclose="Fehler beim Schliessen des Devicemappers mit luksClose! Abbruch.";
  241. title_are_you_sure="Achtung: Daten auf diesem Datenträger werden gelöscht!!!";
  242. msg_update_grub="
  243. Schreibe Bootmenu ...";
  244.  msg_copy_root="
  245.  
  246. Kopiere das System in die verschlüsselte Partition.
  247.  
  248. Dies kann eine Weile dauern. Bitte warten ...";
  249. msg_mkfs_root="
  250.  
  251. Formatiere Root-Dateisystem:
  252.  
  253. ";
  254. msg_sfdisk="Lege Partitionstabelle an ...";
  255.  msg_mount_boot="
  256. Mounte Boot-Partition ...";
  257. msg_mkfssetup="
  258. Erstelle crypttab und fstab ...";
  259. msg_copy_boot="
  260. Kopiere Kernel in die Bootpartition. Bitte warten ...";
  261. msg_grub_install="
  262. Installiere den Bootloader ...
  263.  
  264. "
  265. msg_mkfs_boot="
  266. Formatiere Boot-Dateisystem:
  267. ";
  268. msg_error_copy_boot="
  269. Fehler beim Kopieren! Abbruch.
  270.  
  271. Vielleicht kann die CD nicht richtig gelesen werden?
  272. ";
  273. msg_mount_proc="Mounte /proc in Target ...";
  274. msg_mount_dev="Mounte /dev in Target ...";
  275. msg_update_initramfs="
  276. Aktualisiere Initramdisks mit Cryptroot-Einstellungen ...";
  277.  msg_mkbootiso="
  278.  
  279. Erstelle CD-Abbild der Boot-CD ...";
  280. msg_umount_proc="Hänge im Target /proc wieder aus...";
  281. msg_umount_dev="Hänge im Target /dev wieder aus...";
  282. msg_umount_boot="Hänge das Boot-Filesystem wieder aus ...";
  283.  msg_error_grub_install="Fehler beim Aufruf von grub-install! Abbruch.";
  284. msg_error_update_grub="Fehler beim Aufruf von update-grub ! Abbruch.";
  285. msg_error_update_initramfs="Fehler bei update-initramfs! Abbruch.";
  286.  msg_error_sfdisk="Fehler beim Schreiben der Partitionstabelle mit sfdisk !
  287.  
  288. Abbruch.";
  289. msg_error_mount_proc="Fehler beim Mounten von /proc in Target! Abbruch.";
  290. msg_error_mount_dev="Fehler beim Mounten von /dev in Target. Abbruch.";
  291.  msg_error_mount_base="Fehler beim Mounten des squashfs! Abbruch.";
  292. msg_error_mkfs_boot="Fehler beim Anlegen des Filesystems (mkfs.vfat) auf boot! Abbruch.";
  293.  
  294.  
  295. msg_mkfs_doc="Lege das unter Windows lesbare Dateisystem für die Dokumentation an ...";
  296.  msg_error_mkfs_doc="Fehler beim Anlegen des unter Windows lesbaren Dateisystems";
  297. msg_mount_doc="Hänge unter Windows lesbares Dateisystem ein ...";
  298. msg_umount_doc="Hänge unter Windows lesbares Dateisystem aus ...";
  299.  msg_error_umount_doc="Fehler beim Aushängen des Windows-Dateisystems";
  300.  
  301. msg_are_you_sure1="Sind Sie sich absolut sicher, dass der nachfolgende Datenträger
  302. verwendet werden soll?
  303.  
  304. ";
  305. msg_are_you_sure2="
  306.  
  307. Falls Sie das falsche Gerät gewählt haben,
  308. werden Daten auf einem anderen USB-Speicher
  309. oder einer externen Festplatte überschrieben!
  310.  
  311. Wenn Sie mit < Ja > bestätigen, gibt es kein Zurück mehr
  312. und auf dem gewählten Datenträger vorhandenen Daten sind verloren!
  313.  
  314. Wirklich fortfahren und den Datenträger formatieren?";
  315.  
  316. msg_error_mounted="Der zu verschlüsselnde Datenträger ist noch eingehängt
  317. und wird offenbar noch genutzt!
  318.  
  319. Bitte schliessen Sie alle Programme, die auf Dateien des Datenträgers zugreifen,
  320. hängen Sie den Datenträger aus und führen Sie dann dieses Programm erneut aus!";
  321.  
  322. ;;
  323. esac
  324.  
  325. modprobe dm-crypt
  326.  
  327. # Select USB-Device
  328. filter="usb-devices"
  329. TEMPFILE=/tmp/selection.$$
  330.  
  331. if ! partsel -d $DIALOG -f $filter -o $TEMPFILE -t "$title_select" -m "$msg_select" -nt "$menuitem_none" -nd "$menuitem_none_description"
  332. then
  333.   exit
  334. fi
  335.  
  336. choice=`cat $TEMPFILE`
  337.  rm $TEMPFILE
  338.  
  339. if [ "$choice" == "$menuitem_none" ];
  340. then
  341.    exit
  342. fi
  343.  
  344. device=$choice;
  345.  
  346. # Get infos about the device to ask, if it is the right one
  347. model=$(udevadm --query=env -p `udevadm -q path -n $device` 2>/dev/null | grep "ID_MODEL=" | cut -f 2 -d "=" | sed s/_/\ /g| tr -d [:punct:])
  348.  bus=$(udevadm --query=env -p `udevadm -q path -n $device` 2>/dev/null | grep "ID_BUS=" | cut -f 2 -d "=" | sed s/_/\ /g)
  349. size=$(LC_ALL=C fdisk -l $device 2>/dev/null | grep Disk | grep -i bytes | cut -f 1 -d "," | cut -f 3,4 -d " ");
  350.  vendor=$(udevadm --query=env -p ${partition} 2>/dev/null | grep "ID_VENDOR=" | cut -f2 -d'='|sed s/_/\ /g| tr -d [:punct:])
  351.  
  352. modelandvendor="$model";
  353. [ -n "$vendor" ] && modelandvendor="$modelandvendor ($vendor)";
  354.  msg_are_you_sure="$msg_are_you_sure1$device: $modelandvendor - $size$msg_are_you_sure2"
  355.  
  356. if ! $DIALOG --title "$title_are_you_sure" --yesno "$msg_are_you_sure" 0 0;
  357.   then
  358.     exit
  359.  fi;
  360.  
  361.  
  362. # Ask password for normal user
  363. PASSWORD1=$($DIALOG --stdout --title $title_password --passwordbox "$msg_password_1" 0 0) || exit
  364. PASSWORD2=$($DIALOG --stdout --title $title_password --passwordbox "$msg_password_2" 0 0) || exit
  365.  
  366. if [ "$PASSWORD1" != "$PASSWORD2" ]
  367. then
  368.   error "$msg_error_password";
  369.   exit 1;
  370. fi
  371. PASSWORD2="";
  372.  
  373. # Ask password for root (admin)
  374. PASSWORDADMIN1=$($DIALOG --stdout --title $title_password_admin --passwordbox "$msg_password_admin_1" 0 0) || exit
  375.  PASSWORDADMIN2=$($DIALOG --stdout --title $title_password_admin --passwordbox "$msg_password_admin_2" 0 0) || exit
  376.  
  377. if [ "$PASSWORDADMIN1" != "$PASSWORDADMIN2" ]
  378. then
  379.   error "$msg_error_password";
  380.    exit 1;
  381. fi
  382. PASSWORDADMIN2="";
  383.  
  384. # $device = /dev/sdX
  385. unmount_device $device;
  386.  
  387. # check if the device or a parition on the device is mounted
  388. if cat /etc/mtab | grep $device && echo $?
  389.    then
  390.     error "$msg_error_mounted";
  391. fi
  392.  
  393. # ask if overwrite old data
  394. if $DIALOG --title "$msg_overwrite_ask_title" --yesno "$msg_overwrite_ask" 0 0;
  395. then
  396.  
  397.   # Overwrite old data
  398.    dd bs=2M if=/dev/urandom count=1| pv -n --size=$(fdisk -s $device)k 2>&1 >$device | $DIALOG --title "$title_overwrite" --gauge "$msg_overwrite" 0 0;
  399.  
  400.   clear;
  401.   echo $msg_overwrite_done;
  402.  
  403. else
  404.   # Overwrite begin of the old partition
  405.   # so that the system won't try to mount it
  406.   # after following initialize of the new partition table
  407.   dd bs=2M count=1 if=/dev/zero of=$device
  408.  
  409.   clear;
  410.  fi;
  411.  
  412.  
  413. # Create partitions
  414. echo "$msg_sfdisk";
  415. if ! sfdisk $device -uM <<EOF
  416. ,32,b
  417. ,96,L
  418. ,,L
  419. EOF
  420. then
  421.  error "$msg_error_sfdisk";
  422. fi
  423.  
  424. # Read the new partition table
  425.  partprobe $device
  426.  
  427. # Yet existing (if not overwritten) filesystems could be mounted again after rereading new partition table, so we unmount it again
  428. unmount_device $device;
  429.  
  430. clear;
  431.  
  432. device_doc=${device}1
  433.  device_boot=${device}2
  434. device_root=${device}3
  435.  
  436. # crypt device
  437. echo "$msg_luksformat";
  438. if ! echo -n "$PASSWORD1" | cryptsetup --batch-mode luksFormat $device_root
  439. then
  440.  error "$msg_error_luksformat";
  441.  fi;
  442.  
  443.  
  444. # open crypted device
  445. echo "$msg_luksopen";
  446. if ! echo -n "$PASSWORD1" | cryptsetup luksOpen $device_root root_crypt
  447. then
  448.  error "$msg_error_luksopen";
  449. fi;
  450.  
  451.  PASSWORD1="";
  452.  
  453. #mount_target="/tmp/user-install-$$";
  454. #mount_base="/tmp/squashfs-$$";
  455.  
  456. # create filesystem
  457. echo "$msg_mkfs_root"
  458. if ! mkfs.ext3 -L sistema /dev/mapper/root_crypt
  459.  
  460.  then
  461.  error "$msg_error_mkfs_root";
  462. fi;
  463.  
  464. mkdir $mount_target
  465. if ! mount /dev/mapper/root_crypt $mount_target
  466. then
  467.   error "$msg_error_mount_root";
  468. fi
  469.  
  470. # mount the squashfs and copy system to target
  471.  echo "$msg_copy_root";
  472. mkdir $mount_base
  473. if ! mount -o loop /live/image/live/filesystem.squashfs $mount_base
  474. then
  475.   error "$msg_error_mount_base";
  476. fi;
  477.  
  478. if ! cp -a $mount_base/* $mount_target/
  479.  then
  480.   error "$msg_error_copy_root";
  481. fi;
  482.  
  483. # /boot at root_crypt only as mount directory for the unencrypted boot-partition
  484. #rm -R $mount_target/boot
  485.  
  486. rm -R $mount_target/boot
  487. mkdir $mount_target/boot
  488.  
  489. # Remove installer
  490.  #rm $mount_target/home/user/Desktop/Installation.desktop
  491. #rm $mount_target/usr/local/sbin/installer
  492. # Remove builder
  493. #rm -R $mount_target/usr/local/src/user
  494.  
  495. echo "$msg_syncing";
  496. sync
  497.  
  498. umount $device_boot >/dev/null 2>/dev/null
  499.  
  500. echo "$msg_mkfs_boot"
  501. if ! mkfs.ext3 -L boot $device_boot
  502. then
  503.   error "$msg_error_mkfs_boot";
  504. fi;
  505.  
  506. # $mount_target = $mount_base-n dagoena $mount_target dagenaren antzekoa. USBan koiatuko dena.
  507.  # $mount_base=squashfs-n dauden datuak ditu lerroa 467
  508.  
  509. echo "$msg_mount_boot";
  510.  
  511. if ! mount $device_boot $mount_target/boot
  512. then
  513.   error "Error mounting $device_boot on $mount_target/syslinux ! Abort."
  514.  fi
  515.  
  516. echo "$msg_copy_boot";
  517.  
  518. if ! cp $mount_base/boot/* $mount_target/boot/
  519. then
  520.   error "$msg_error_copy_boot";
  521. fi
  522.  
  523. #echo "$msg_copy_boot";
  524. #mkdir $mount_target/syslinux
  525. #if ! cp /syslinux/* $mount_target/syslinux
  526. #then
  527. #  error "$msg_error_copy_boot";
  528. #fi
  529.  
  530. echo "$msg_syncing";
  531. sync
  532.  
  533.  
  534. umount $device_doc >/dev/null 2>/dev/null
  535.  
  536. echo "$msg_mkfs_doc"
  537. if ! mkfs.vfat -n boota $device_doc
  538. then
  539.   error "$msg_error_mkfs_doc";
  540. fi;
  541.  
  542. echo 'VFAT OK!!!!!'
  543.  
  544. echo "$msg_mount_doc";
  545.  
  546. mkdir $mount_target/win
  547.  
  548. if ! mount $device_doc $mount_target/win
  549. then
  550.   error "Error mounting $device_doc on $mount_target/win ! Abort."
  551. fi
  552.  
  553. mkdir $mount_target/win/boot
  554.  
  555. if ! cp /boot/* $mount_target/win/boot
  556. then
  557.   echo "dos";
  558.   error "$msg_error_copy_boot";
  559.  
  560. fi
  561.  
  562. mkdir $mount_target/win/syslinux
  563.  
  564. if ! cp -r /syslinux/* $mount_target/win/syslinux
  565. then
  566.   echo "tres";
  567.   error "$msg_error_copy_boot";
  568.  
  569. fi
  570.  
  571. umount $mount_base
  572. rmdir $mount_base
  573.  
  574.  
  575. echo "$msg_mkfssetup";
  576.  
  577. root_uuid=`/lib/udev/vol_id -u $device_root`
  578. boot_uuid=`/lib/udev/vol_id -u $device_boot`
  579. doc_uuid=`/lib/udev/vol_id -u $device_doc`
  580.  
  581. # Create fstab
  582. echo "# /etc/fstab: static file system information.
  583. #
  584. # <file system> <mount point>   <type>  <options>       <dump>  <pass>
  585. proc            /proc           proc    defaults        0       0
  586. /dev/mapper/root_crypt /               ext3    errors=remount-ro 0       1
  587. /dev/disk/by-uuid/$boot_uuid /boot ext3 defaults 0 1
  588. /dev/disk/by-uuid/$doc_uuid /win vfat noauto,ro,noexec,nosuid 0 1" >$mount_target/etc/fstab
  589.  
  590. # Create crypttab
  591. echo "root_crypt /dev/disk/by-uuid/$root_uuid none luks" >$mount_target/etc/crypttab
  592.  
  593. # Create kernel-img.conf
  594. echo "do_initrd = yes" >>$mount_target/etc/kernel-img.conf
  595.  
  596. # Set hostname
  597. echo "user" > $mount_target/etc/hostname
  598.  
  599. # Set hosts
  600. cat >> $mount_target/etc/hosts << EOF
  601.  127.0.0.1 localhost
  602. 127.0.1.1 user
  603.  
  604. # The following lines are desirable for IPv6 capable hosts
  605. ::1     ip6-localhost ip6-loopback
  606. fe00::0 ip6-localnet
  607. ff00::0 ip6-mcastprefix
  608. ff02::1 ip6-allnodes
  609. ff02::2 ip6-allrouters
  610.  ff02::3 ip6-allhosts
  611. EOF
  612.  
  613.  
  614. echo "$msg_grub_install";
  615.  
  616. mkdir $mount_target/boot/grub
  617. echo "(hd0) $device" >$mount_target/boot/grub/device.map;
  618.  
  619. if ! /usr/sbin/grub-install --no-floppy --root-directory=$mount_target $device
  620. then
  621.   error "$msg_error_grub_install";
  622. fi
  623.  
  624. echo "$msg_mount_proc";
  625. if ! mount -t proc /proc $mount_target/proc
  626. then
  627.   error "$msg_error_mount_proc";
  628.  fi;
  629.  
  630. echo "$msg_mount_dev";
  631. if ! mount -o bind /dev $mount_target/dev
  632. then
  633.   error "$msg_error_mount_dev";
  634. fi;
  635.  
  636. echo "$msg_update_grub";
  637. if ! chroot $mount_target update-grub
  638.  then
  639.   error "$msg_error_update_grub";
  640. fi
  641.  
  642. echo "$msg_update_initramfs";
  643. # Create new initramdisk because of changed crypttab
  644. if ! chroot $mount_target update-initramfs -u
  645. then
  646.    error "$msg_error_update_initramfs";
  647. fi;
  648.  
  649. echo "$msg_mkbootiso";
  650. # Create boot.iso containing this ramdisk with our crypttab
  651. chroot $mount_target/ /usr/local/sbin/mkbootiso
  652.  
  653. # Delete packages that are not needet on usb-device
  654. chroot $mount_target/ apt-get -y purge live-helper
  655. chroot $mount_target/ apt-get -y autoremove
  656.  
  657. # set root- and user-password
  658. chroot $mount_target/ chpasswd -c MD5 <<EOF
  659. root:$PASSWORDADMIN1
  660. user:$PASSWORD1
  661. EOF
  662.  
  663. # Copy doc to windows-readable partition
  664. cp /win/image/usb.html $mount_target/win/index.html
  665. cp /win/image/style.css $mount_target/win
  666. cp /win/image/autorun.bat $mount_target/win
  667. cp /win/image/autorun.inf $mount_target/win
  668. cp $mount_target/boot/boot.iso $mount_target/win
  669.  
  670. echo "$msg_umount_dev";
  671. umount $mount_target/dev
  672. echo "$msg_umount_proc";
  673. umount $mount_target/proc
  674.  
  675. echo "$msg_umount_doc";
  676.  if ! umount $device_doc
  677. then
  678.   error "$msg_error_umount_doc";
  679. fi
  680.  
  681.  
  682. echo "$msg_umount_boot";
  683. if ! umount $device_boot
  684. then
  685.   error "$msg_error_umount_boot";
  686. fi
  687.  
  688. echo "$msg_umount_rootcrypt";
  689. if ! umount /dev/mapper/root_crypt
  690. then
  691.   error "$msg_error_umount_root";
  692. fi
  693.  
  694. if ! cryptsetup luksClose root_crypt
  695. then
  696.   error "$msg_error_luksclose";
  697.  fi
  698.  
  699. rmdir $mount_target
  700. $DIALOG --title "$title_done" --msgbox "$msg_done" 0 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement