Create a trashbag facility
Introduction
The purpose of this exercise is to create one script file which will act similar to the trashcan facility on a linux/windows system. Actually, it is a trashbag (i.e. it gets thrown out with the trash!). This will be created on your Ubuntu system.
Note: This lab is three parts - trashbag, test trashbag with instructor test suite, test trashbag with student test suite. This is a three week lab with each due a week later; see schedule.
Note: due to the implementation of a new version of the OS (10.04), points in the lab may be added/changed/deleted.
Trash Script
Create a script file which will have the name trash and will be kept in your $HOME/bin directory. Ensure that this directory is in your path for you must be able to run the script from anywhere in the system.
This part is due at the end of the first week.
The syntax for usage of trash is
trash - display this list
trash -e - throw out the trashbag
trash file_name1 [file_name2] - delete the named files
No parameter
The help list above is displayed on the screen
-e parameter
Verify with the user that s/he wants to delete the directory trashbag and its contents.
If the answer is no, issue a message that the directory is not deleted.
If the answer is yes, delete the directory trashbag and its contents. Then issue a message that the directory has been deleted.
file_name parameter
Determine if the directory trashbag exists. If it does not, then create it in the $HOME/bin directory.
Move each file file_name into the trashbag directory. The minimum requirement is that the script works with one file.
Note that the file may be a file, a non-existent file, a directory, a directory with a file, …
Issue a message that the file has been moved to the trashbag.
test_trash Script
Create a script called test_trash or similar that contains a suite of tests to confirm the operation of the script trash .
You will need to create a set/directory of test files/directories that can be used to run the test suite.
As a bare minimum you must ensure that the programme works with each syntax in your home directory and in sub-directories.
The sample test_trash gives you three test cases. It is NOT to be modified. Your trashbag script will be modified to work with it and the data. A copy of the results (i.e. redirected to a file) is the report for the second week.
The student-created documented test-script, with four additional test cases, is the basis for the report for the third week. In addition to the test-script, a copy of the results (i.e. redirected to a file) is to be included with the test-script in the report.
Report
Part I - The trash script must be properly documented internally and be accompanied by external documentation. The external documentation is of your choice - UML diagrammes, Bon diagrammes, state charts, flowcharts, …(For flowcharts,see Sobell, Ubuntu, chap. 11; 2nd Ed - chap.27)
Part II - As the only requirement here is a copy of the results; your trash script must be designed to properly interface with the test_trash script. (Remember, the test_trash script cannot be modified). No external documentation is required.
Part III - The requirement is the student-created test-script. The test-script must be internally documented. (Think about how much documentation it REALLY needs). No external documentation is required. A copy of the results of the four tests are required.
아래 이코드를 이용하는 것이 숙제 입니다
#!/bin/bash
#This is a sample of test_trash script to do
#the test suite for the trash script
Kenn Baker October 26, 2004
PASSED="\033[0;32;49mPASSED \033[0;39m "
FAILED="\033[0;31;49mFAILED \033[0m "
clear
echo "Test script for the trash script"
echo "--------------------------------"
echo Display the help screen: trash
trash
echo -en "Help screen is acceptable? (y/n)"
read keyxin
if [ "$keyxin" = "Y" -o "$keyxin" = "y" ]
then
echo -e "Help screen acceptable : $PASSED"
else
echo -e "Help screen acceptable : $FAILED"
fi
#Copy the test directory for tests
if [ ! -d copydir ]
then
mkdir copydir
fi
cp -r testdir/* copydir
echo
echo "Trash file with messages (no trashbag)"
trash -e
trash copydir/file1
if [ ! -f copydir/file1 -a -f ~/bin/trashbag/file1 ]
then
echo -e "Trash file with messages : $PASSED"
else
echo -e "Trash file with messages : $FAILED"
fi
echo
#echo "Trash file without messages (yes trashbag)"
trash copydir/file2 > /dev/null
if [ ! -f copydir/file2 -a -f ~/bin/trashbag/file2 ]
then
echo -e "Trash file without messages : $PASSED"
else
echo -e "Trash file without messages : $FAILED"
fi
Clean up
echo
if [ -d copydir ]
then
rm -r copydir
fi
echo Done testing