Skip to content

Commit

Permalink
Merge pull request #28 from happymab/usb-fix
Browse files Browse the repository at this point in the history
Filters USB devices to not be listed in disk selection dialog. Add a config value to allow USB devices to show in selection dialog. Fixes installation on USB devices.
  • Loading branch information
sysrich authored Jun 14, 2024
2 parents d0521bd + 199d8c9 commit cae5ecf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
4 changes: 4 additions & 0 deletions usr/lib/tik/config
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ TIK_CUSTOM_DIR="/etc/tik"
# Default: "/usr/lib/tik/img"
TIK_IMG_DIR="/usr/lib/tik/img"

# To show USB devices in the install device selection dialog, uncomment this variable
# USB devices are filtered out by default
#TIK_ALLOW_USB_INSTALL_DEVICES=1

# For unattended installations the disk device to deploy the image must be defined
# Default: Undefined
#TIK_INSTALL_DEVICE=""
Expand Down
47 changes: 41 additions & 6 deletions usr/lib/tik/lib/tik-functions
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ get_disk() {
local message
local blk_opts_plus_label="${blk_opts},LABEL"
local tik_install_disk_part
local part_meta
local part_count
local part_size
local part_info
local part_fs
local blk_opts_part_info="${blk_opts_plus_label},FSTYPE"
local usb_match_1="usb"
local usb_match_2=":0"

tik_install_disk_part=$(
eval lsblk "${blk_opts_plus_label}" | \
Expand All @@ -106,6 +114,27 @@ get_disk() {
continue
fi
disk_device="$(echo "${disk_meta}" | cut -f1 -d:)"
# find partitions and info for this disk
part_count=0
part_info=""
for part_meta in $(
eval lsblk "${blk_opts_part_info}" | grep -E "${disk_device}.+part.+" | tr ' ' ":"
);do
part_count=$(expr $part_count + 1)
part_size=$(echo "${part_meta}" | cut -f2 -d:)
part_fs=$(echo "${part_meta}" | cut -f5 -d:)
if [ -n "${part_info}" ]; then
part_info="${part_info},"
fi
if [ -n "${part_fs}" ]; then
part_info="${part_info}${part_fs}(${part_size})"
else
part_info="${part_info}unknown(${part_size})"
fi
done
if [[ ${part_count} -eq 0 ]]; then
part_info="none"
fi
if [[ "${tik_install_disk_part}" == "${disk_device}"* ]]; then
# ignore install source device
continue
Expand All @@ -121,10 +150,15 @@ get_disk() {
disk_device_by_id=$(
get_persistent_device_from_unix_node "${disk_device}" "${disk_id}"
)
if [[ ( "${TIK_ALLOW_USB_INSTALL_DEVICES}" -ne 1 ) && ( "{$disk_device_by_id}" == *"${usb_match_1}"* || "{$disk_device_by_id}" == *"${usb_match_2}"* ) ]]; then
# ignore USB devices if TIK_ALLOW_USB_INSTALL_DEVICES not set in config
continue
fi
if [ -n "${disk_device_by_id}" ];then
disk_device=${disk_device_by_id}
fi
list_items="${list_items} $(basename ${disk_device}) ${disk_size}"
list_items="${list_items} $(basename ${disk_device}) ${disk_size} ${part_count} ${part_info}"
disk_list="${disk_list} $(basename ${disk_device}) ${disk_size}"
done
if [ -n "${TIK_INSTALL_DEVICE}" ];then
# install device overwritten by config.
Expand All @@ -144,15 +178,16 @@ get_disk() {
grep -E "disk|raid" | tr ' ' ":"
)
device_size=$(echo "${device_meta}" | cut -f2 -d:)
# this case is not shown in manual selection, threfore we don't need partition info
list_items="$(basename ${device}) ${device_size}"
disk_list="$(basename ${device}) ${device_size}"
message="tik installation device set to to: ${device}"
log "${message}"
fi
if [ -z "${list_items}" ];then
local no_device_text="No device(s) for installation found."
error "${no_device_text}"
fi
disk_list=${list_items}
if [ -n "${disk_list}" ];then
local count=0
local device_index=0
Expand All @@ -175,7 +210,7 @@ get_disk() {
fi
else
# manually select from storage list
d --list --column=Disk --column=Size --width=1000 --height=340 --title="Select A Disk" --text="Select the disk to install the operating system to. <b>Make sure any important documents and files have been backed up.</b>\n" ${list_items}
d --list --column=Disk --column=Size --column=Partitions --column=Filesystems --width=1000 --height=340 --title="Select A Disk" --text="Select the disk to install the operating system to. <b>Make sure any important documents and files have been backed up.</b>\n" ${list_items}
# Add back full path to it
TIK_INSTALL_DEVICE="/dev/disk/${disk_id}/${result}"

Expand All @@ -201,9 +236,9 @@ get_img() {
for img_meta in $(
eval cd $TIK_IMG_DIR && (stat --printf="%n\t%s\n" *.raw.xz | tr ' ' ":")
);do
img_filename="$(echo $img_meta | cut -f1 -d:)"
img_size="$(echo $img_meta | cut -f2 -d:)"
list_items="${list_items} ${img_filename} ${img_size}"
img_filename="$(echo $img_meta | cut -f1 -d:)"
img_size="$(echo $img_meta | cut -f2 -d:)"
list_items="${list_items} ${img_filename} ${img_size}"
done
if [ -n "${TIK_INSTALL_IMAGE}" ];then
# install image overwritten by config.
Expand Down
10 changes: 6 additions & 4 deletions usr/lib/tik/modules/pre/20-mig
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ probe_partitions() {
fi
prun /usr/bin/mkdir -p ${mig_dir}/mnt
probedpart=""
for part in $(lsblk ${device} -p -n -r -o ID-LINK,FSTYPE|tr -s ' ' ":"|grep ":${filesystem_type}"|cut -d: -f1); do
prun /usr/bin/mount ${mountops} /dev/disk/by-id/${part} ${mig_dir}/mnt
for part in $(lsblk ${device} -p -n -r -o ID-LINK,FSTYPE|tr -s ' ' ";"|grep ";${filesystem_type}"|cut -d\; -f1); do
# Fallback to unix device in order to fix issue with USB devices
prun /usr/bin/mount ${mountops} "$(/usr/bin/readlink -f "/dev/disk/by-id/${part}")" "${mig_dir}/mnt"
# Check if ${filematch} exists
if [ -f ${mig_dir}/mnt/${filematch} ]; then
probedpart=/dev/disk/by-id/${part}
# Fallback to unix device in order to fix issue USB devices
probedpart="$(/usr/bin/readlink -f "/dev/disk/by-id/""${part}")"
log "[probe_partitions] /dev/disk/by-id/${part} found"
if grep -q 'PRETTY_NAME="openSUSE MicroOS"' ${mig_dir}/mnt/${filematch} && [ -f ${mig_dir}/mnt/usr/bin/gnome-shell ]; then
# Found legacy Aeon, activate easter egg
Expand Down Expand Up @@ -74,7 +76,7 @@ if [ -z "${skipbackup}" ]; then
# some users might have nevertheless enabled encryption anyway.
# Search for existing crypto_LUKS partitions and, if found, prompt the user
# to unlock those so that the migration module can find existing data.
for encrypted_partition in $(lsblk ${TIK_INSTALL_DEVICE} -p -n -r -o ID-LINK,FSTYPE|tr -s ' ' ":"|grep ":crypto_LUKS"|cut -d: -f1); do
for encrypted_partition in $(lsblk ${TIK_INSTALL_DEVICE} -p -n -r -o ID-LINK,FSTYPE|tr -s ' ' ";"|grep ";crypto_LUKS"|cut -d\; -f1); do
if [ -e /dev/mapper/crypt_${encrypted_partition} ]; then
# Already opened for some reason... do not prompt for the passphrase
# but ensure we will clean up afterwards
Expand Down

0 comments on commit cae5ecf

Please sign in to comment.