Lab 6 (online) - pinfo 5 points (plus possible 5 points of extra credit)
Note: Lab6 finshes implementing pinfo, which is begun in lab5 as xpinfo. Refer to lab5 for more info.
In Lab 6 we will finish the implementation of pinfo, starting with xpinfo, which we created in lab5, by adding a few loops. Here are the features you must add to pinfo:
If the .project and/or the .plan file don't exist, you will allow the user to type it in. The .project file is a single line, so it is easy to create. You can use a while read loop or just use cat to allow the user to create the .plan file if it is missing. If either file cannot be created, output a message and exit. When the user is typing in the .plan file you must tell them how to indicate when they are finished.
When you ask the user a yes or no question, you will use a loop to force them to input a valid response. (If you started lab5 with the code I gave you for xpinfo, just add a loop to the askyn function.)
You will add a loop to ensure that the title the user enters is unique (i.e, that no other user uses that title already). The comparison should be case-insensitive. If another user already has that title, inform the user and ask them to enter it again. (Look at the file /etc/passwd's fifth field for where the title is stored.
The information on the extra credit part is below.
Here is sample output from a version of pinfo. In this example, the user's home directory was searchable (executable) for everyone, his .plan file did not exist, and the .project file had the incorrect permissions. He also had a problem getting a unique title (the user-entered text is bold-italic.)
Welcome to pinfo - Set your finger personal information
pinfo:ERROR: The ~/.plan file does not exist.
Please type in the ~/.plan now. Type control-D to finish
To teach what I know of Unix and Linux and
learn the rest with my students.
< --- control-D was typed here
Your ~/.project file must allow r access for all users.
Do you want me to change its permissions?(y/n): yes
Please enter y or n
Do you want me to change its permissions?(y/n): y
Enter your title: Lord of Peanut Butter
Sorry, that title is already in-use. Try another.
Enter your title: Unix/Linux Instructor
Enter your location: L413
For the extra credit you must implement the following function
makereadable will check that file xxx (its single argument) is world-readable. If not, it will ask the user's permission to make xxx readable. If the user does not allow the permissions to be changed OR the file's permissions cannot be changed (chmod fails), makereadable returns with a failure status. If xxx already is world-readable or makereadable successfully makes it world-readable, makereadable returns with a success status. You may want to make use of askyn in your function makereadable.
You should call your function twice, once for .project and once for .plan. Of course you must test makereadable's exit status when it returns and exit if it failed.
For full credit makereadable must be free of side-effects (not use global variables) and have a few lines of documentation.
If you do the extra credit, you must indicate you did the extra credit as a comment at the beginning of your shell script like this:
# EXTRA CREDIT
Submit a copy of your shell script online for grading by pasting it into the assignment submission box. Then run the transfer program on hills to place a machine-readable copy of your shell script (which must be named pinfo ) in your share directory as in all assignments like this:
Submit a single copy of pinfo whether you did the extra credit or not. If you do the extra credit, make sure you indicate that in the beginning of your shell script as indicated above.
This document was produced with free software: OpenOffice.org on linux.