freedombone-app-peertube 38KB

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