No Description

ctl 5.6KB

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