Skip to content

Commit

Permalink
Make the local archive in /dell/debs/ when using the customized insta…
Browse files Browse the repository at this point in the history
…llation without the recovery partition. (Closes: #105)
  • Loading branch information
fourdollars authored and superm1 committed Jun 16, 2020
1 parent e72f4bc commit db47388
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 22 deletions.
57 changes: 57 additions & 0 deletions late/chroot_scripts/60-detect-no-recovery-patition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3

import glob
import json
from os.path import basename
import os
import subprocess as cmd
import shutil

devices = []

for name in glob.glob('/sys/block/*'):
name = basename(name)
if name.startswith('sd'):
devices.append(name)
elif name.startswith('md'):
devices.append(name)
elif name.startswith('nvme'):
devices.append(name)
elif name.startswith('pmem'):
devices.append(name)

root = cmd.check_output("findmnt -M / -o source -v | tail -n1", shell=True)
root = basename(root.decode().strip())
root_device = ''

cdrom = cmd.check_output("findmnt -M /cdrom -o source -v | tail -n1", shell=True)
cdrom = basename(cdrom.decode().strip())
cdrom_device = ''

disks = json.loads(cmd.check_output("lsblk -fs -J", shell=True).decode())
disks = disks['blockdevices']

for disk in disks:
if disk['name'] == root:
data = json.dumps(disk)
for device in devices:
if device in data:
root_device = device
break
elif disk['name'] == cdrom:
data = json.dumps(disk)
for device in devices:
if device in data:
cdrom_device = device
break

if root_device == cdrom_device:
exit(0)

print('No recovery partition is detected.')

os.makedirs('/dell/debs')

for folder in ('/cdrom/pool', '/cdrom/debs'):
for deb in glob.glob(f'{folder}/**/*.deb', recursive=True):
shutil.copy(deb, f'/dell/debs')
5 changes: 5 additions & 0 deletions late/scripts/chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ if ! mount | grep "$TARGET/run"; then
mount --bind /run $TARGET/run
MOUNT_CLEANUP="$TARGET/run $MOUNT_CLEANUP"
fi
if ! mount | grep "$TARGET/pts"; then
[ ! -e "$TARGET/pts" ] && mkdir -p "$TARGET/pts"
mount -t devpts devpts $TARGET/pts
MOUNT_CLEANUP="$TARGET/pts $MOUNT_CLEANUP"
fi
if ! mount | grep "$TARGET/proc"; then
mount -t proc targetproc $TARGET/proc
MOUNT_CLEANUP="$TARGET/proc $MOUNT_CLEANUP"
Expand Down
42 changes: 25 additions & 17 deletions late/scripts/oem_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,46 @@
# $1 -> early/late
#
# for early:
# $2 -> /cdrom or /isodevice
# $2 -> /cdrom or /isodevice or none when /dell/debs exists for no recovery partition.

DEVICE=$(python3 << EOF
from Dell.recovery_common import find_partition
print(find_partition().decode('utf-8'))
device = find_partition()
if device:
print(device.decode('utf-8'))
EOF
)

if [ "$1" = "early" ]; then
mkdir -p $2
mount $DEVICE $2
if [ -f $2/.disk/info.recovery -a ! -f $2/.disk/info ]; then
cp $2/.disk/info.recovery $2/.disk/info
fi
if [ -f "$2/factory/grubenv" ]; then
grub-editenv $2/factory/grubenv unset install_finished
fi
mount -o remount,ro $2
if [ -f "$2/ubuntu.iso" ]; then
mount -o loop $2/ubuntu.iso /cdrom
if [ -n "$2" ]; then
mkdir -p "$2"
mount "$DEVICE" "$2"
if [ -f "$2"/.disk/info.recovery ] && [ ! -f "$2"/.disk/info ]; then
cp "$2"/.disk/info.recovery "$2"/.disk/info
fi
if [ -f "$2"/factory/grubenv ]; then
grub-editenv "$2"/factory/grubenv unset install_finished
fi
mount -o remount,ro "$2"
if [ -f "$2"/ubuntu.iso ]; then
mount -o loop "$2"/ubuntu.iso /cdrom
fi
fi
/usr/share/dell/scripts/pool.sh
elif [ "$1" = "late" ]; then
if [ -d "/isodevice" ]; then
umount /isodevice
rm -rf /isodevice
fi
mount $DEVICE /cdrom
if [ -f /cdrom/.disk/info.recovery -a -f /cdrom/.disk/info ]; then
rm -f /cdrom/.disk/info
if [ -n "$DEVICE" ]; then
mount "$DEVICE" /cdrom
if [ -f /cdrom/.disk/info.recovery ] && [ -f /cdrom/.disk/info ]; then
rm -f /cdrom/.disk/info
fi
umount /cdrom
elif [ -d /dell/debs ]; then
rm -fr /dell
fi
umount /cdrom
/usr/share/dell/scripts/pool.sh cleanup

BOOTNUMS=$(efibootmgr | sed '/MokSBStateSet/!d; s,\* .*,,; s,Boot,,')
Expand Down
4 changes: 2 additions & 2 deletions late/scripts/pool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# MA 02110-1301, USA.
# vim:ts=8:sw=8:et:tw=0

[ -d /cdrom/debs -o -d /isodevice/debs ]
[ -d /cdrom/debs ] || [ -d /isodevice/debs ] || [ -d /dell/debs ]

#Persistent mode has a tendency to break the dynamic apt cache
if grep -q persistent /proc/cmdline 2>/dev/null; then
Expand Down Expand Up @@ -64,7 +64,7 @@ if [ ! -f /etc/apt/sources.list.d/dell.list ]; then
mv /etc/apt/sources.list.d/* /etc/apt/sources.list.d.old
fi
#Produce a dynamic list
for dir in /cdrom/debs /isodevice/debs;
for dir in /cdrom/debs /isodevice/debs /dell/debs;
do
if [ -d "$dir" ]; then
cd $dir
Expand Down
8 changes: 5 additions & 3 deletions ubiquity/dell-bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,7 @@ def unset_drive_preseeds(self):
'grub-installer/only_debian',
'grub-installer/with_other_os',
'grub-installer/bootdev',
'grub-installer/make_active',
'oem-config/early_command',
'oem-config/late_command']
'grub-installer/make_active']
self.usb_boot_preseeds(keys)

def fixup_recovery_devices(self):
Expand Down Expand Up @@ -904,6 +902,10 @@ def cleanup(self):
elif rec_type == "interactive":
self.ui.show_dialog("forward")
self.unset_drive_preseeds()
self.preseed('oem-config/early_command',
'/usr/share/dell/scripts/oem_config.sh early')
self.preseed('oem-config/late_command',
'/usr/share/dell/scripts/oem_config.sh late')

# Factory install, and booting from RP
else:
Expand Down

0 comments on commit db47388

Please sign in to comment.