freedombone-app-peertube 37KB

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