######################################################################################
# Script.....: /usr/lib/setup/armedslack-filter-SLK-partitions
# Called from: /sbin/probe
# Purpose....: Prevent any of the Slackware /boot, firmware partitions or Slackware
#              Installation media USB sticks from being presented as candidates to be
#              formatted or mounted.
#              These are handled by the installer directly and require no user
#              involvement.
# Author.....: Stuart Winter <mozes@slackware.com>
# Date.......: 02-Jan-2022
# Status.....: NOTUPSTREAMED - unnecessary
#
######################################################################################
# Copyright 2021, 2022 Stuart Winter, Donostia, Spain.
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
######################################################################################
#
# Labels:
# SLKins = Media (usually a USB stick) containing the Slackware install media
#          This FS label isn't required to locate the media, but it's helpful
#          as a way to exclude the media from the list of candidates.
# SLKhwm_bw = Hardware Model Bootware - native Bootware for the RPi
# SLKboot = Slackware OS /boot partition
# We don't filter out 'SLKroot' (Slackware OS root FS) because it's unnecessary
# and if the FS is already labeled when this script runs, the device won't appear
# as a candidate for the root FS within the menu.
#            
# The wrapping of e2label is because whilst it handles other file system types,
# it includes verbosity about the filesystem type; where as for ext filesystems
# it outputs only the label.
######################################################################################

for mmcdev in /dev/mmcblk* ; do
   { ( e2label ${mmcdev} 2>/dev/null | tail -n1 | rev \
       | awk '{print $1}' | rev | tr -d "'" | \
       grep -Eq '^SLK(ins|hwm_bw|boot)$' ) && sed -i '\|^'"${mmcdev}"'|d' $TMP/SeTfdisk ;}
done
