#!/bin/bash
#################################################################################
# /usr/lib/setup/armedslack-nofscheck
#
# On some devices such as the Raspberry Pi, there is no RTC (Real Time Clock)
# which causes fsck checks on the system, which is undesirable because it keeps
# happening since there's no RTC!
# Users using such devices should switch off the fsck checks.
#
# Stuart Winter <mozes@slackware.com>
# 12-Jan-2008, check only for Raspberry Pi v1.
# 10-Mar-2015, check for RPi models 1 & 2, and the HummingBoard i1
# 01-Aug-2018, Check for RPI3 models.
#################################################################################

FSTAB=/var/log/setup/tmp/SeTnative
MODELTYPE=/proc/device-tree/model
EXDEVICES="Raspberry Pi Model B|Raspberry Pi 2 Model B|SolidRun HummingBoard Solo/Dual|Raspberry Pi 3 Model B"

if [ "$( strings $MODELTYPE 2>/dev/null | grep -E "$EXDEVICES" )" != "" -a -s $FSTAB ]; then
   dialog --backtitle "Platform without an RTC (Real Time Clock): skip fsck check" \
     --title "SKIP FSCK CHECKS ON PLATFORM WITHOUT A REAL TIME CLOCK?" --yesno \
"This device is known not have a Real Time Clock (RTC).  This means that \
fsck time-based checks will always run on bootup, and you may experience \
trouble booting the installation. \
\n\n\
It is recommended to switch off fsck checks for all mounts in /etc/fstab \
\n\n\
However, JFS filesystems will ONLY mount after a clean report from fsck - so \
if you have any JFS filesystems, it is recommended to choose 'No'. \
\n\nWould you like to switch off fsck checks? " \
17 69

   if [ $? = 0 ]; then
      # Switch off fsck checks & produce nice output format
      # consistent with Slackware.
      printf "%-16s %-16s %-11s %-16s %-3s %s\n" $( awk "/^ *$(sed -e's?/?\\/?g' <<<"${1:-/dev}")/{\$6=0};{print \$0}" $FSTAB ) > $FSTAB
      # This only works for ext* filesystems but we do it anyway, since
      # without it, the fsck still happens since it's called from /etc/rc.d/rc.S
      # XFS and resierfs seem to be ok without it.
      ( grep ^/ $FSTAB | awk '{print $1}' | while read part ; do
        echo "$part..." ; tune2fs -i0 $part
        done ) > /dev/null 2>&1 # > /tmp/armedslack-tune2fs.debug
   fi
fi

#EOF
