A book about the command line for humans.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.0 KiB

  1. #!/bin/bash
  2. # $1 is the first parameter to our script
  3. POEM=$1
  4. # Complain and exit if we weren't given a path:
  5. if [ ! $POEM ]; then
  6. echo 'usage: markpoem <path>'
  7. # Confusingly, an exit status of 0 means to the shell that everything went
  8. # fine, while any other number means that something went wrong.
  9. exit 64
  10. fi
  11. if [ ! -e $POEM ]; then
  12. echo "$POEM not found"
  13. exit 66
  14. fi
  15. echo "marking $POEM an ok poem"
  16. POEM_BASENAME=$(basename $POEM)
  17. # If the target is a plain file instead of a directory, make it into
  18. # a directory and move the content into $POEM/index:
  19. if [ -f $POEM ]; then
  20. echo "making $POEM into a directory, moving content to"
  21. echo " $POEM/index"
  22. TEMPFILE="/tmp/$POEM_BASENAME.$(date +%s.%N)"
  23. mv $POEM $TEMPFILE
  24. mkdir $POEM
  25. mv $TEMPFILE $POEM/index
  26. fi
  27. if [ -d $POEM ]; then
  28. # touch(1) will either create the file or update its timestamp:
  29. touch $POEM/meta-ok-poem
  30. else
  31. echo "something broke - why isn't $POEM a directory?"
  32. file $POEM
  33. fi
  34. # Signal that all is copacetic:
  35. echo kthxbai
  36. exit 0