exclude 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/bash
  2. #this script adds or removes an article from excluded entries list
  3. #you can use this feature, for example, if you wrote custom HTML in some articles and you don't want nci to destroy your changes.
  4. if [ ! -d "entries" ] || [ ! -d "public_html" ]; then
  5. echo "You haven't initialized nci system yet... Please use \"./init\" before posting a new entry."
  6. exit 1
  7. fi
  8. #check if the excluded entries file exists
  9. if [ ! -f "exclude.conf" ]; then
  10. echo "The exclude.conf file doesn't exists... please create it or run the \"./init\" command again (it won't affect your existing files)"
  11. fi
  12. #check if no id entered.
  13. if [ -z "$1" ]; then
  14. echo "Error: Please type the ID of the entry you want to exclude/include from being updated when you run \"./refresh\" (Usage: \"./exclude <entry_id>\")."
  15. exit 1
  16. fi
  17. if [ "$1" == "-c" ]; then
  18. truncate -s 0 "exclude.conf"
  19. echo "All excluded entries were removed!"
  20. exit 1
  21. fi
  22. if [ "$1" == "-a" ]; then
  23. entry_count=$(ls "entries/" | wc -l)
  24. ((entry_count-=1))
  25. for (( i=1; i<=$entry_count; i++))
  26. do
  27. echo $i >> "exclude.conf"
  28. done
  29. echo "All entries are now excluded!"
  30. exit 1
  31. fi
  32. lnum=0
  33. while read -r line; do
  34. ((lnum+=1))
  35. if [ "$1" == "$line" ]; then
  36. echo "Entry removed from the list of excluded entries. Now it'll be updated the next time you run the \"./refresh\" command."
  37. sed -i $lnum"d" "exclude.conf"
  38. exit 1
  39. fi
  40. done < "exclude.conf"
  41. echo "$1" >> "exclude.conf"
  42. echo "Entry added to the list of excluded entries. Now it won't be updated when you run the \"./refresh\" command, so you need to modify it manually from the HTML source."
  43. echo "Protip: You can remove an entry from the list of excludes by running the \"./exclude $1\" command again."