From 0fcf52265bbc12a92370dbfeb53bb7d449e6942e Mon Sep 17 00:00:00 2001 From: "mauro.giachero" Date: Fri, 23 Jan 2009 16:11:57 +0000 Subject: [PATCH] Validation: revert r365 and do it properly. The implementation of r365 has some major problem, deleting the permanent log being the most user-visible. Undo that crud and do the checks in a proper way. Signed-off-by: Mauro Giachero --- src/usr/bin/sbopkg | 80 +++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/src/usr/bin/sbopkg b/src/usr/bin/sbopkg index 94f6474..d7b8b0c 100755 --- a/src/usr/bin/sbopkg +++ b/src/usr/bin/sbopkg @@ -52,18 +52,17 @@ crunch() { # the inspiration for this and the next function comes from the crunch() # in installpkg. Both take one argument - the first reduces runs of spaces # to one and the second does that and reformats to 78 columns. - echo "$@" | tr -s ' ' + echo -e "$@" | tr -s ' ' } crunch_fmt() { - echo "$@" | tr -s ' ' | fmt -78 + echo -e "$@" | tr -s ' ' | fmt -78 } config_check () { # Check if config file is there and if so check that it has all # needed variables with any value, and set them. - local MISSING CANTCREATE - local VARNAME VARDIR VARVALUE + local MISSING VAR if [ ! -e $SBOPKG_CONF ]; then echo "$SCRIPT: No $SBOPKG_CONF file was found." @@ -94,41 +93,6 @@ config_check () { echo "Please correct this error and run $SCRIPT again." exit 1 fi - - # Verify that the files/folders specified exist or can be created - # This is done only if the user is root, since there's little a - # non-root user can do with these anyway. - if has_root; then - for VAR in SRCDIR/ TMP/ OUTPUT/ LOGFILE; do - eval VARVALUE=\$$VAR - VARNAME=${VARVALUE##*/} - if [[ -z "$VARNAME" ]]; then - VARNAME="sbopkg-testfile" - fi - VARDIR=$(echo $VARVALUE |rev |cut -d/ -f2- |rev) - if [[ ! -e $VARDIR ]]; then - mkdir -p $VARDIR || CANTCREATE+="$VARVALUE " - fi - if [[ -d $VARDIR ]]; then - (touch $VARDIR/$VARNAME && rm -f $VARDIR/$VARNAME) \ - || CANTCREATE+="$VARVALUE " - fi - done - fi - if [ "$CANTCREATE" ]; then - echo - echo "ERROR" - echo "$SCRIPT: Can't create the file(s)/folder(s):" - echo "$CANTCREATE" - echo - echo "Make sure you have enough privileges to create and" - echo "access these, or change the problematic settings in" - echo "the sbopkg.conf file." - echo "See the sbopkg.conf(5) man page for more details." - echo - echo "Please correct this error and run $SCRIPT again." - exit 1 - fi if [ -e $HOME/.sbopkg.conf ]; then . $HOME/.sbopkg.conf fi @@ -138,22 +102,48 @@ config_check () { ck_dir() { # This function displays the directory-creation message and then creates # the missing directory. + local ERROR=0 + + # Try to create the specified folder if [ ! -d "$1" ]; then echo crunch_fmt "$2" echo read -n1 -sep "Press any key to continue or Ctrl-C to exit." - # One of these days, I'll see about implementing a cleaner way of - # exiting with a nice error message if the user does not have - # sufficient permissions to create these directories. For now, - # the || exit 1 will suffice. - mkdir -p $1 || exit 1 + mkdir -p $1 || ERROR=1 fi + + # Try to create a file in the specified folder + if [[ $ERROR -eq 0 ]]; then + (touch $1/sbopkg-testfile && rm -f $1/sbopkg-testfile) || ERROR=2 + fi + + case $ERROR in + 1) crunch_fmt "\\n\\nWARNING:\ + \\n$SCRIPT: Unable to create $1.\ + \\n\\nMake sure you have enough privileges to create that\ + directory, or specify a different location in sbopkg.conf.\ + \\nSee the sbopkg.conf(5) man page for more details.\ + \\n\\nHit ENTER to continue anyway, CTRL-C to abort." + read JUNK + ;; + 2) crunch_fmt "\\n\\nWARNING:\ + \\n$SCRIPT: Unable to create files in $1.\ + \\n\\nMake sure you have enough privileges to write in\ + that directory, or specify a different location in\ + sbopkg.conf.\ + \\nSee the sbopkg.conf(5) man page for more details.\ + \\n\\nHit ENTER to continue anyway, CTRL-C to abort." + read JUNK + ;; + esac } directory_checks () { # Check and make sure certain sbopkg-related directories exist. # If not, create them. + local LOGDIR=$(dirname $LOGFILE) + ck_dir "$LOCALREPO/$SLACKVER" \ "Creating local repository directory $LOCALREPO/$SLACKVER for the \ rsync mirror." @@ -163,6 +153,8 @@ directory_checks () { "Creating local TMP directory $TMP." ck_dir "$OUTPUT" \ "Creating local package output directory $OUTPUT." + ck_dir "$LOGDIR" \ + "Creating log directory $LOGDIR." # FIXME: This can probably be removed, but leave as-is for a bit. #cd $LOCALREPO