del 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. if [ ! -d "entries" ]; then
  3. echo "You haven't initialized nci system yet... Please use \"./init\" before deleting entries."
  4. exit 1
  5. fi
  6. #check if no id entered
  7. if [ -z "$1" ]; then
  8. echo "Error: Please type the ID of the entry you want to delete (Command usage: ./del <entry_id>)."
  9. exit 1
  10. fi
  11. if [ ! -f "entries/entry_$1" ]; then
  12. echo "Error: That entry doesn't exist."
  13. exit 1
  14. else
  15. contents=$(cat "entries/entry_$1")
  16. if [ "$contents" == "[DELETED]" ]; then
  17. echo "Error: Already deleted."
  18. exit 1
  19. fi
  20. fi
  21. #confirmation for entry deletion
  22. yn=""
  23. while true; do
  24. echo "IMPORTANT: When you delete an entry, you are just removing it from HTML and RSS files, files saved in the \"entries/\" folder won't and mustn't be deleted!"
  25. echo "Are you sure you want to delete entry no. $1? There's NO UNDO for this action! (y/n)"
  26. read -r yn
  27. case $yn in
  28. [Yy]* ) truncate -s 0 "entries/entry_$1"
  29. echo "[DELETED]" >> "entries/entry_$1"
  30. echo "Entry no. $1 successfully deleted. REMEMBER: Use \"./refresh\" to make the changes take effect on your blog."
  31. exit 1
  32. ;;
  33. [Nn]* ) echo "Deletion cancelled. Entry no. $1 is safe for now."
  34. exit 1
  35. ;;
  36. * ) echo "Error: Please answer just y/n.";;
  37. esac
  38. done