No Description

ctl 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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.7
  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. if [ -e "$BASE/platform_${PLATFORM}/lib/libunrar.so" ]; then
  56. export UNRAR_LIB_PATH="$BASE/platform_${PLATFORM}/lib/libunrar.so"
  57. fi
  58. fi
  59. if [ $SYSTEM == "Darwin" ]; then
  60. PLATFORM="darwin64"
  61. PLATFORM_PYTHON=3.7
  62. if [ -e "$BASE/platform_${PLATFORM}/lib/libunrar.dylib" ]; then
  63. export UNRAR_LIB_PATH="$BASE/platform_${PLATFORM}/lib/libunrar.dylib"
  64. fi
  65. fi
  66. export PLATFORM_ENV="$BASE/platform_${PLATFORM}"
  67. fi
  68. PATH="$PLATFORM_ENV/bin:$PATH"
  69. SHARED_ENV="$BASE/platform/Shared"
  70. export SHARED_ENV
  71. PATH="$SHARED_ENV/bin:$PATH"
  72. export PATH
  73. if [ $SYSTEM == "Darwin" ]; then
  74. export DYLD_FALLBACK_LIBRARY_PATH="$PLATFORM_ENV/lib"
  75. export SSL_CERT_FILE="$SHARED_ENV/etc/openssl/cert.pem"
  76. export SSL_CERT_DIR="$SHARED_ENV/etc/openssl/certs"
  77. fi
  78. PYTHONPATH="${PLATFORM_ENV}/lib/python${PLATFORM_PYTHON}/site-packages"
  79. PYTHONPATH="${PYTHONPATH}:${SHARED_ENV}/lib/python${PLATFORM_PYTHON}/site-packages"
  80. PYTHONPATH="${PYTHONPATH}:${SHARED_ENV}/lib/python${SHARED_PYTHON}/site-packages"
  81. PYTHONPATH="${PYTHONPATH}:${BASE}/${NAME}"
  82. export PYTHONPATH
  83. oxCACHE="$DATA/ox"
  84. export oxCACHE
  85. #must be called to update commands in $PATH
  86. hash -r 2>/dev/null
  87. # allow more open files
  88. ulimit -S -n 2048
  89. function update_gitbase() {
  90. if [ -e "${BASE}/openmedialibrary/.git/config" ]; then
  91. GIT_BASE=`grep origin .git/config -A 1 | grep url | cut -f2 -d=`
  92. fi
  93. }
  94. if [ "$1" == "start" ]; then
  95. cd "$BASE/$NAME"
  96. if [ -e "$PID" ]; then
  97. if ps -p `cat "$PID"` > /dev/null; then
  98. echo openmedialibrary already running
  99. exit 1
  100. fi
  101. fi
  102. $PYTHON oml server "$PID"
  103. exit $?
  104. fi
  105. if [ "$1" == "debug" ]; then
  106. cd "$BASE/$NAME"
  107. if [ -e "$PID" ]; then
  108. if ps -p `cat "$PID"` > /dev/null; then
  109. echo openmedialibrary already running
  110. exit 1
  111. fi
  112. fi
  113. shift
  114. $PYTHON oml server debug "$PID"
  115. exit $?
  116. fi
  117. if [ "$1" == "stop" ]; then
  118. if [ -e "$PID" ]; then
  119. _PID=`cat "$PID"`
  120. kill $_PID
  121. waited=0
  122. while ps -p $_PID > /dev/null
  123. do
  124. sleep 1
  125. waited=$(($waited+1))
  126. if [ $waited -gt 60 ]; then
  127. kill -9 $_PID
  128. sleep 1
  129. fi
  130. done
  131. test -e "$PID" && rm "$PID"
  132. fi
  133. exit $?
  134. fi
  135. if [ "$1" == "restart" ]; then
  136. if [ -e "$PID" ]; then
  137. "$0" stop
  138. "$0" start
  139. exit $?
  140. else
  141. "$0" start
  142. exit $?
  143. fi
  144. fi
  145. function get_port() {
  146. port=$(grep '"port"' "${BASE}/data/server.json" | cut -f2 -d: | cut -f1 -d, | xargs)
  147. return $port
  148. }
  149. function open_linux() {
  150. port=$(get_port)
  151. if [ -e /usr/bin/gio ]; then
  152. gio open "file://${BASE}/openmedialibrary/static/html/load.html#$port"
  153. else
  154. xdg-open "file://${BASE}/openmedialibrary/static/html/load.html#$port"
  155. fi
  156. }
  157. if [ "$1" == "open" ]; then
  158. if [ $SYSTEM == "Darwin" ]; then
  159. open "/Applications/Open Media Library.app"
  160. fi
  161. if [ $SYSTEM == "Linux" ]; then
  162. if [ -e "$PID" ]; then
  163. if ps -p `cat "$PID"` > /dev/null; then
  164. open_linux
  165. else
  166. open_linux
  167. "$0" start &
  168. fi
  169. else
  170. open_linux
  171. "$0" start &
  172. fi
  173. fi
  174. exit 0
  175. fi
  176. if [ "$1" == "autostart" ]; then
  177. if [ $SYSTEM == "Darwin" ]; then
  178. open "/Applications/Open Media Library.app" --args --autostart
  179. fi
  180. if [ $SYSTEM == "Linux" ]; then
  181. if [ ! -e "$PID" ]; then
  182. $PYTHON "$NAME/oml/gtkstatus.py" --autostart
  183. exit $?
  184. fi
  185. fi
  186. exit 0
  187. fi
  188. if [ "$1" == "ui" ]; then
  189. shift
  190. $PYTHON "$NAME/oml/ui.py" "$@"
  191. exit $?
  192. fi
  193. if [ "$1" == "init" ]; then
  194. update_gitbase
  195. if [ ! -e "${BASE}/platform" ]; then
  196. git clone --depth 1 $GIT_BASE/openmedialibrary_platform.git "${BASE}/platform"
  197. fi
  198. if [ ! -e "${PLATFORM_ENV}" ]; then
  199. git clone --depth 1 $GIT_BASE/openmedialibrary_platform_${PLATFORM}.git "${PLATFORM_ENV}"
  200. fi
  201. cd "${BASE}"
  202. if [ ! -e "${BASE}/ctl" ]; then
  203. ln -s openmedialibrary/ctl
  204. fi
  205. "${BASE}/ctl" update_static
  206. exit
  207. fi
  208. if [ "$1" == "update" ]; then
  209. cd "$BASE/$NAME"
  210. if [ ! -e "${PLATFORM_ENV}" ]; then
  211. update_gitbase
  212. git clone --depth 1 $GIT_BASE/openmedialibrary_platform_${PLATFORM}.git "${PLATFORM_ENV}"
  213. fi
  214. if [ -d "$BASE/$NAME/.git" ]; then
  215. OLD=`"$0" version`
  216. cd "$BASE/platform"
  217. echo Update shared platform...
  218. git pull
  219. cd "${PLATFORM_ENV}"
  220. echo Update platform...
  221. git pull
  222. echo Update $NAME...
  223. cd "$BASE/$NAME"
  224. find . -name "*.pyc" -exec rm "{}" \;
  225. git pull
  226. "$0" update_static > /dev/null
  227. NEW=`"$0" version`
  228. "$0" postupdate -o $OLD -n $NEW
  229. else
  230. $PYTHON oml update
  231. fi
  232. exit $?
  233. fi
  234. if [ "$1" == "python" ]; then
  235. cd "$BASE/$NAME"
  236. shift
  237. $PYTHON $@
  238. exit $?
  239. fi
  240. cd "$BASE/$NAME"
  241. $PYTHON oml $@
  242. exit $?