fixuuid.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/bash
  2. #
  3. # This script regenerates the asset UUIDs for all LSL scripts in an IAR file.
  4. # This is done so that when a script has been updated inside the IAR rather than in world...
  5. # ...then reimported into an SL grid that had it before, or using a viewer that already has it in the cache...
  6. # ...we can be sure that the new version will be used, not the old one.
  7. #
  8. # These UUIDs are generated based on the md5 hash of the contents of the script.
  9. # This means that given two identical scripts with different UUIDs,
  10. # ...it will have the side effect of combining them into a single script.
  11. #
  12. # It is intended to be used as follows on an untarred IAR, like the one in sloodle_opensim_iar:
  13. # cd sloodle_opensim_iar/iar
  14. # find . -name '*.lsl' -exec ../../sloodle_development_tools/opensim_sync/fixuuid.sh {} \;
  15. #
  16. OLDASSET=$1
  17. if [ ! -f "$OLDASSET" ]
  18. then
  19. echo "Asset '$OLDASSET' not found"
  20. exit 1;
  21. fi
  22. #./assets/432e3970-5331-b90e-b157-08e3d3fa0ef1_script.lsl
  23. HASH=`md5sum $OLDASSET`
  24. NEWUUID="${HASH:0:8}-${HASH:8:4}-${HASH:12:4}-${HASH:16:4}-${HASH:20:12}"
  25. OLDSCRIPT=`echo $OLDASSET | awk -F'/' '{print $3}'`
  26. OLDUUID=`echo $OLDSCRIPT | awk -F'_' '{print $1}'`
  27. if [ "$NEWUUID" = "" ]
  28. then
  29. echo "Could not make NEWUUID for file '$OLDASSET'"
  30. exit 2
  31. fi
  32. if [ "$OLDUUID" = "" ]
  33. then
  34. echo "Could not make OLDUUID"
  35. exit 2
  36. fi
  37. if [ "$NEWUUID" != "$OLDUUID" ]
  38. then
  39. NEWASSET="./assets/${NEWUUID}_script.lsl"
  40. echo "Renaming old asset $OLDASSET to $NEWASSET"
  41. mv $OLDASSET $NEWASSET
  42. find . -name '*.xml' -exec sed -i "s/$OLDUUID/$NEWUUID/g" '{}' \;
  43. fi