.key DEVICE/A,CLEAN/S,NOCHECK/S,NODEFRAG/S,LIST/S
.BRA (
.KET )
;# 
;# SFSTool 0.8 by P-O Yliniemi <peoyli@algonet.se>
;#
;# $VER: SFSTool 0.8 (21.12.100) © 2000-2001 by P-O Yliniemi
;#
;# A tool for SFS file systems to remove deleted files, check
;# the file system, generate a file list, and defragment the FS.
;#
;# Every function is optional, which means it could be used on
;# any file system using the NOCHECK and NODEFRAG switches.
;#
;# Uses a special version of SFSOpenDefragmentGUI, which opens
;# a much smaller, inactive window, and exits when it is done.
;#
;# If available, it uses the GNU / GG 'find' command to generate
;# file lists (because of its compatibility with symbolic links).
;#
;# Otherwise the AmigaOS 'list' command is used to generate a list
;# that almost looks like the 'find' output, but it will fail when
;# it reaches a symbolic link.
;#
;# Parameters:
;#   DEVICE      - Device to perform the actions on (required)
;#
;#   CLEAN       - Remove the files in the .recycled directory
;#   NOCHECK     - Do not run SFSCheck on the device
;#   NODEFRAG    - Do not run SFSDefragmentGUI on the device
;#
;#   LIST        - Generate a list of all the files and store as :.filelist
;#
failat 200

set error 0

if (CLEAN)
  echo noline "Removing stuff from [(DEVICE).recycled]..."
  delete >nil: (DEVICE).recycled/#? quiet
  echo "done"
endif

if not (NOCHECK)
  echo noline "Checking [(DEVICE)]..."
  c:SFS/SFSCheck (DEVICE) >t:sfscheck.out
  if fail
    echo "Error!"
    type t:sfscheck.out >"CON:0/0/640/200/SFSCheck Result - error/AUTO/CLOSE/WAIT"
    set error 1
  else
    echo "OK"
    set error 0
  endif
endif

if (LIST)
  echo noline "Generating file list for [(DEVICE)]..."
  which find >nil:
  if warn
    list all (DEVICE) lformat "%f%n" >(DEVICE).filelist files
  else
    find (DEVICE) -type f -o -type l >(DEVICE).filelist
  endif
  echo "done"
endif

if not (NODEFRAG)
  if $error eq 1
    echo "[(DEVICE)] not defragmented due to errors!"
  else
    echo noline "Defragging [(DEVICE)]..."
    c:SFS/SFSDefragmentGUI (DEVICE)
    echo "done"
  endif
endif

unset error
