Oberon/A2/myaos

From Wikibooks, open books for an open world
< Oberon‎ | A2
Jump to navigation Jump to search
#!/bin/bash 
# A script to start UnixAos with a working directory, possibly in a removable
# flash store. 
# Aos with the flash store on various machines is accomodated 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 
#   assigned by a udev rule. 
#   https://wiki.archlinux.org/index.php/udev#Writing_udev_rules. 
#   In this instance the name is GRNSDHC41 or 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 and 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/GRNSDHC41 /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 
#   My preference to reformat the flash card to ext2. 
# 
# WorkingVolume=/dev/BLKSDHC41 
WorkingVolume=/dev/GRNSDHC41 
echo WorkingVolume is $WorkingVolume. 
WorkingDirectory=/home/$USER/MY
echo WorkingDirectory=$WorkingDirectory.
MountPoint=/home/$USER/MY 
echo MountPoint is $MountPoint.
#Host=$(hostname --short) 
#echo Host is $Host. 
ConfigAndStartAos () { 
     AosContextDir=$PWD
     cd $WorkingDirectory 
     if test -f Configuration.$(hostname --short).XML ; then 
          echo Copying Configuration.$(hostname --short).XML to Configuration.XML. 
          /bin/cp Configuration.$(hostname --short).XML Configuration.XML 
          if test -f Oberon.$(hostname --short).Text ; then 
               echo Copying Oberon.$(hostname --short).Text to Oberon.Text. 
               /bin/cp Oberon.$(hostname --short).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.$(hostname --short).Text not present in $WorkingDirectory.  Aborting. 
          fi 
     else 
          echo Configuration.$(hostname --short).XML not present in $WorkingDirectory.  Aborting. 
     fi
     }

if test -b $WorkingVolume ; then 
     if mountpoint -q $MountPoint ; then
          # Working volume is mounted; e2fsck not required. 
          ConfigAndStartAos 
     else 
          # 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