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.

41 lines
795 B

  1. #!/bin/bash
  2. ENTRY=$1
  3. PROPERTY=$2
  4. # Complain and exit if we weren't given a path and a property:
  5. if [[ ! $ENTRY || ! $PROPERTY ]]; then
  6. echo "usage: addprop <path> <property>"
  7. exit 64
  8. fi
  9. if [ ! -e $ENTRY ]; then
  10. echo "$ENTRY not found"
  11. exit 66
  12. fi
  13. echo "marking $ENTRY with $PROPERTY"
  14. # If the target is a plain file instead of a directory, make it into
  15. # a directory and move the content into $ENTRY/index:
  16. if [ -f $ENTRY ]; then
  17. echo "making $ENTRY into a directory, moving content to"
  18. echo " $ENTRY/index"
  19. # Get a safe temporary file:
  20. TEMPFILE=`mktemp`
  21. mv $ENTRY $TEMPFILE
  22. mkdir $ENTRY
  23. mv $TEMPFILE $ENTRY/index
  24. fi
  25. if [ -d $ENTRY ]; then
  26. touch $ENTRY/$PROPERTY
  27. else
  28. echo "something broke - why isn't $ENTRY a directory?"
  29. file $ENTRY
  30. fi
  31. echo kthxbai
  32. exit 0