Points :
Due : Thursday, 8 Dec. 2017
Write a bash script that will allow user to restore files stored in the Backup directory by the Backup function.
You may want to create a $HOME/bin directory, make sure it is only accessible by you, and append ~/bin to the PATH variable in .bash_profile file.
PATH="${PATH}":~/bin
You will be creating a shell script called Restore in your bin directory. Remember to make it executable.
Restore will have several modes of execution, depending on how it is invoked.
Included in the list, possibly at the end, should be the choice Quit.
User may select the file to restore or he/she may terminate the Restore by choosing to quit.
Review the bash select loop.
If a file is chosen, Restore will restore the file in the current working directory, minus the timestamp extension. Leave the backed-up copy in $HOME/Backup directory.
Hint : use sed to trim off the extension. Describe the timestamp extension as a period followed by an 11 digit number followed by the end of the line. Substitute this matched string with null.
If done right, you should be able to restore non-timestamped files in Backup without removing their final extension. (in most cases).
Restore should then again list the contents of Backup with the Quit option and allow the user to choose again.
Because some of these backups may be symbolic links, use the -P option to restore. If you don't, the system will attempt to restore the file that is linked to. If the link was a relative path, it may be invalid.
Still offer the Quit option, so that the user may cancel the Restore rather than selecting a file.
Because this is file specific, once the file is restored or the operation is canceled, the program should terminate.
If your program is invoked by the name Purge, then code it so it performs the same steps as the Restore with no arguments.
Rather than restoring the selected file in the current directory, delete it from the Backup directory.
If Restore is invoked with a -p option, have it perform the same as if it was invoked as Purge.
Note that this means that the 1st argument after the command is a -p, not a file name. Consider setting a flag and using shift so that if it there was also a filename provided, it becomes the 1st argument of the command line.
******
If Purge is invoked with a -a option, it will clear the ~/Backup folder of all files.
If Purge is invoked with a -a option and a filename, purge ~/Backup of all backup copies of that file, whether they are actual files or symbolic links.