No Description

ctl 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. #!/usr/bin/env bash
  2. NAME="openmedialibrary"
  3. PID="/tmp/$NAME.$USER.pid"
  4. cd "`dirname "$0"`"
  5. if [ -e oml ]; then
  6. cd ..
  7. fi
  8. BASE=`pwd`
  9. SYSTEM=`uname -s`
  10. PLATFORM=`uname -m`
  11. GIT_BASE=https://code.0x2620.org/0x2620
  12. PYTHON=python3
  13. DATA="$BASE/data"
  14. if [ ! -e "$DATA" ] && [ -e "$BASE/config" ]; then
  15. if [ "$1" == "stop" ] || [ "$1" == "restart" ]; then
  16. DATA="$BASE/config"
  17. else
  18. mv "$BASE/config" "$DATA"
  19. fi
  20. else
  21. if [ ! -e "$BASE/data/release.json" ] && [ -e "$BASE/config/release.json" ]; then
  22. mv "$BASE/config/release.json" "$BASE/data/release.json"
  23. fi
  24. fi
  25. if [ ! -e "$PID" ]; then
  26. if [ -e "$DATA/tor/hostname" ]; then
  27. onion=$(cat "$DATA/tor/hostname")
  28. id=${onion/.onion/}
  29. PID="/tmp/$NAME.$USER.$id.pid"
  30. fi
  31. fi
  32. if [ ! -e "$PID" ]; then
  33. PID="$DATA/$NAME.pid"
  34. fi
  35. PLATFORM_PYTHON=3.4
  36. SHARED_PYTHON=3.4
  37. if [ -e "$BASE/platform_local" ]; then
  38. export PLATFORM_ENV="$BASE/platform_local"
  39. else
  40. if [ $SYSTEM == "Linux" ]; then
  41. if [ $PLATFORM == "x86_64" ]; then
  42. ARCH=64
  43. PLATFORM_PYTHON=3.7
  44. else
  45. ARCH=32
  46. fi
  47. if [ $PLATFORM == "aarch64" ]; then
  48. ARCH="_aarch64"
  49. PLATFORM_PYTHON=3.5
  50. fi
  51. if [ $PLATFORM == "armv7l" ]; then
  52. ARCH="_armv7l"
  53. fi
  54. PLATFORM="linux$ARCH"
  55. fi
  56. if [ $SYSTEM == "Darwin" ]; then
  57. PLATFORM="darwin64"
  58. PLATFORM_PYTHON=3.7
  59. fi
  60. export PLATFORM_ENV="$BASE/platform_${PLATFORM}"
  61. fi
  62. PATH="$PLATFORM_ENV/bin:$PATH"
  63. SHARED_ENV="$BASE/platform/Shared"
  64. export SHARED_ENV
  65. PATH="$SHARED_ENV/bin:$PATH"
  66. export PATH
  67. if [ $SYSTEM == "Darwin" ]; then
  68. export DYLD_FALLBACK_LIBRARY_PATH="$PLATFORM_ENV/lib"
  69. export SSL_CERT_FILE="$SHARED_ENV/etc/openssl/cert.pem"
  70. export SSL_CERT_DIR="$SHARED_ENV/etc/openssl/certs"
  71. fi
  72. PYTHONPATH="${PLATFORM_ENV}/lib/python${PLATFORM_PYTHON}/site-packages"
  73. PYTHONPATH="${PYTHONPATH}:${SHARED_ENV}/lib/python${SHARED_PYTHON}/site-packages"
  74. PYTHONPATH="${PYTHONPATH}:${BASE}/${NAME}"
  75. export PYTHONPATH
  76. oxCACHE="$DATA/ox"
  77. export oxCACHE
  78. #must be called to update commands in $PATH
  79. hash -r 2>/dev/null
  80. # allow more open files
  81. ulimit -S -n 2048
  82. function update_gitbase() {
  83. if [ -e "${BASE}/openmedialibrary/.git/config" ]; then
  84. GIT_BASE=`grep origin .git/config -A 1 | grep url | cut -f2 -d=`
  85. fi
  86. }
  87. if [ "$1" == "start" ]; then
  88. cd "$BASE/$NAME"
  89. if [ -e "$PID" ]; then
  90. if ps -p `cat "$PID"` > /dev/null; then
  91. echo openmedialibrary already running
  92. exit 1
  93. fi
  94. fi
  95. $PYTHON oml server "$PID"
  96. exit $?
  97. fi
  98. if [ "$1" == "debug" ]; then
  99. cd "$BASE/$NAME"
  100. if [ -e "$PID" ]; then
  101. if ps -p `cat "$PID"` > /dev/null; then
  102. echo openmedialibrary already running
  103. exit 1
  104. fi
  105. fi
  106. shift
  107. $PYTHON oml server debug "$PID"
  108. exit $?
  109. fi
  110. if [ "$1" == "stop" ]; then
  111. if [ -e "$PID" ]; then
  112. _PID=`cat "$PID"`
  113. kill $_PID
  114. waited=0
  115. while ps -p $_PID > /dev/null
  116. do
  117. sleep 1
  118. waited=$(($waited+1))
  119. if [ $waited -gt 60 ]; then
  120. kill -9 $_PID
  121. sleep 1
  122. fi
  123. done
  124. test -e "$PID" && rm "$PID"
  125. fi
  126. exit $?
  127. fi
  128. if [ "$1" == "restart" ]; then
  129. if [ -e "$PID" ]; then
  130. "$0" stop
  131. "$0" start
  132. exit $?
  133. else
  134. "$0" start
  135. exit $?
  136. fi
  137. fi
  138. if [ "$1" == "open" ]; then
  139. if [ $SYSTEM == "Darwin" ]; then
  140. open "/Applications/Open Media Library.app"
  141. fi
  142. if [ $SYSTEM == "Linux" ]; then
  143. if [ -e "$PID" ]; then
  144. if ps -p `cat "$PID"` > /dev/null; then
  145. if [ -e /usr/bin/gio ]; then
  146. gio open "file://${BASE}/openmedialibrary/static/html/load.html"
  147. else
  148. xdg-open "file://${BASE}/openmedialibrary/static/html/load.html"
  149. fi
  150. else
  151. $PYTHON "${NAME}/oml/gtkstatus.py" $@
  152. exit $?
  153. fi
  154. else
  155. $PYTHON "$NAME/oml/gtkstatus.py" $@
  156. exit $?
  157. fi
  158. fi
  159. exit 0
  160. fi
  161. if [ "$1" == "autostart" ]; then
  162. if [ $SYSTEM == "Darwin" ]; then
  163. open "/Applications/Open Media Library.app" --args --autostart
  164. fi
  165. if [ $SYSTEM == "Linux" ]; then
  166. if [ ! -e "$PID" ]; then
  167. $PYTHON "$NAME/oml/gtkstatus.py" --autostart
  168. exit $?
  169. fi
  170. fi
  171. exit 0
  172. fi
  173. if [ "$1" == "ui" ]; then
  174. shift
  175. $PYTHON "$NAME/oml/ui.py" $@
  176. exit $?
  177. fi
  178. if [ "$1" == "init" ]; then
  179. update_gitbase
  180. if [ ! -e "${BASE}/platform" ]; then
  181. git clone --depth 1 $GIT_BASE/openmedialibrary_platform.git "${BASE}/platform"
  182. fi
  183. if [ ! -e "${PLATFORM_ENV}" ]; then
  184. git clone --depth 1 $GIT_BASE/openmedialibrary_platform_${PLATFORM}.git "${PLATFORM_ENV}"
  185. fi
  186. cd "${BASE}"
  187. if [ ! -e "${BASE}/ctl" ]; then
  188. ln -s openmedialibrary/ctl
  189. fi
  190. "${BASE}/ctl" update_static
  191. exit
  192. fi
  193. if [ "$1" == "update" ]; then
  194. cd "$BASE/$NAME"
  195. if [ ! -e "${PLATFORM_ENV}" ]; then
  196. update_gitbase
  197. git clone --depth 1 $GIT_BASE/openmedialibrary_platform_${PLATFORM}.git "${PLATFORM_ENV}"
  198. fi
  199. if [ -d "$BASE/$NAME/.git" ]; then
  200. OLD=`"$0" version`
  201. cd "$BASE/platform"
  202. echo Update shared platform...
  203. git pull
  204. cd "${PLATFORM_ENV}"
  205. echo Update platform...
  206. git pull
  207. echo Update $NAME...
  208. cd "$BASE/$NAME"
  209. find . -name "*.pyc" -exec rm "{}" \;
  210. git pull
  211. "$0" update_static > /dev/null
  212. NEW=`"$0" version`
  213. "$0" postupdate -o $OLD -n $NEW
  214. else
  215. $PYTHON oml update
  216. fi
  217. exit $?
  218. fi
  219. if [ "$1" == "python" ]; then
  220. cd "$BASE/$NAME"
  221. shift
  222. $PYTHON $@
  223. exit $?
  224. fi
  225. cd "$BASE/$NAME"
  226. $PYTHON oml $@
  227. exit $?