freedombone-app-peertube 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # PeerTube server
  10. #
  11. # There's a problem with installing this onto mesh images, which is
  12. # that qemu appears to run out of RAM when using yarn to add webpack.
  13. #
  14. # License
  15. # =======
  16. #
  17. # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
  18. #
  19. # This program is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU Affero General Public License as published by
  21. # the Free Software Foundation, either version 3 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU Affero General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU Affero General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. VARIANTS="full full-vim media"
  32. IN_DEFAULT_INSTALL=0
  33. SHOW_ON_ABOUT=1
  34. NOT_ON_ONION=1
  35. PEERTUBE_DOMAIN_NAME=
  36. PEERTUBE_CODE=
  37. PEERTUBE_REPO="https://github.com/Chocobozzz/PeerTube"
  38. PEERTUBE_COMMIT='50a3f3b821cd255ad8ae43f086aede0d2c9c778a'
  39. PEERTUBE_ONION_PORT=8136
  40. PEERTUBE_PORT=9004
  41. MESH_PEERTUBE_PORT=8500
  42. PEERTUBE_DIR=/etc/peertube
  43. PEERTUBE_SHORT_DESCRIPTION=$'Video broadcast'
  44. PEERTUBE_DESCRIPTION=$'Video broadcast'
  45. PEERTUBE_MOBILE_APP_URL=
  46. peertube_variables=(PEERTUBE_DOMAIN_NAME
  47. PEERTUBE_CODE
  48. PEERTUBE_ADMIN_PASSWORD
  49. ONION_ONLY
  50. DDNS_PROVIDER
  51. MY_USERNAME
  52. ARCHITECTURE
  53. MY_EMAIL_ADDRESS)
  54. function peertube_import_from_syncthing {
  55. peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
  56. nodecmd='node'
  57. if [[ "$ONION_ONLY" != 'no' ]]; then
  58. peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
  59. nodecmd='torsocks node'
  60. fi
  61. { echo '#!/bin/bash';
  62. echo '';
  63. echo 'LOCKFILE=/tmp/.peertube.lock';
  64. echo '';
  65. echo 'if [ -f /root/.peertube.lock ]; then';
  66. echo " lockctr=\$(cat \$LOCKFILE)";
  67. echo " lockctr=\$((lockctr+1))";
  68. echo " echo \"\$lockctr\" > \$LOCKFILE";
  69. echo " if [ \$lockctr -ge 30 ]; then";
  70. echo " rm \$LOCKFILE";
  71. echo ' else';
  72. echo ' exit 0';
  73. echo ' fi';
  74. echo 'fi';
  75. echo '';
  76. echo "MY_USERNAME=\$(cat /root/${PROJECT_NAME}.cfg | grep MY_USERNAME | awk -F '=' '{print \$2}')";
  77. echo "if [ ! \"\$MY_USERNAME\" ]; then";
  78. echo ' exit 0';
  79. echo 'fi';
  80. echo '';
  81. echo "search_dir=/home/\$MY_USERNAME/Sync/peertube_upload";
  82. echo "if [ ! -f \$search_dir/login.txt ]; then";
  83. echo ' exit 0';
  84. echo 'fi';
  85. echo "import_script=${PEERTUBE_DIR}/dist/server/tools/upload.js";
  86. echo "if [ ! -f \$import_script ]; then";
  87. echo ' exit 0';
  88. echo 'fi';
  89. echo '';
  90. echo "peertubedomain=\"$peertubedomain\"";
  91. echo "peertubeuser=\$(sed -n 1p < \"\$search_dir/login.txt\")";
  92. echo "peertubepassword=\$(sed -n 2p < \"\$search_dir/login.txt\")";
  93. echo 'peertubensfw=';
  94. echo "if grep -q 'nsfw' \"\$search_dir/login.txt\"; then";
  95. echo " peertubensfw='--nsfw'";
  96. echo 'fi';
  97. echo "if grep -q 'NSFW' \"\$search_dir/login.txt\"; then";
  98. echo " peertubensfw='--nsfw'";
  99. echo 'fi';
  100. echo '';
  101. echo "peertubeprivate='-P 3'";
  102. echo "if grep -q 'public' \"\$search_dir/login.txt\"; then";
  103. echo " peertubeprivate='-P 1'";
  104. echo 'fi';
  105. echo "if grep -q 'Public' \"\$search_dir/login.txt\"; then";
  106. echo " peertubeprivate='-P 1'";
  107. echo 'fi';
  108. echo '';
  109. echo 'failed_uploads=0';
  110. echo '';
  111. echo "cd ${PEERTUBE_DIR} || exit 32468356";
  112. echo "echo \"0\" > \$LOCKFILE";
  113. echo '';
  114. echo "for video_file in \$search_dir/*; do";
  115. echo " if [[ \"\$video_file\" == *'.ogv' || \"\$video_file\" == *'.mp4' || \"\$video_file\" == *'.webm' ]]; then";
  116. echo " if ! grep -q \"\$video_file\" /root/.peertube_uploaded; then";
  117. echo " peertubetitle=\$(basename \"\$video_file\" | awk -F '.' '{print \$1}' | sed 's|_| |g' | sed 's|-| |g')";
  118. echo " if $nodecmd \$import_script -n \"\$peertubetitle\" \$peertubensfw \$peertubeprivate -u \"\$peertubedomain\" -U \"\$peertubeuser\" --password \"\$peertubepassword\" -f \"\$video_file\"; then";
  119. echo " echo \"\$video_file\" >> /root/.peertube_uploaded";
  120. echo " rm \$LOCKFILE";
  121. echo " exit 0";
  122. echo ' else';
  123. echo " failed_uploads=\$((failed_uploads+1))";
  124. echo " if [ \$failed_uploads -gt 1 ]; then";
  125. echo " rm \$LOCKFILE";
  126. echo ' exit 0';
  127. echo ' fi';
  128. echo ' fi';
  129. echo ' fi';
  130. echo ' fi';
  131. echo 'done';
  132. echo '';
  133. echo "rm \$LOCKFILE"; } > /usr/bin/peertubesync
  134. chmod +x /usr/bin/peertubesync
  135. cron_add_mins 1 /usr/bin/peertubesync
  136. }
  137. function peertube_create_database {
  138. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  139. PEERTUBE_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
  140. else
  141. if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
  142. PEERTUBE_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  143. fi
  144. fi
  145. if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
  146. return
  147. fi
  148. systemctl restart postgresql
  149. run_system_query_postgresql "CREATE USER peertube WITH PASSWORD '$PEERTUBE_ADMIN_PASSWORD';"
  150. run_system_query_postgresql "CREATE DATABASE peertube OWNER peertube;"
  151. run_system_query_postgresql "GRANT ALL PRIVILEGES ON DATABASE peertube to peertube;"
  152. run_system_query_postgresql "set statement_timeout to 40000;"
  153. }
  154. function logging_on_peertube {
  155. echo -n ''
  156. }
  157. function logging_off_peertube {
  158. echo -n ''
  159. }
  160. function remove_user_peertube {
  161. echo -n ''
  162. # remove_username="$1"
  163. }
  164. function add_user_peertube {
  165. if [[ $(app_is_installed peertube) == "0" ]]; then
  166. echo '0'
  167. return
  168. fi
  169. # new_username="$1"
  170. # new_user_password="$2"
  171. echo '0'
  172. }
  173. function install_interactive_peertube {
  174. if [ ! "$ONION_ONLY" ]; then
  175. ONION_ONLY='no'
  176. fi
  177. if [[ $ONION_ONLY != "no" ]]; then
  178. PEERTUBE_DOMAIN_NAME='peertube.local'
  179. write_config_param "PEERTUBE_DOMAIN_NAME" "$PEERTUBE_DOMAIN_NAME"
  180. else
  181. function_check interactive_site_details
  182. interactive_site_details "peertube" "PEERTUBE_DOMAIN_NAME" "PEERTUBE_CODE"
  183. fi
  184. APP_INSTALLED=1
  185. }
  186. function peertube_set_admin_email {
  187. read_config_param "$MY_EMAIL_ADDRESS"
  188. data=$(mktemp 2>/dev/null)
  189. dialog --title $"Set PeerTube administrator email address" \
  190. --backtitle $"Freedombone Control Panel" \
  191. --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>"$data"
  192. sel=$?
  193. case $sel in
  194. 0) peertube_email=$(<"$data")
  195. if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
  196. if [ ${#peertube_email} -gt 8 ]; then
  197. sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
  198. systemctl restart peertube
  199. dialog --title $"Set PeerTube administrator email address" \
  200. --msgbox $"Set to $peertube_email" 6 75
  201. fi
  202. fi
  203. ;;
  204. esac
  205. rm -f "$data"
  206. }
  207. function peertube_disable_signups {
  208. dialog --title $"Disable PeerTube signups" \
  209. --backtitle $"Freedombone Control Panel" \
  210. --yesno $"\\nDo you wish to disable further PeerTube signups?" 8 75
  211. sel=$?
  212. case $sel in
  213. 0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
  214. 1) sed -i "0,/enabled:.*/s//enabled: true/" $PEERTUBE_DIR/config/production.yaml;;
  215. 255) return;;
  216. esac
  217. systemctl restart peertube
  218. }
  219. function peertube_import_from_file {
  220. read_config_param MY_USERNAME
  221. read_config_param PEERTUBE_DOMAIN_NAME
  222. read_config_param ONION_ONLY
  223. data2=$(mktemp 2>/dev/null)
  224. dialog --backtitle $"Freedombone Control Panel" \
  225. --title $"Import Video from file" \
  226. --form $"Enter your PeerTube login details and video title" 10 65 4 \
  227. $"Username:" 1 1 "$MY_USERNAME" 1 18 16 15 \
  228. $"Password:" 2 1 "" 2 18 40 10000 \
  229. $"Video Title:" 3 1 "" 3 18 40 1000 \
  230. $"NSFW:" 4 1 $"no" 4 18 4 4 \
  231. 2> "$data2"
  232. sel=$?
  233. case $sel in
  234. 1) rm -f "$data2"
  235. return;;
  236. 255) rm -f "$data2"
  237. return;;
  238. esac
  239. peertubeuser=$(sed -n 1p < "$data2")
  240. peertubepassword=$(sed -n 2p < "$data2")
  241. peertubetitle=$(sed -n 3p < "$data2")
  242. peertubensfw=$(sed -n 4p < "$data2")
  243. rm -f "$data2"
  244. peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
  245. nodecmd='node'
  246. if [[ "$ONION_ONLY" != 'no' ]]; then
  247. peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
  248. nodecmd='torsocks node'
  249. fi
  250. selected_file=$(dialog --title "Choose the video file (select with spacebar)" --fselect "/home/$MY_USERNAME/" 30 60)
  251. if [ ! "$selected_file" ]; then
  252. return
  253. fi
  254. if [[ "$selected_file" != *'.ogv' && "$selected_file" != *'.mp4' && "$selected_file" != *'.webm' ]]; then
  255. dialog --title $"Import video from file" \
  256. --msgbox $"The video should be in ogv, mp4 or webm format" 6 75
  257. return
  258. fi
  259. cd $PEERTUBE_DIR || exit 32468356
  260. import_script=$PEERTUBE_DIR/dist/server/tools/upload.js
  261. if [ ! -f $import_script ]; then
  262. dialog --title $"Import videos" \
  263. --msgbox $"upload script was not found" 6 75
  264. return
  265. fi
  266. nsfwstr=
  267. if [[ "$peertubensfw" == *'y'* || "$peertubensfw" == *'Y'* ]]; then
  268. nsfwstr='--nsfw'
  269. fi
  270. titlestr=$(basename "$selected_file" | awk -F '.' '{print $1}' | sed 's|_| |g' | sed 's|-| |g')
  271. if [ "$peertubetitle" ]; then
  272. titlestr="-n \"$peertubetitle\""
  273. fi
  274. clear
  275. $nodecmd $import_script $nsfwstr "$titlestr" -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -f "$selected_file"
  276. dialog --title $"Import video from file" \
  277. --msgbox $"Video imported from $selected_file" 6 75
  278. }
  279. function peertube_import_videos {
  280. read_config_param MY_USERNAME
  281. read_config_param PEERTUBE_DOMAIN_NAME
  282. read_config_param ONION_ONLY
  283. data2=$(mktemp 2>/dev/null)
  284. dialog --backtitle $"Freedombone Control Panel" \
  285. --title $"Import Videos from legacy sites" \
  286. --form $"Enter a channel of video URL for YouTube/Vimeo/Dailymotion" 10 75 4 \
  287. $"Username:" 1 1 "$MY_USERNAME" 1 22 16 15 \
  288. $"Password:" 2 1 "" 2 22 50 10000 \
  289. $"Video/Channel URL:" 3 1 "" 3 22 50 10000 \
  290. 2> "$data2"
  291. sel=$?
  292. case $sel in
  293. 1) rm -f "$data2"
  294. return;;
  295. 255) rm -f "$data2"
  296. return;;
  297. esac
  298. peertubeuser=$(sed -n 1p < "$data2")
  299. peertubepassword=$(sed -n 2p < "$data2")
  300. video_url=$(sed -n 3p < "$data2")
  301. rm -f "$data2"
  302. peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
  303. nodecmd='node'
  304. if [[ "$ONION_ONLY" != 'no' ]]; then
  305. peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
  306. nodecmd='torsocks node'
  307. fi
  308. if [ ${#peertubeuser} -lt 3 ]; then
  309. dialog --title $"Import videos from legacy sites" \
  310. --msgbox $"Username was not valid" 6 75
  311. return
  312. fi
  313. if [ ${#peertubepassword} -lt 3 ]; then
  314. dialog --title $"Import videos from legacy sites" \
  315. --msgbox $"Password was not valid" 6 75
  316. return
  317. fi
  318. if [[ "$video_url" == *' '* || "$video_url" == *','* || "$video_url" == *'@'* ]]; then
  319. dialog --title $"Import videos from legacy sites" \
  320. --msgbox $"Video/channel URL was not valid" 6 75
  321. return
  322. fi
  323. if [ ${#video_url} -lt 8 ]; then
  324. dialog --title $"Import videos from legacy sites" \
  325. --msgbox $"Video/channel URL was not valid" 6 75
  326. return
  327. fi
  328. cd $PEERTUBE_DIR || exit 32468356
  329. import_script=$PEERTUBE_DIR/dist/server/tools/import-videos.js
  330. if [ ! -f $import_script ]; then
  331. dialog --title $"Import videos from legacy sites" \
  332. --msgbox $"import-videos script was not found" 6 75
  333. return
  334. fi
  335. clear
  336. $nodecmd $import_script -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -t "$video_url"
  337. dialog --title $"Import videos from legacy sites" \
  338. --msgbox $"Video/s imported from $video_url" 6 75
  339. }
  340. function configure_interactive_peertube {
  341. W=(1 $"Set administrator email address"
  342. 2 $"Disable or enable signups"
  343. 3 $"Import videos from YouTube/Vimeo/Dailymotion"
  344. 4 $"Import video from file")
  345. while true
  346. do
  347. # shellcheck disable=SC2068
  348. selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"PeerTube" --menu $"Choose an operation, or ESC to exit:" 12 60 4 "${W[@]}" 3>&2 2>&1 1>&3)
  349. if [ ! "$selection" ]; then
  350. break
  351. fi
  352. case $selection in
  353. 1) peertube_set_admin_email;;
  354. 2) peertube_disable_signups;;
  355. 3) peertube_import_videos;;
  356. 4) peertube_import_from_file;;
  357. esac
  358. done
  359. }
  360. function change_password_peertube {
  361. # PEERTUBE_USERNAME="$1"
  362. PEERTUBE_PASSWORD="$2"
  363. if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
  364. echo $'Peertube password is too short'
  365. return
  366. fi
  367. #"${PROJECT_NAME}-pass" -u "$PEERTUBE_USERNAME" -a peertube -p "$PEERTUBE_PASSWORD"
  368. }
  369. function reconfigure_peertube {
  370. echo -n ''
  371. }
  372. function upgrade_peertube {
  373. peertube_import_from_syncthing
  374. CURR_PEERTUBE_COMMIT=$(get_completion_param "peertube commit")
  375. if [[ "$CURR_PEERTUBE_COMMIT" == "$PEERTUBE_COMMIT" ]]; then
  376. return
  377. fi
  378. read_config_param PEERTUBE_DOMAIN_NAME
  379. systemctl stop peertube
  380. cd "$PEERTUBE_DIR" || exit 7824552627
  381. function_check set_repo_commit
  382. set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
  383. if ! npm install -g yarn@1.5.1; then
  384. echo $'Failed to install yarn'
  385. exit 79353234
  386. fi
  387. yarn add -D webpack --network-concurrency 1
  388. if ! yarn install; then
  389. echo $'Failed to run yarn install'
  390. exit 63754235
  391. fi
  392. if ! npm install -g npm@4; then
  393. # https://github.com/KraigM/homebridge-harmonyhub/issues/119
  394. echo $'Failed to downgrade npm'
  395. npm install -g "npm@${NPM_VERSION}"
  396. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  397. exit 3476835
  398. fi
  399. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  400. if ! npm install; then
  401. echo $'Failed to install peertube'
  402. npm install -g "npm@${NPM_VERSION}"
  403. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  404. exit 7835243
  405. fi
  406. if ! npm install -g "npm@${NPM_VERSION}"; then
  407. echo $'Failed to restore npm after downgrade'
  408. exit 5737583
  409. fi
  410. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  411. npm run build
  412. # This doesn't appear to work
  413. #sudo -u peertube ./upgrade.sh $PEERTUBE_DIR
  414. chown -R peertube:peertube $PEERTUBE_DIR
  415. systemctl start peertube
  416. }
  417. function backup_local_peertube {
  418. PEERTUBE_DOMAIN_NAME='peertube.local'
  419. if grep -q "peertube domain" "$COMPLETION_FILE"; then
  420. PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
  421. fi
  422. systemctl stop peertube
  423. USE_POSTGRESQL=1
  424. function_check backup_database_to_usb
  425. backup_database_to_usb peertube
  426. systemctl start peertube
  427. peertube_path=$PEERTUBE_DIR/videos
  428. if [ -d $peertube_path ]; then
  429. suspend_site "${PEERTUBE_DOMAIN_NAME}"
  430. systemctl stop peertube
  431. backup_directory_to_usb $peertube_path peertubevideos
  432. systemctl start peertube
  433. restart_site
  434. fi
  435. }
  436. function restore_local_peertube {
  437. PEERTUBE_DOMAIN_NAME='peertube.local'
  438. if grep -q "peertube domain" "$COMPLETION_FILE"; then
  439. PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
  440. fi
  441. if [ "$PEERTUBE_DOMAIN_NAME" ]; then
  442. suspend_site "${PEERTUBE_DOMAIN_NAME}"
  443. systemctl stop peertube
  444. USE_POSTGRESQL=1
  445. restore_database peertube
  446. temp_restore_dir=/root/temppeertubevideos
  447. function_check restore_directory_from_usb
  448. restore_directory_from_usb $temp_restore_dir peertubevideos
  449. if [ -d $temp_restore_dir ]; then
  450. if [ -d $temp_restore_dir$PEERTUBE_DIR/videos ]; then
  451. cp -r $temp_restore_dir$PEERTUBE_DIR/videos/* $PEERTUBE_DIR/videos/
  452. else
  453. cp -r $temp_restore_dir/* $PEERTUBE_DIR/videos/
  454. fi
  455. chown -R peertube:peertube $PEERTUBE_DIR
  456. rm -rf $temp_restore_dir
  457. fi
  458. systemctl start peertube
  459. restart_site
  460. fi
  461. }
  462. function backup_remote_peertube {
  463. PEERTUBE_DOMAIN_NAME='peertube.local'
  464. if grep -q "peertube domain" "$COMPLETION_FILE"; then
  465. PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
  466. fi
  467. systemctl stop peertube
  468. USE_POSTGRESQL=1
  469. function_check backup_database_to_friend
  470. backup_database_to_friend peertube
  471. systemctl start peertube
  472. temp_backup_dir=$PEERTUBE_DIR/videos
  473. if [ -d $temp_backup_dir ]; then
  474. systemctl stop peertube
  475. suspend_site "${PEERTUBE_DOMAIN_NAME}"
  476. backup_directory_to_friend $temp_backup_dir peertubevideos
  477. restart_site
  478. systemctl start peertube
  479. else
  480. echo $"Peertube domain specified but not found in $temp_backup_dir"
  481. exit 6383523
  482. fi
  483. }
  484. function restore_remote_peertube {
  485. PEERTUBE_DOMAIN_NAME='peertube.local'
  486. if grep -q "peertube domain" "$COMPLETION_FILE"; then
  487. PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
  488. fi
  489. suspend_site "${PEERTUBE_DOMAIN_NAME}"
  490. systemctl stop peertube
  491. # shellcheck disable=SC2034
  492. USE_POSTGRESQL=1
  493. function_check restore_database_from_friend
  494. restore_database_from_friend peertube
  495. temp_restore_dir=/root/temppeertubevideos
  496. function_check restore_directory_from_friend
  497. restore_directory_from_friend $temp_restore_dir peertubevideos
  498. if [ -d $temp_restore_dir ]; then
  499. if [ -d $temp_restore_dir$PEERTUBE_DIR/videos ]; then
  500. cp -r $temp_restore_dir$PEERTUBE_DIR/videos/* $PEERTUBE_DIR/videos/
  501. else
  502. cp -r $temp_restore_dir/* $PEERTUBE_DIR/videos/
  503. fi
  504. chown -R peertube: $PEERTUBE_DIR
  505. rm -rf $temp_restore_dir
  506. fi
  507. systemctl start peertube
  508. restart_site
  509. }
  510. function remove_peertube {
  511. if [ ${#PEERTUBE_DOMAIN_NAME} -eq 0 ]; then
  512. return
  513. fi
  514. systemctl stop peertube
  515. systemctl disable peertube
  516. rm /etc/systemd/system/peertube.service
  517. systemctl daemon-reload
  518. function_check remove_nodejs
  519. remove_nodejs peertube
  520. read_config_param "PEERTUBE_DOMAIN_NAME"
  521. nginx_dissite "$PEERTUBE_DOMAIN_NAME"
  522. remove_certs "${PEERTUBE_DOMAIN_NAME}"
  523. if [ -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME" ]; then
  524. rm -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME"
  525. fi
  526. if [ -d "/var/www/$PEERTUBE_DOMAIN_NAME" ]; then
  527. rm -rf "/var/www/$PEERTUBE_DOMAIN_NAME"
  528. fi
  529. remove_config_param PEERTUBE_DOMAIN_NAME
  530. remove_config_param PEERTUBE_CODE
  531. function_check remove_onion_service
  532. remove_onion_service peertube ${PEERTUBE_ONION_PORT}
  533. remove_completion_param "install_peertube"
  534. sed -i '/peertube/d' "$COMPLETION_FILE"
  535. sed -i '/peertubesync/d' /etc/crontab
  536. if [ -f /usr/bin/peertubesync ]; then
  537. rm /usr/bin/peertubesync
  538. fi
  539. if [ -f /root/peertube_uploaded ]; then
  540. rm /root/peertube_uploaded
  541. fi
  542. function_check drop_database_postgresql
  543. drop_database_postgresql peertube peertube
  544. groupdel -f peertube
  545. userdel -r peertube
  546. if [ -d $PEERTUBE_DIR ]; then
  547. rm -rf $PEERTUBE_DIR
  548. fi
  549. function_check remove_ddns_domain
  550. remove_ddns_domain "$PEERTUBE_DOMAIN_NAME"
  551. }
  552. function peertube_setup_web {
  553. peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
  554. if [[ $ONION_ONLY == "no" ]]; then
  555. { echo 'server {';
  556. echo ' listen 80;';
  557. echo ' listen [::]:80;';
  558. echo " server_name $PEERTUBE_DOMAIN_NAME;";
  559. echo " rewrite ^ https://\$server_name\$request_uri? permanent;";
  560. echo '}';
  561. echo '';
  562. echo 'server {';
  563. echo ' listen 443 ssl http2;';
  564. echo ' #listen [::]:443 ssl http2;';
  565. echo " server_name $PEERTUBE_DOMAIN_NAME;";
  566. echo ''; } > "$peertube_nginx_file"
  567. function_check nginx_ssl
  568. nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile
  569. function_check nginx_security_options
  570. nginx_security_options "$PEERTUBE_DOMAIN_NAME"
  571. { echo ' add_header Strict-Transport-Security max-age=15768000;';
  572. echo '';
  573. echo ' location / {';
  574. echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
  575. echo " proxy_set_header X-Real-IP \$remote_addr;";
  576. echo " proxy_set_header Host \$host;";
  577. echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
  578. echo '';
  579. echo ' # For the video upload';
  580. echo ' client_max_body_size 2G;';
  581. echo ' }';
  582. echo '';
  583. echo ' location /static/webseed {';
  584. echo " if (\$request_method = 'OPTIONS') {";
  585. echo " add_header 'Access-Control-Allow-Origin' '*';";
  586. echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
  587. echo " add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
  588. echo " add_header 'Access-Control-Max-Age' 1728000;";
  589. echo " add_header 'Content-Type' 'text/plain charset=UTF-8';";
  590. echo " add_header 'Content-Length' 0;";
  591. echo ' return 204;';
  592. echo ' }';
  593. echo '';
  594. echo " if (\$request_method = 'GET') {";
  595. echo " add_header 'Access-Control-Allow-Origin' '*';";
  596. echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
  597. echo " add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
  598. echo ' }';
  599. echo '';
  600. echo " alias $PEERTUBE_DIR/videos;";
  601. echo ' }';
  602. echo '';
  603. echo ' # Websocket tracker';
  604. echo ' location /tracker/socket {';
  605. echo ' # Peers send a message to the tracker every 15 minutes';
  606. echo ' # Dont close the websocket before this time';
  607. echo ' proxy_read_timeout 1200s;';
  608. echo " proxy_set_header Upgrade \$http_upgrade;";
  609. echo ' proxy_set_header Connection "upgrade";';
  610. echo ' proxy_http_version 1.1;';
  611. echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
  612. echo " proxy_set_header Host \$host;";
  613. echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
  614. echo ' }';
  615. echo '}'; } >> "$peertube_nginx_file"
  616. else
  617. echo -n '' > "$peertube_nginx_file"
  618. fi
  619. { echo 'server {';
  620. echo " listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;";
  621. echo " server_name $PEERTUBE_ONION_HOSTNAME;";
  622. echo '';
  623. echo ' location / {';
  624. echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
  625. echo " proxy_set_header X-Real-IP \$remote_addr;";
  626. echo " proxy_set_header Host \$host;";
  627. echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
  628. echo '';
  629. echo ' # For the video upload';
  630. echo ' client_max_body_size 2G;';
  631. echo ' }';
  632. echo '';
  633. echo ' location /static/webseed {';
  634. echo " if (\$request_method = 'OPTIONS') {";
  635. echo " add_header 'Access-Control-Allow-Origin' '*';";
  636. echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
  637. echo " add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
  638. echo " add_header 'Access-Control-Max-Age' 1728000;";
  639. echo " add_header 'Content-Type' 'text/plain charset=UTF-8';";
  640. echo " add_header 'Content-Length' 0;";
  641. echo ' return 204;';
  642. echo ' }';
  643. echo '';
  644. echo " if (\$request_method = 'GET') {";
  645. echo " add_header 'Access-Control-Allow-Origin' '*';";
  646. echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
  647. echo " add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
  648. echo ' }';
  649. echo '';
  650. echo " alias $PEERTUBE_DIR/videos;";
  651. echo ' }';
  652. echo '';
  653. echo ' # Websocket tracker';
  654. echo ' location /tracker/socket {';
  655. echo ' # Peers send a message to the tracker every 15 minutes';
  656. echo ' # Dont close the websocket before this time';
  657. echo ' proxy_read_timeout 1200s;';
  658. echo " proxy_set_header Upgrade \$http_upgrade;";
  659. echo ' proxy_set_header Connection "upgrade";';
  660. echo ' proxy_http_version 1.1;';
  661. echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
  662. echo " proxy_set_header Host \$host;";
  663. echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
  664. echo ' }';
  665. echo '}'; } >> "$peertube_nginx_file"
  666. # CSP currently causes an error
  667. sed -i '/Content-Security-Policy/d' "$peertube_nginx_file"
  668. function_check create_site_certificate
  669. create_site_certificate "$PEERTUBE_DOMAIN_NAME" 'yes'
  670. function_check nginx_ensite
  671. nginx_ensite "$PEERTUBE_DOMAIN_NAME"
  672. }
  673. function mesh_peertube_setup_web {
  674. # shellcheck disable=SC2154
  675. peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
  676. { echo 'server {';
  677. echo " listen $MESH_PEERTUBE_PORT http2;";
  678. echo " listen [::]:\$MESH_PEERTUBE_PORT http2;";
  679. echo " server_name \$HOSTNAME;";
  680. echo '';
  681. echo ' location / {';
  682. echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
  683. echo " proxy_set_header X-Real-IP \$remote_addr;";
  684. echo " proxy_set_header Host \$host;";
  685. echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
  686. echo '';
  687. echo ' # For the video upload';
  688. echo ' client_max_body_size 2G;';
  689. echo ' }';
  690. echo '';
  691. echo ' location /static/webseed {';
  692. echo " if (\$request_method = 'OPTIONS') {";
  693. echo " add_header 'Access-Control-Allow-Origin' '*';";
  694. echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
  695. echo " add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
  696. echo " add_header 'Access-Control-Max-Age' 1728000;";
  697. echo " add_header 'Content-Type' 'text/plain charset=UTF-8';";
  698. echo " add_header 'Content-Length' 0;";
  699. echo ' return 204;';
  700. echo ' }';
  701. echo '';
  702. echo " if (\$request_method = 'GET') {";
  703. echo " add_header 'Access-Control-Allow-Origin' '*';";
  704. echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
  705. echo " add_header 'Access-Control-Allow-Headers' 'Range,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';";
  706. echo ' }';
  707. echo '';
  708. echo " alias $PEERTUBE_DIR/videos;";
  709. echo ' }';
  710. echo '';
  711. echo ' # Websocket tracker';
  712. echo ' location /tracker/socket {';
  713. echo ' # Peers send a message to the tracker every 15 minutes';
  714. echo ' # Dont close the websocket before this time';
  715. echo ' proxy_read_timeout 1200s;';
  716. echo " proxy_set_header Upgrade \$http_upgrade;";
  717. echo " proxy_set_header Connection \"upgrade\";";
  718. echo ' proxy_http_version 1.1;';
  719. echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
  720. echo " proxy_set_header Host \$host;";
  721. echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
  722. echo ' }';
  723. echo '}'; } > "$peertube_nginx_file"
  724. }
  725. function peertube_create_config {
  726. peertube_prefix=$1
  727. peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
  728. { echo 'listen:';
  729. echo " port: $PEERTUBE_PORT";
  730. echo '';
  731. echo '# Correspond to your reverse proxy "listen" configuration';
  732. echo 'webserver:'; } > "$peertube_config_file"
  733. if [ ! "$peertube_prefix" ]; then
  734. if [[ "$ONION_ONLY" == 'no' ]]; then
  735. { echo ' https: true';
  736. echo " hostname: '$PEERTUBE_DOMAIN_NAME'";
  737. echo ' port: 443'; } >> "$peertube_config_file"
  738. else
  739. { echo ' https: false';
  740. echo " hostname: '$PEERTUBE_ONION_HOSTNAME'";
  741. echo ' port: 80'; } >> "$peertube_config_file"
  742. fi
  743. else
  744. { echo ' https: false';
  745. echo " hostname: ''";
  746. echo " port: $MESH_PEERTUBE_PORT"; } >> "$peertube_config_file"
  747. fi
  748. { echo '';
  749. echo '# Your database name will be "peertube"+database.suffix';
  750. echo 'database:';
  751. echo " hostname: 'localhost'";
  752. echo ' port: 5432';
  753. echo " suffix: ''";
  754. echo " username: 'peertube'"; } >> "$peertube_config_file"
  755. if [ ! "$peertube_prefix" ]; then
  756. echo " password: '$PEERTUBE_ADMIN_PASSWORD'" >> "$peertube_config_file"
  757. else
  758. echo " password: ''" >> "$peertube_config_file"
  759. fi
  760. { echo '';
  761. echo '# From the project root directory';
  762. echo 'storage:';
  763. echo " certs: 'certs/'";
  764. echo " videos: 'videos/'";
  765. echo " logs: 'logs/'";
  766. echo " previews: 'previews/'";
  767. echo " thumbnails: 'thumbnails/'";
  768. echo " torrents: 'torrents/'";
  769. echo " cache: 'cache/'";
  770. echo '';
  771. echo 'cache:';
  772. echo ' previews:';
  773. echo ' size: 10 # Max number of previews you want to cache';
  774. echo '';
  775. echo 'admin:';
  776. # This is deliberately a dummy email address
  777. echo " email: 'testuser@testdomain.net'";
  778. echo '';
  779. echo 'signup:';
  780. echo ' enabled: true';
  781. echo ' limit: 5 # When the limit is reached, registrations are disabled. -1 == unlimited';
  782. echo '';
  783. echo 'user:';
  784. echo ' # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).';
  785. echo ' # -1 == unlimited';
  786. echo ' video_quota: -1';
  787. echo '';
  788. echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag';
  789. echo '# Uses a lot of CPU!';
  790. echo 'transcoding:';
  791. echo ' enabled: false';
  792. echo ' threads: 2';
  793. echo ' resolutions: # Only created if the original video has a higher resolution';
  794. echo ' 240p: true';
  795. echo ' 360p: false';
  796. echo ' 480p: false';
  797. echo ' 720p: false';
  798. echo ' 1080p: false'; } >> "$peertube_config_file"
  799. }
  800. function mesh_install_peertube {
  801. # shellcheck disable=SC2153
  802. if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
  803. return
  804. fi
  805. if [[ "$ARCHITECTURE" != 'x86_64' && "$ARCHITECTURE" != 'amd64' && "$ARCHITECTURE" != 'i386' ]]; then
  806. return
  807. fi
  808. chroot "$rootdir" apt-get -yq install ffmpeg curl redis-tools redis-server
  809. function_check install_postgresql
  810. install_postgresql
  811. if [ -d "$rootdir$PEERTUBE_DIR" ]; then
  812. rm -rf "$rootdir$PEERTUBE_DIR"
  813. fi
  814. git clone "$PEERTUBE_REPO" "$rootdir$PEERTUBE_DIR"
  815. chroot "$rootdir" groupadd peertube
  816. chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
  817. cd "$rootdir$PEERTUBE_DIR" || exit 246824524
  818. git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
  819. get_npm_arch
  820. cat <<EOF > "$rootdir/usr/bin/install_peertube"
  821. #!/bin/bash
  822. cd $PEERTUBE_DIR
  823. curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  824. echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  825. apt-get -y update
  826. apt-get -yq install yarn
  827. #if ! npm install --arch=$NPM_ARCH -g yarn@1.5.1; then
  828. # echo $'PeerTube Failed to install yarn'
  829. # exit 79353234
  830. #fi
  831. #if ! npm install --arch=$NPM_ARCH webpack@3.10.0 --no-optional; then
  832. # echo $'PeerTube failed to install webpack'
  833. # exit 68386353
  834. #fi
  835. yarn install
  836. yarn run build:prod
  837. if ! yarn add -D webpack; then
  838. echo $'PeerTube failed to add webpack'
  839. exit 67342823
  840. fi
  841. if ! yarn install --ignore-optional; then
  842. echo $'PeerTube failed to run yarn install'
  843. exit 63754235
  844. fi
  845. if ! npm install --arch=$NPM_ARCH -g npm@4; then
  846. # https://github.com/KraigM/homebridge-harmonyhub/issues/119
  847. echo $'Failed to downgrade npm'
  848. exit 3476835
  849. fi
  850. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  851. if ! npm install --arch=$NPM_ARCH; then
  852. echo $'PeerTube failed to install peertube'
  853. exit 7835243
  854. fi
  855. if ! npm install --arch=$NPM_ARCH -g "npm@${NPM_VERSION}"; then
  856. echo $'Failed to restore npm after downgrade'
  857. exit 5737583
  858. fi
  859. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  860. if ! npm run build --arch=$NPM_ARCH; then
  861. echo $'PeerTube failed to build peertube'
  862. exit 5293593
  863. fi
  864. EOF
  865. chmod +x "$rootdir/usr/bin/install_peertube"
  866. if ! chroot "$rootdir" /usr/bin/install_peertube; then
  867. echo $'PeerTube install failed'
  868. exit 735638
  869. fi
  870. { echo '[Unit]';
  871. echo 'Description=PeerTube Decentralized video streaming platform';
  872. echo 'After=syslog.target';
  873. echo 'After=network.target';
  874. echo '';
  875. echo '[Service]';
  876. echo 'User=peertube';
  877. echo 'Group=peertube';
  878. echo "WorkingDirectory=$PEERTUBE_DIR";
  879. echo "ExecStart=/usr/local/bin/npm start";
  880. echo "ExecStop=/usr/local/bin/npm stop";
  881. echo 'StandardOutput=syslog';
  882. echo 'StandardError=syslog';
  883. echo 'SyslogIdentifier=peertube';
  884. echo 'Restart=always';
  885. echo "Environment=NODE_ENV=production";
  886. echo '';
  887. echo '[Install]';
  888. echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/peertube.service"
  889. peertube_create_config "$rootdir"
  890. chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
  891. mesh_peertube_setup_web
  892. }
  893. function install_peertube {
  894. if [[ $VARIANT == "mesh"* ]]; then
  895. mesh_install_peertube
  896. return
  897. fi
  898. if [[ $ARCHITECTURE != 'x86_64' && $ARCHITECTURE != 'amd64' ]]; then
  899. return
  900. fi
  901. if [ ! $ONION_ONLY ]; then
  902. ONION_ONLY='no'
  903. fi
  904. if [ ! "$PEERTUBE_DOMAIN_NAME" ]; then
  905. echo $'The peertube domain name was not specified'
  906. exit 783523
  907. fi
  908. apt-get -yq install ffmpeg redis-tools redis-server
  909. function_check install_postgresql
  910. install_postgresql
  911. if [ ! -d "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs" ]; then
  912. mkdir -p "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs"
  913. fi
  914. if [ -d $PEERTUBE_DIR ]; then
  915. rm -rf $PEERTUBE_DIR
  916. fi
  917. groupadd peertube
  918. useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
  919. peertube_create_database
  920. function_check install_nodejs
  921. install_nodejs peertube
  922. if [ -d /repos/peertube ]; then
  923. mkdir -p $PEERTUBE_DIR
  924. cp -r -p /repos/peertube/. $PEERTUBE_DIR
  925. cd "$PEERTUBE_DIR" || exit 642874682
  926. git pull
  927. else
  928. function_check git_clone
  929. git_clone $PEERTUBE_REPO $PEERTUBE_DIR
  930. fi
  931. cd "$PEERTUBE_DIR" || exit 27492742
  932. git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
  933. set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
  934. if ! npm install -g yarn@1.5.1; then
  935. echo $'Failed to install yarn'
  936. exit 79353234
  937. fi
  938. yarn add -D webpack --network-concurrency 1
  939. if ! yarn install; then
  940. echo $'Failed to run yarn install'
  941. exit 63754235
  942. fi
  943. if ! npm install -g npm@4; then
  944. # https://github.com/KraigM/homebridge-harmonyhub/issues/119
  945. echo $'Failed to downgrade npm'
  946. exit 3476835
  947. fi
  948. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  949. if ! npm install; then
  950. echo $'Failed to install peertube'
  951. exit 7835243
  952. fi
  953. if ! npm install -g "npm@${NPM_VERSION}"; then
  954. echo $'Failed to restore npm after downgrade'
  955. exit 5737583
  956. fi
  957. cp /root/.npm-global/bin/npm /usr/local/bin/npm
  958. npm run build
  959. PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
  960. { echo '[Unit]';
  961. echo 'Description=PeerTube Decentralized video streaming platform';
  962. echo 'After=syslog.target';
  963. echo 'After=network.target';
  964. echo '';
  965. echo '[Service]';
  966. echo 'User=peertube';
  967. echo 'Group=peertube';
  968. echo "WorkingDirectory=$PEERTUBE_DIR";
  969. echo "ExecStart=/usr/local/bin/npm start";
  970. echo "ExecStop=/usr/local/bin/npm stop";
  971. echo 'StandardOutput=syslog';
  972. echo 'StandardError=syslog';
  973. echo 'SyslogIdentifier=peertube';
  974. echo 'Restart=always';
  975. echo "Environment=NODE_ENV=production";
  976. echo '';
  977. echo '[Install]';
  978. echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/peertube.service
  979. peertube_create_config
  980. chown -R peertube:peertube $PEERTUBE_DIR
  981. peertube_setup_web
  982. "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
  983. function_check add_ddns_domain
  984. add_ddns_domain "$PEERTUBE_DOMAIN_NAME"
  985. systemctl enable peertube
  986. systemctl daemon-reload
  987. systemctl start peertube
  988. systemctl restart nginx
  989. # wait for the database to get generated after initial peertube daemon start
  990. sleep 10
  991. # update the admin email address after creation of the database
  992. sed -i "s|email: .*|email: '$MY_EMAIL_ADDRESS'|g" $PEERTUBE_DIR/config/production.yaml
  993. peertube_import_from_syncthing
  994. set_completion_param "peertube domain" "$PEERTUBE_DOMAIN_NAME"
  995. APP_INSTALLED=1
  996. }
  997. # NOTE: deliberately no exit 0