|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Set hostname from DHCP |
| 4 | +fix_hostname() { |
| 5 | + NEWHOSTNAME=`hostname|sed -e 's/\..*//'` |
| 6 | + NEWDOMAIN=`hostname|sed -e 's/[^.]*\.//'` |
| 7 | + echo $NEWHOSTNAME > /etc/hostname |
| 8 | +} |
| 9 | + |
| 10 | +# Set system time from NTP and hwclock |
| 11 | +configure_time() { |
| 12 | + echo "Setting time..." |
| 13 | + hwclock -s |
| 14 | + ntpdate ntp |
| 15 | + hwclock -w |
| 16 | +} |
| 17 | + |
| 18 | +# Creates EFI partition |
| 19 | +create_efi() { |
| 20 | + mkfs.fat -F32 $EFI_DEVICE |
| 21 | + mount_efi |
| 22 | + mkdir -p /mnt/efi/EFI/ |
| 23 | + umount_efi |
| 24 | +} |
| 25 | + |
| 26 | +# Sets default block devices if they are not set |
| 27 | +set_block_devices() { |
| 28 | + if [ -z $DISK ]; then |
| 29 | + DISK=/dev/sda |
| 30 | + fi |
| 31 | + |
| 32 | + if [ $UEFI = true ]; then |
| 33 | + if [ -z $DEVICE ]; then |
| 34 | + DEVICE=${DISK}2 |
| 35 | + fi |
| 36 | + |
| 37 | + if [ -z $EFI_DEVICE ]; then |
| 38 | + EFI_DEVICE=${DISK}1 |
| 39 | + fi |
| 40 | + else |
| 41 | + if [ -z $DEVICE ]; then |
| 42 | + DEVICE=${DISK}1 |
| 43 | + fi |
| 44 | + fi |
| 45 | +} |
| 46 | + |
| 47 | +mount_efi() { |
| 48 | + mount $EFI_DEVICE /mnt/efi || { echo "ERROR: mount $DEVICE failed"; exit 5; } |
| 49 | + cat /proc/mounts > /etc/mtab |
| 50 | +} |
| 51 | + |
| 52 | +umount_efi() { |
| 53 | + umount /mnt/efi |
| 54 | + cat /proc/mounts > /etc/mtab |
| 55 | +} |
| 56 | + |
| 57 | +mount_win() { |
| 58 | + mount -o permissions $DEVICE /mnt/hd || { echo "ERROR: mount $DEVICE failed"; exit 5; } |
| 59 | + cat /proc/mounts > /etc/mtab |
| 60 | +} |
| 61 | + |
| 62 | +umount_win() { |
| 63 | + umount /mnt/hd |
| 64 | + cat /proc/mounts > /etc/mtab |
| 65 | +} |
| 66 | + |
| 67 | +mount_lin() { |
| 68 | + |
| 69 | + mount $DEVICE /mnt/hd |
| 70 | + mount -t proc proc /mnt/hd/proc |
| 71 | + mount -o bind /dev /mnt/hd/dev/ |
| 72 | + mount -o bind /sys /mnt/hd/sys/ |
| 73 | +} |
| 74 | + |
| 75 | +umount_lin() { |
| 76 | + umount /mnt/hd/sys |
| 77 | + umount /mnt/hd/proc |
| 78 | + umount /mnt/hd/dev |
| 79 | + umount /mnt/hd |
| 80 | +} |
| 81 | + |
| 82 | +win_reg_set_utc_time() { |
| 83 | + mount_win |
| 84 | + |
| 85 | + echo -e "cd ControlSet001\\Control\\TimeZoneInformation\nnv 4 RealTimeIsUniversal\ned RealTimeIsUniversal\n1\nq\ny" | chntpw -e /mnt/hd/Windows/System32/config/SYSTEM |
| 86 | + |
| 87 | + umount_win |
| 88 | +} |
| 89 | + |
| 90 | +fix_grub2() { |
| 91 | + mount_lin |
| 92 | + chroot /mnt/hd /usr/sbin/update-grub |
| 93 | + if [ $UEFI = true ]; then |
| 94 | + mount $EFI_DEVICE /mnt/hd/boot/efi |
| 95 | + chroot /mnt/hd /usr/sbin/grub-install --target=x86_64-efi --force $DISK |
| 96 | + umount /mnt/hd/boot/efi |
| 97 | + else |
| 98 | + chroot /mnt/hd /usr/sbin/grub-install --force $DISK |
| 99 | + fi |
| 100 | + umount_lin |
| 101 | +} |
| 102 | + |
| 103 | +# Restore partition table from ptable, ptable.sfdisk or ptable.sgdisk |
| 104 | +restore_ptable() { |
| 105 | + ROOTDEVICE=$(echo $DISK|sed -e 's/^\([a-z\/]*\).*/\1/') |
| 106 | + |
| 107 | + cd $IMAGEPATH/komputery/$BASECOMP |
| 108 | + echo `pwd` |
| 109 | + if [ -e ptable ]; then |
| 110 | + echo "Taking as ptable: ptable" |
| 111 | + dd if=ptable of=$ROOTDEVICE |
| 112 | + elif [ -e ptable.sfdisk ]; then |
| 113 | + echo "Taking as ptable: ptable.sfdisk" |
| 114 | + sfdisk $ROOTDEVICE < ptable.sfdisk |
| 115 | + elif [ -e ptable.sgdisk ]; then |
| 116 | + echo "Taking as ptable: ptable.sgdisk" |
| 117 | + sgdisk --zap-all $ROOTDEVICE |
| 118 | + sgdisk --load-backup=ptable.sgdisk $ROOTDEVICE |
| 119 | + sgdisk --randomize-guids $ROOTDEVICE |
| 120 | + elif [ -e $IMAGEPATH/res/ptable.sfdisk ]; then |
| 121 | + echo "Taking as ptable: ptable.sfdisk" |
| 122 | + sfdisk $ROOTDEVICE < $IMAGEPATH/res/ptable.sfdisk |
| 123 | + else |
| 124 | + echo "No valid ptable found!" |
| 125 | + exit 2 |
| 126 | + fi |
| 127 | + cd $IMAGEPATH |
| 128 | + sync |
| 129 | + blockdev --rereadpt $ROOTDEVICE |
| 130 | +} |
| 131 | + |
| 132 | +recreate_windows_efi() { |
| 133 | + mount_efi |
| 134 | + mount_win |
| 135 | + |
| 136 | + mkdir -p /mnt/efi/EFI/Microsoft/Boot/ |
| 137 | + cp -r /mnt/hd/Windows/Boot/EFI/. /mnt/efi/EFI/Microsoft/Boot/ |
| 138 | + if [ -f $IMAGEPATH/komputery/$BASECOMP/BCD ]; then |
| 139 | + BCD_FILE=$IMAGEPATH/komputery/$BASECOMP/BCD |
| 140 | + else |
| 141 | + BCD_FILE=$IMAGEPATH/res/BCD |
| 142 | + fi |
| 143 | + cp $BCD_FILE /mnt/efi/EFI/Microsoft/Boot/BCD |
| 144 | + |
| 145 | + umount_efi |
| 146 | + umount_win |
| 147 | +} |
| 148 | + |
| 149 | +install_debian() { |
| 150 | + if [ $UEFI = true ]; then |
| 151 | + GRUB_VARIANT=grub-efi |
| 152 | + else |
| 153 | + GRUB_VARIANT=grub-pc |
| 154 | + fi |
| 155 | + |
| 156 | + mkfs.ext4 -c -FF $DEVICE |
| 157 | + mount $DEVICE /mnt/hd |
| 158 | + mmdebstrap --include=linux-image-amd64,$GRUB_VARIANT,xserver-xorg-video-all,gnome,gnome-shell-extension-dash-to-panel,libreoffice-gtk3,bash-completion,vim,nano,htop,locales,firefox-esr-l10n-pl,libreoffice-l10n-pl,$INSTALL_APPS --arch amd64 $DEBIAN_VERSION /mnt/hd http://ftp.pl.debian.org/debian/ |
| 159 | + |
| 160 | + echo -e "$DEVICE\t/\text4\terrors=remount-ro\t0\t1" > /mnt/hd/etc/fstab |
| 161 | + if [ $UEFI = true ]; then |
| 162 | + mkdir /mnt/hd/boot/efi/ |
| 163 | + echo -e "$EFI_DEVICE\t/boot/efi\tvfat\tdefaults\t0\t1" >> /mnt/hd/etc/fstab |
| 164 | + fi |
| 165 | + |
| 166 | + echo GRUB_DISABLE_RECOVERY=\"true\" >> /mnt/hd/etc/default/grub |
| 167 | + echo sleep-inactive-ac-type=\'blank\' >> /mnt/hd/etc/gdm3/greeter.dconf-defaults |
| 168 | + echo -e "[org.gnome.desktop.wm.preferences]\nbutton-layout='appmenu:minimize,maximize,close'\nnum-workspaces=1\n\n[org.gnome.desktop.interface]\nenable-hot-corners=false\n\n[org.gnome.shell]\nfavorite-apps=['firefox-esr.desktop', 'libreoffice-writer.desktop', 'org.gnome.Nautilus.desktop']\nenabled-extensions=['[email protected]', '[email protected]', '[email protected]', '[email protected]']\n\n[org.gnome.shell.extensions.dash-to-panel]\npanel-size=32\nshow-show-apps-button=false\n\n[org.gnome.login-screen]\ndisable-user-list=true\n\n[org.gnome.settings-daemon.plugins.power]\nsleep-inactive-ac-type='nothing'" > /mnt/hd/usr/share/glib-2.0/schemas/00_xivlo.gschema.override |
| 169 | + chroot /mnt/hd glib-compile-schemas /usr/share/glib-2.0/schemas/ |
| 170 | + echo Europe/Warsaw > /mnt/hd/etc/timezone |
| 171 | + ln -sf /usr/share/zoneinfo/Europe/Warsaw /mnt/hd/etc/localtime |
| 172 | + echo pl_PL\.UTF-8\ UTF-8 >> /mnt/hd/etc/locale.gen |
| 173 | + chroot /mnt/hd locale-gen |
| 174 | + echo LANG=\"pl_PL.utf8\" > /mnt/hd/etc/default/locale |
| 175 | + echo KEYMAP=pl2 > /mnt/hd/etc/vconsole.conf |
| 176 | + sed -i -e 's/XKBLAYOUT=.*/XKBLAYOUT=pl/' /mnt/hd/etc/default/keyboard |
| 177 | + umount /mnt/hd |
| 178 | + |
| 179 | + fix_grub2 |
| 180 | +} |
| 181 | + |
| 182 | +install_windows() { |
| 183 | + mkfs.ntfs --fast --label Windows $DEVICE |
| 184 | + wimapply obrazy/windows_images/Win_Pro_10_2004_64BIT_Polish.wim 5 $DEVICE |
| 185 | + recreate_windows_efi |
| 186 | +} |
| 187 | + |
| 188 | +uninstall_windows_apps() { |
| 189 | + UNINSTALL_APPS="Microsoft.SkypeApp Microsoft.Xbox.TCUI Microsoft.XboxApp Microsoft.XboxGameOverlay Microsoft.XboxGamingOverlay Microsoft.XboxIdentityProvider Microsoft.XboxSpeechToTextOverlay Microsoft.MicrosoftOfficeHub Microsoft.OneConnect Microsoft.Messaging" |
| 190 | + |
| 191 | + for I in $UNINSTALL_APPS; do |
| 192 | + rm -r /mnt/hd/Program\ Files/WindowsApps/${I}_* |
| 193 | + done |
| 194 | +} |
0 commit comments