updatem.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # User check imo
  3. if [[ $EUID -eq 0 ]]; then
  4. echo "Do not run this script as root fam"
  5. exit 1
  6. fi
  7. # Need at least `diff` and `find` lol (should be there, but let's just check anyways)
  8. if [[ -z $(which diff) ]]; then
  9. echo "This script requires the utility 'diff'"
  10. exit 1
  11. fi
  12. if [[ -z $(which find) ]]; then
  13. echo "This script requires the utility 'find'"
  14. exit 1
  15. fi
  16. # Cuz om lazy =]]]
  17. relpath=$(dirname "${BASH_SOURCE[0]}")
  18. if [ "$relpath" != "." ]; then
  19. echo "Please run this script directly from the skrip directory yo (./updatem.sh)"
  20. exit 1
  21. fi
  22. cd ..
  23. if [[ ! -f HALP.md ]]; then
  24. echo "This script doesn't seem to be inside the module repository's root dir"
  25. exit 1
  26. fi
  27. # Check if we got a path one way or anotha
  28. if [[ -z "$1" ]] && [[ -z "$UNREALPATH" ]]; then
  29. echo "Usage: $0 <UnrealIRCd source directory>"
  30. echo "You can also export a variable \$UNREALPATH pointing to that same dir"
  31. exit 1
  32. fi
  33. # Initialise this shit to empty, just in case
  34. upath=
  35. # Check passed argument's sanity
  36. if [[ ! -z "$1" ]]; then
  37. if [[ ! -e "$1" ]]; then
  38. echo "Directory doesn't exist"
  39. exit 1
  40. elif [[ ! -d "$1" ]]; then
  41. echo "Seems to be a file and not a directory"
  42. exit 1
  43. elif [[ ! -d "$1/src/modules/third" ]]; then
  44. echo "Doesn't seem to be an UnrealIRCd source tree"
  45. exit 1
  46. elif [[ ! -w "$1" ]]; then
  47. echo "Directory is not writable"
  48. exit 1
  49. fi
  50. # Set variable from earlier to something nao
  51. upath="$1"
  52. # We gottem $UNREALPATH, checkem
  53. elif [[ ! -z "$UNREALPATH" ]]; then
  54. if [[ ! -e "$UNREALPATH" ]]; then
  55. echo "Directory doesn't exist: $UNREALPATH"
  56. exit 1
  57. elif [[ ! -d "$UNREALPATH" ]]; then
  58. echo "Seems to be a file and not a directory: $UNREALPATH"
  59. exit 1
  60. elif [[ ! -d "$UNREALPATH/src/modules/third" ]]; then
  61. echo "Doesn't seem to be an UnrealIRCd source tree: $UNREALPATH"
  62. exit 1
  63. elif [[ ! -w "$UNREALPATH" ]]; then
  64. echo "Directory is not writable: $UNREALPATH"
  65. exit 1
  66. fi
  67. # Shit out UNREALPATH for good measure y0
  68. echo "Found UNREALPATH: $UNREALPATH"
  69. upath="$UNREALPATH"
  70. # Fallthrough, shouldn't happen
  71. else
  72. echo "Something went wrong lel"
  73. exit 2
  74. fi
  75. # Get current dir (repo root dir fam)
  76. moddir=$(pwd)
  77. # Need to re-make etc?
  78. makem=0
  79. # Go to third party mod dir and checkem .c fiels imo tbh
  80. cd "$upath/src/modules/third"
  81. for muhmod in *.c; do
  82. echo "Found third-party mod '$muhmod' -- checkin' if it's mine..."
  83. # Attempt to find the .c file in the mod repo
  84. wegottem=$(find "$moddir"/* -type f -iname "$muhmod")
  85. # Not found, prolly someone else's
  86. if [[ -z "$wegottem" ]]; then
  87. echo -e "Doesn't look like it, skipping\n"
  88. continue
  89. fi
  90. # Es mien, but does it need an update?
  91. echo -n "Looks like it, requires update? "
  92. # If empty diff, means no change =]
  93. if [[ -z $(diff "$wegottem" "$muhmod") ]]; then
  94. echo -e "No\n"
  95. continue;
  96. fi
  97. # Clean up old .so file to make sure we recompile that shit (lazily)
  98. echo "Yes, (attempting to) removing old .so file first"
  99. rm -vf "${muhmod%.*}.so"
  100. # Flip makem flag
  101. makem=1
  102. # Copy that shit and add an empty line f0' padding
  103. cp -v "$wegottem" "$upath/src/modules/third/"
  104. echo ""
  105. done
  106. # Need to re-make?
  107. if [[ $makem -eq 1 ]]; then
  108. echo "We updated at least one module, running make && make install"
  109. # Go into the source root dir and run em
  110. cd "$upath"
  111. (make && make install && echo -e "\n============\nAll good, now rehash the IRCd") || (echo -e "\n============\nSomething went wrong, review the make output and fix/report any errors, then rerun make && make install")
  112. # Na we GOOD
  113. else
  114. echo "No updates necessary at all =]"
  115. fi