freedombone-app-peertube 37KB

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