< Oberon < A2
#!/bin/bash 
# A script to start UnixAos with a working directory which can be in a
# removable flash store. 
# A flash store is accomodated in various machines by copying 
# machine specific configurations into Configuration.XML and 
# Oberon.Text. 
# 
# Conditions for this script to work. 
# * The volume containing the working files has a reliable name.
#   https://wiki.archlinux.org/index.php/Persistent_block_device_naming
#   Examples here are GRNSD and BlackSDHC1.
# * A mount point and working directory exist for the working volume.  
#   MountPoint and WorkingDirectory can be the same or different.
#   A system may automount the volume at another location.  Automounting
#   is harmless to this script. 
# * The following assignments to WorkingVolume, WorkingDirectory
#   and MountPoint are correct. 
# * An appropriate entry exists in /etc/fstab.  This is an example. 
#   /dev/GRNSD /home/me/MY ext2 defaults,noauto,user,users,exec 0  0 
# * /etc/sudoers.d/sudoers is adjusted to allow the user to e2fsck the working
#   filesystem.
#   me mycomputer = NOPASSWD: /sbin/e2fsck
#   Test e2fsck interactively.
# * If the working volume is removeable the user can mount it.  Note the 
#   user option in /etc/fstab. 
# * /usr/bin/aos attempts to create the link .aoshome to /usr/bin/aos in the 
#   working directory but a FAT file system does not allow links.  This can be 
#   resolved by bind mounting a directory, .aoshome, to /usr/bin/aos. 
#   Create the directory .aoshome in the Working Directory. 
#   Add a line to /etc/fstab to allow the user to perform the mount. 
#   /usr/aos /home/me/MY/.aoshome none rbind,user,users
#   Uncomment the mount and umount commands below.
#   My preference is to reformat the flash card from FAT to ext2. 
# 
# WorkingVolume=/dev/BLKSDHC41 
WorkingVolume=/dev/GRNSD
echo WorkingVolume is $WorkingVolume.
WorkingDirectory=/home/$USER/MY
echo WorkingDirectory=$WorkingDirectory.
MountPoint=/home/$USER/MY
echo MountPoint is $MountPoint.
# For any hostname violating Oberon file name syntax, make a conformant name.
# Otherwise, the name is conformant. Use it.
# Ref. https://www.tldp.org/LDP/abs/html/comparison-ops.html
if [[ $(hostname) = xo-53-1d-bb* ]]; then
     h="xo"
elif [[ $(hostname) = joule* ]]; then
     h="joule"
# Add more cases here.
else
     h=$(hostname --short)
fi
echo h = $h
ConfigAndStartAos () {
     AosContextDir=$PWD
     cd $WorkingDirectory
     if test -f Configuration.$h.XML
     then
          echo Copying Configuration.$h.XML to Configuration.XML.
          /bin/cp Configuration.$h.XML Configuration.XML
          if test -f Oberon.$h.Text
          then
               echo Copying Oberon.$h.Text to Oberon.Text.
               /bin/cp Oberon.$h.Text Oberon.Text
               /bin/rm --force --verbose AOS*.Log
               /bin/rm --force --verbose Trap*.txt
               /bin/rm --force --verbose .tmp.*
#             sudo mount --bind /usr/aos .aoshome
               /usr/bin/aos
#             sudo umount .aoshome
          else
               echo Oberon.$h.Text not present in $WorkingDirectory.  Aborting.
          fi
     else
          echo Configuration.$h.XML not present in $WorkingDirectory.  Aborting.
     fi
     }

if test -b $WorkingVolume
then
    if mountpoint -q $MountPoint
    then
        echo Working volume is mounted.  e2fsck not required.
        ConfigAndStartAos
    else
        echo Working volume is not mounted.  perform e2fsck.
        if /sbin/e2fsck -p $WorkingVolume
        then
            echo Filesystem in $WorkingVolume passed e2fsck.
            mount -v $WorkingVolume
            ConfigAndStartAos
        else
            echo e2fsck found a problem in $WorkingVolume and attempted repair.  Try again.
        fi
    fi
else
     echo $WorkingVolume containing working files not connected.  Aborting.
fi


This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.