1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129 |
- #!/bin/bash
- # _____ _ _
- # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
- # | __| _| -_| -_| . | . | | . | . | | -_|
- # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
- #
- # Freedom in the Cloud
- #
- # PeerTube server
- #
- # There's a problem with installing this onto mesh images, which is
- # that qemu appears to run out of RAM when using yarn to add webpack.
- #
- # License
- # =======
- #
- # Copyright (C) 2017-2018 Bob Mottram <bob@freedombone.net>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- VARIANTS="full full-vim media"
-
- IN_DEFAULT_INSTALL=0
- SHOW_ON_ABOUT=1
- NOT_ON_ONION=1
-
- PEERTUBE_DOMAIN_NAME=
- PEERTUBE_CODE=
- PEERTUBE_REPO="https://github.com/Chocobozzz/PeerTube"
- PEERTUBE_COMMIT='50a3f3b821cd255ad8ae43f086aede0d2c9c778a'
- PEERTUBE_ONION_PORT=8136
- PEERTUBE_PORT=9004
- MESH_PEERTUBE_PORT=8500
- PEERTUBE_DIR=/etc/peertube
-
- PEERTUBE_SHORT_DESCRIPTION=$'Video broadcast'
- PEERTUBE_DESCRIPTION=$'Video broadcast'
- PEERTUBE_MOBILE_APP_URL=
-
- peertube_variables=(PEERTUBE_DOMAIN_NAME
- PEERTUBE_CODE
- PEERTUBE_ADMIN_PASSWORD
- ONION_ONLY
- DDNS_PROVIDER
- MY_USERNAME
- ARCHITECTURE
- MY_EMAIL_ADDRESS)
-
- function peertube_import_from_syncthing {
- peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
- nodecmd='node'
-
- if [[ "$ONION_ONLY" != 'no' ]]; then
- peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
- nodecmd='torsocks node'
- fi
-
- { echo '#!/bin/bash';
- echo '';
- echo 'LOCKFILE=/tmp/.peertube.lock';
- echo '';
- echo 'if [ -f /root/.peertube.lock ]; then';
- echo " lockctr=\$(cat \$LOCKFILE)";
- echo " lockctr=\$((lockctr+1))";
- echo " echo \"\$lockctr\" > \$LOCKFILE";
- echo " if [ \$lockctr -ge 30 ]; then";
- echo " rm \$LOCKFILE";
- echo ' else';
- echo ' exit 0';
- echo ' fi';
- echo 'fi';
- echo '';
- echo "MY_USERNAME=\$(cat /root/${PROJECT_NAME}.cfg | grep MY_USERNAME | awk -F '=' '{print \$2}')";
- echo "if [ ! \"\$MY_USERNAME\" ]; then";
- echo ' exit 0';
- echo 'fi';
- echo '';
- echo "search_dir=/home/\$MY_USERNAME/Sync/peertube_upload";
- echo "if [ ! -f \$search_dir/login.txt ]; then";
- echo ' exit 0';
- echo 'fi';
- echo "import_script=${PEERTUBE_DIR}/dist/server/tools/upload.js";
- echo "if [ ! -f \$import_script ]; then";
- echo ' exit 0';
- echo 'fi';
- echo '';
- echo "peertubedomain=\"$peertubedomain\"";
- echo "peertubeuser=\$(sed -n 1p < \"\$search_dir/login.txt\")";
- echo "peertubepassword=\$(sed -n 2p < \"\$search_dir/login.txt\")";
- echo 'peertubensfw=';
- echo "if grep -q 'nsfw' \"\$search_dir/login.txt\"; then";
- echo " peertubensfw='--nsfw'";
- echo 'fi';
- echo "if grep -q 'NSFW' \"\$search_dir/login.txt\"; then";
- echo " peertubensfw='--nsfw'";
- echo 'fi';
- echo '';
- echo "peertubeprivate='-P 3'";
- echo "if grep -q 'public' \"\$search_dir/login.txt\"; then";
- echo " peertubeprivate='-P 1'";
- echo 'fi';
- echo "if grep -q 'Public' \"\$search_dir/login.txt\"; then";
- echo " peertubeprivate='-P 1'";
- echo 'fi';
- echo '';
- echo 'failed_uploads=0';
- echo '';
- echo "cd ${PEERTUBE_DIR} || exit 32468356";
- echo "echo \"0\" > \$LOCKFILE";
- echo '';
- echo "for video_file in \$search_dir/*; do";
- echo " if [[ \"\$video_file\" == *'.ogv' || \"\$video_file\" == *'.mp4' || \"\$video_file\" == *'.webm' ]]; then";
- echo " if ! grep -q \"\$video_file\" /root/.peertube_uploaded; then";
- echo " peertubetitle=\$(basename \"\$video_file\" | awk -F '.' '{print \$1}' | sed 's|_| |g' | sed 's|-| |g')";
- echo " if $nodecmd \$import_script -n \"\$peertubetitle\" \$peertubensfw \$peertubeprivate -u \"\$peertubedomain\" -U \"\$peertubeuser\" --password \"\$peertubepassword\" -f \"\$video_file\"; then";
- echo " echo \"\$video_file\" >> /root/.peertube_uploaded";
- echo " rm \$LOCKFILE";
- echo " exit 0";
- echo ' else';
- echo " failed_uploads=\$((failed_uploads+1))";
- echo " if [ \$failed_uploads -gt 1 ]; then";
- echo " rm \$LOCKFILE";
- echo ' exit 0';
- echo ' fi';
- echo ' fi';
- echo ' fi';
- echo ' fi';
- echo 'done';
- echo '';
- echo "rm \$LOCKFILE"; } > /usr/bin/peertubesync
-
- chmod +x /usr/bin/peertubesync
- cron_add_mins 1 /usr/bin/peertubesync
- }
-
- function peertube_create_database {
- if [ -f "$IMAGE_PASSWORD_FILE" ]; then
- PEERTUBE_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
- else
- if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
- PEERTUBE_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
- fi
- fi
- if [ ! "$PEERTUBE_ADMIN_PASSWORD" ]; then
- return
- fi
-
- systemctl restart postgresql
- run_system_query_postgresql "CREATE USER peertube WITH PASSWORD '$PEERTUBE_ADMIN_PASSWORD';"
- run_system_query_postgresql "CREATE DATABASE peertube OWNER peertube;"
- run_system_query_postgresql "GRANT ALL PRIVILEGES ON DATABASE peertube to peertube;"
- run_system_query_postgresql "set statement_timeout to 40000;"
- }
-
- function logging_on_peertube {
- echo -n ''
- }
-
- function logging_off_peertube {
- echo -n ''
- }
-
- function remove_user_peertube {
- echo -n ''
- # remove_username="$1"
- }
-
- function add_user_peertube {
- if [[ $(app_is_installed peertube) == "0" ]]; then
- echo '0'
- return
- fi
-
- # new_username="$1"
- # new_user_password="$2"
-
- echo '0'
- }
-
- function install_interactive_peertube {
- if [ ! "$ONION_ONLY" ]; then
- ONION_ONLY='no'
- fi
-
- if [[ $ONION_ONLY != "no" ]]; then
- PEERTUBE_DOMAIN_NAME='peertube.local'
- write_config_param "PEERTUBE_DOMAIN_NAME" "$PEERTUBE_DOMAIN_NAME"
- else
- function_check interactive_site_details
- interactive_site_details "peertube" "PEERTUBE_DOMAIN_NAME" "PEERTUBE_CODE"
- fi
- APP_INSTALLED=1
- }
-
- function peertube_set_admin_email {
- read_config_param "$MY_EMAIL_ADDRESS"
- data=$(mktemp 2>/dev/null)
- dialog --title $"Set PeerTube administrator email address" \
- --backtitle $"Freedombone Control Panel" \
- --inputbox $"Admin email address" 8 75 "$MY_EMAIL_ADDRESS" 2>"$data"
- sel=$?
- case $sel in
- 0) peertube_email=$(<"$data")
- if [[ "$peertube_email" != *' '* && "$peertube_email" != *','* && "$peertube_email" != *';'* && "$peertube_email" == *'@'* && "$peertube_email" == *'.'* ]]; then
- if [ ${#peertube_email} -gt 8 ]; then
- sed -i "s|email:.*|email: '${peertube_email}'|g" $PEERTUBE_DIR/config/production.yaml
- systemctl restart peertube
- dialog --title $"Set PeerTube administrator email address" \
- --msgbox $"Set to $peertube_email" 6 75
- fi
- fi
- ;;
- esac
- rm -f "$data"
- }
-
- function peertube_disable_signups {
- dialog --title $"Disable PeerTube signups" \
- --backtitle $"Freedombone Control Panel" \
- --yesno $"\\nDo you wish to disable further PeerTube signups?" 8 75
- sel=$?
- case $sel in
- 0) sed -i "0,/enabled:.*/s//enabled: false/" $PEERTUBE_DIR/config/production.yaml;;
- 1) sed -i "0,/enabled:.*/s//enabled: true/" $PEERTUBE_DIR/config/production.yaml;;
- 255) return;;
- esac
-
- systemctl restart peertube
- }
-
- function peertube_import_from_file {
- read_config_param MY_USERNAME
- read_config_param PEERTUBE_DOMAIN_NAME
- read_config_param ONION_ONLY
-
- data2=$(mktemp 2>/dev/null)
- dialog --backtitle $"Freedombone Control Panel" \
- --title $"Import Video from file" \
- --form $"Enter your PeerTube login details and video title" 10 65 4 \
- $"Username:" 1 1 "$MY_USERNAME" 1 18 16 15 \
- $"Password:" 2 1 "" 2 18 40 10000 \
- $"Video Title:" 3 1 "" 3 18 40 1000 \
- $"NSFW:" 4 1 $"no" 4 18 4 4 \
- 2> "$data2"
- sel=$?
- case $sel in
- 1) rm -f "$data2"
- return;;
- 255) rm -f "$data2"
- return;;
- esac
- peertubeuser=$(sed -n 1p < "$data2")
- peertubepassword=$(sed -n 2p < "$data2")
- peertubetitle=$(sed -n 3p < "$data2")
- peertubensfw=$(sed -n 4p < "$data2")
- rm -f "$data2"
-
- peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
- nodecmd='node'
-
- if [[ "$ONION_ONLY" != 'no' ]]; then
- peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
- nodecmd='torsocks node'
- fi
-
- selected_file=$(dialog --title "Choose the video file (select with spacebar)" --fselect "/home/$MY_USERNAME/" 30 60)
- if [ ! "$selected_file" ]; then
- return
- fi
- if [[ "$selected_file" != *'.ogv' && "$selected_file" != *'.mp4' && "$selected_file" != *'.webm' ]]; then
- dialog --title $"Import video from file" \
- --msgbox $"The video should be in ogv, mp4 or webm format" 6 75
- return
- fi
-
- cd $PEERTUBE_DIR || exit 32468356
- import_script=$PEERTUBE_DIR/dist/server/tools/upload.js
- if [ ! -f $import_script ]; then
- dialog --title $"Import videos" \
- --msgbox $"upload script was not found" 6 75
- return
- fi
-
- nsfwstr=
- if [[ "$peertubensfw" == *'y'* || "$peertubensfw" == *'Y'* ]]; then
- nsfwstr='--nsfw'
- fi
-
- titlestr=$(basename "$selected_file" | awk -F '.' '{print $1}' | sed 's|_| |g' | sed 's|-| |g')
- if [ "$peertubetitle" ]; then
- titlestr="-n \"$peertubetitle\""
- fi
-
- clear
- $nodecmd $import_script $nsfwstr "$titlestr" -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -f "$selected_file"
-
- dialog --title $"Import video from file" \
- --msgbox $"Video imported from $selected_file" 6 75
- }
-
- function peertube_import_videos {
- read_config_param MY_USERNAME
- read_config_param PEERTUBE_DOMAIN_NAME
- read_config_param ONION_ONLY
-
- data2=$(mktemp 2>/dev/null)
- dialog --backtitle $"Freedombone Control Panel" \
- --title $"Import Videos from legacy sites" \
- --form $"Enter a channel of video URL for YouTube/Vimeo/Dailymotion" 10 75 4 \
- $"Username:" 1 1 "$MY_USERNAME" 1 22 16 15 \
- $"Password:" 2 1 "" 2 22 50 10000 \
- $"Video/Channel URL:" 3 1 "" 3 22 50 10000 \
- 2> "$data2"
- sel=$?
- case $sel in
- 1) rm -f "$data2"
- return;;
- 255) rm -f "$data2"
- return;;
- esac
- peertubeuser=$(sed -n 1p < "$data2")
- peertubepassword=$(sed -n 2p < "$data2")
- video_url=$(sed -n 3p < "$data2")
- rm -f "$data2"
-
- peertubedomain="https://$PEERTUBE_DOMAIN_NAME"
- nodecmd='node'
-
- if [[ "$ONION_ONLY" != 'no' ]]; then
- peertubedomain="http://$(cat /var/lib/tor/hidden_service_peertube/hostname)"
- nodecmd='torsocks node'
- fi
-
- if [ ${#peertubeuser} -lt 3 ]; then
- dialog --title $"Import videos from legacy sites" \
- --msgbox $"Username was not valid" 6 75
- return
- fi
-
- if [ ${#peertubepassword} -lt 3 ]; then
- dialog --title $"Import videos from legacy sites" \
- --msgbox $"Password was not valid" 6 75
- return
- fi
-
- if [[ "$video_url" == *' '* || "$video_url" == *','* || "$video_url" == *'@'* ]]; then
- dialog --title $"Import videos from legacy sites" \
- --msgbox $"Video/channel URL was not valid" 6 75
- return
- fi
-
- if [ ${#video_url} -lt 8 ]; then
- dialog --title $"Import videos from legacy sites" \
- --msgbox $"Video/channel URL was not valid" 6 75
- return
- fi
-
- cd $PEERTUBE_DIR || exit 32468356
- import_script=$PEERTUBE_DIR/dist/server/tools/import-videos.js
- if [ ! -f $import_script ]; then
- dialog --title $"Import videos from legacy sites" \
- --msgbox $"import-videos script was not found" 6 75
- return
- fi
-
- clear
- $nodecmd $import_script -u "$peertubedomain" -U "$peertubeuser" --password "$peertubepassword" -t "$video_url"
-
- dialog --title $"Import videos from legacy sites" \
- --msgbox $"Video/s imported from $video_url" 6 75
- }
-
- function configure_interactive_peertube {
- W=(1 $"Set administrator email address"
- 2 $"Disable or enable signups"
- 3 $"Import videos from YouTube/Vimeo/Dailymotion"
- 4 $"Import video from file")
-
- while true
- do
- # shellcheck disable=SC2068
- 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)
-
- if [ ! "$selection" ]; then
- break
- fi
-
- case $selection in
- 1) peertube_set_admin_email;;
- 2) peertube_disable_signups;;
- 3) peertube_import_videos;;
- 4) peertube_import_from_file;;
- esac
- done
- }
-
- function change_password_peertube {
- # PEERTUBE_USERNAME="$1"
- PEERTUBE_PASSWORD="$2"
- if [ ${#PEERTUBE_PASSWORD} -lt 8 ]; then
- echo $'Peertube password is too short'
- return
- fi
- #"${PROJECT_NAME}-pass" -u "$PEERTUBE_USERNAME" -a peertube -p "$PEERTUBE_PASSWORD"
- }
-
- function reconfigure_peertube {
- echo -n ''
- }
-
- function upgrade_peertube {
- peertube_import_from_syncthing
-
- CURR_PEERTUBE_COMMIT=$(get_completion_param "peertube commit")
- if [[ "$CURR_PEERTUBE_COMMIT" == "$PEERTUBE_COMMIT" ]]; then
- return
- fi
-
- read_config_param PEERTUBE_DOMAIN_NAME
- systemctl stop peertube
- cd "$PEERTUBE_DIR" || exit 7824552627
-
- function_check set_repo_commit
- set_repo_commit $PEERTUBE_DIR "peertube commit" "$PEERTUBE_COMMIT" $PEERTUBE_REPO
-
- if ! npm install -g yarn@1.5.1; then
- echo $'Failed to install yarn'
- exit 79353234
- fi
- yarn add -D webpack --network-concurrency 1
- if ! yarn install; then
- echo $'Failed to run yarn install'
- exit 63754235
- fi
- if ! npm install -g npm@4; then
- # https://github.com/KraigM/homebridge-harmonyhub/issues/119
- echo $'Failed to downgrade npm'
- npm install -g "npm@${NPM_VERSION}"
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- exit 3476835
- fi
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- if ! npm install; then
- echo $'Failed to install peertube'
- npm install -g "npm@${NPM_VERSION}"
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- exit 7835243
- fi
- if ! npm install -g "npm@${NPM_VERSION}"; then
- echo $'Failed to restore npm after downgrade'
- exit 5737583
- fi
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- npm run build
-
- # This doesn't appear to work
- #sudo -u peertube ./upgrade.sh $PEERTUBE_DIR
-
- chown -R peertube:peertube $PEERTUBE_DIR
- systemctl start peertube
- }
-
- function backup_local_peertube {
- PEERTUBE_DOMAIN_NAME='peertube.local'
- if grep -q "peertube domain" "$COMPLETION_FILE"; then
- PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
- fi
-
- systemctl stop peertube
- USE_POSTGRESQL=1
- function_check backup_database_to_usb
- backup_database_to_usb peertube
- systemctl start peertube
-
- peertube_path=$PEERTUBE_DIR/videos
- if [ -d $peertube_path ]; then
- suspend_site "${PEERTUBE_DOMAIN_NAME}"
- systemctl stop peertube
- backup_directory_to_usb $peertube_path peertubevideos
- systemctl start peertube
- restart_site
- fi
- }
-
- function restore_local_peertube {
- PEERTUBE_DOMAIN_NAME='peertube.local'
- if grep -q "peertube domain" "$COMPLETION_FILE"; then
- PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
- fi
- if [ "$PEERTUBE_DOMAIN_NAME" ]; then
- suspend_site "${PEERTUBE_DOMAIN_NAME}"
- systemctl stop peertube
-
- USE_POSTGRESQL=1
- restore_database peertube
-
- temp_restore_dir=/root/temppeertubevideos
- function_check restore_directory_from_usb
- restore_directory_from_usb $temp_restore_dir peertubevideos
- if [ -d $temp_restore_dir ]; then
- if [ -d $temp_restore_dir$PEERTUBE_DIR/videos ]; then
- cp -r $temp_restore_dir$PEERTUBE_DIR/videos/* $PEERTUBE_DIR/videos/
- else
- cp -r $temp_restore_dir/* $PEERTUBE_DIR/videos/
- fi
- chown -R peertube:peertube $PEERTUBE_DIR
- rm -rf $temp_restore_dir
- fi
-
- systemctl start peertube
- restart_site
- fi
- }
-
- function backup_remote_peertube {
- PEERTUBE_DOMAIN_NAME='peertube.local'
- if grep -q "peertube domain" "$COMPLETION_FILE"; then
- PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
- fi
-
- systemctl stop peertube
- USE_POSTGRESQL=1
- function_check backup_database_to_friend
- backup_database_to_friend peertube
- systemctl start peertube
-
- temp_backup_dir=$PEERTUBE_DIR/videos
- if [ -d $temp_backup_dir ]; then
- systemctl stop peertube
- suspend_site "${PEERTUBE_DOMAIN_NAME}"
- backup_directory_to_friend $temp_backup_dir peertubevideos
- restart_site
- systemctl start peertube
- else
- echo $"Peertube domain specified but not found in $temp_backup_dir"
- exit 6383523
- fi
- }
-
- function restore_remote_peertube {
- PEERTUBE_DOMAIN_NAME='peertube.local'
- if grep -q "peertube domain" "$COMPLETION_FILE"; then
- PEERTUBE_DOMAIN_NAME=$(get_completion_param "peertube domain")
- fi
- suspend_site "${PEERTUBE_DOMAIN_NAME}"
-
- systemctl stop peertube
-
- # shellcheck disable=SC2034
- USE_POSTGRESQL=1
- function_check restore_database_from_friend
- restore_database_from_friend peertube
-
- temp_restore_dir=/root/temppeertubevideos
- function_check restore_directory_from_friend
- restore_directory_from_friend $temp_restore_dir peertubevideos
- if [ -d $temp_restore_dir ]; then
- if [ -d $temp_restore_dir$PEERTUBE_DIR/videos ]; then
- cp -r $temp_restore_dir$PEERTUBE_DIR/videos/* $PEERTUBE_DIR/videos/
- else
- cp -r $temp_restore_dir/* $PEERTUBE_DIR/videos/
- fi
- chown -R peertube: $PEERTUBE_DIR
- rm -rf $temp_restore_dir
- fi
-
- systemctl start peertube
- restart_site
- }
-
- function remove_peertube {
- if [ ${#PEERTUBE_DOMAIN_NAME} -eq 0 ]; then
- return
- fi
-
- systemctl stop peertube
- systemctl disable peertube
- rm /etc/systemd/system/peertube.service
- systemctl daemon-reload
-
- function_check remove_nodejs
- remove_nodejs peertube
-
- read_config_param "PEERTUBE_DOMAIN_NAME"
- nginx_dissite "$PEERTUBE_DOMAIN_NAME"
- remove_certs "${PEERTUBE_DOMAIN_NAME}"
- if [ -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME" ]; then
- rm -f "/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME"
- fi
- if [ -d "/var/www/$PEERTUBE_DOMAIN_NAME" ]; then
- rm -rf "/var/www/$PEERTUBE_DOMAIN_NAME"
- fi
- remove_config_param PEERTUBE_DOMAIN_NAME
- remove_config_param PEERTUBE_CODE
- function_check remove_onion_service
- remove_onion_service peertube ${PEERTUBE_ONION_PORT}
- remove_completion_param "install_peertube"
- sed -i '/peertube/d' "$COMPLETION_FILE"
- sed -i '/peertubesync/d' /etc/crontab
-
- if [ -f /usr/bin/peertubesync ]; then
- rm /usr/bin/peertubesync
- fi
- if [ -f /root/peertube_uploaded ]; then
- rm /root/peertube_uploaded
- fi
-
- function_check drop_database_postgresql
- drop_database_postgresql peertube peertube
-
- groupdel -f peertube
- userdel -r peertube
-
- if [ -d $PEERTUBE_DIR ]; then
- rm -rf $PEERTUBE_DIR
- fi
-
- function_check remove_ddns_domain
- remove_ddns_domain "$PEERTUBE_DOMAIN_NAME"
- }
-
- function peertube_setup_web {
- peertube_nginx_file=/etc/nginx/sites-available/$PEERTUBE_DOMAIN_NAME
-
- if [[ $ONION_ONLY == "no" ]]; then
- { echo 'server {';
- echo ' listen 80;';
- echo ' listen [::]:80;';
- echo " server_name $PEERTUBE_DOMAIN_NAME;";
- echo " rewrite ^ https://\$server_name\$request_uri? permanent;";
- echo '}';
- echo '';
- echo 'server {';
- echo ' listen 443 ssl http2;';
- echo ' #listen [::]:443 ssl http2;';
- echo " server_name $PEERTUBE_DOMAIN_NAME;";
- echo ''; } > "$peertube_nginx_file"
- function_check nginx_ssl
- nginx_ssl "$PEERTUBE_DOMAIN_NAME" mobile
-
- function_check nginx_security_options
- nginx_security_options "$PEERTUBE_DOMAIN_NAME"
-
- { echo ' add_header Strict-Transport-Security max-age=15768000;';
- echo '';
- echo ' location / {';
- echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
- echo " proxy_set_header X-Real-IP \$remote_addr;";
- echo " proxy_set_header Host \$host;";
- echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
- echo '';
- echo ' # For the video upload';
- echo ' client_max_body_size 2G;';
- echo ' }';
- echo '';
- echo ' location /static/webseed {';
- echo " if (\$request_method = 'OPTIONS') {";
- echo " add_header 'Access-Control-Allow-Origin' '*';";
- echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
- 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';";
- echo " add_header 'Access-Control-Max-Age' 1728000;";
- echo " add_header 'Content-Type' 'text/plain charset=UTF-8';";
- echo " add_header 'Content-Length' 0;";
- echo ' return 204;';
- echo ' }';
- echo '';
- echo " if (\$request_method = 'GET') {";
- echo " add_header 'Access-Control-Allow-Origin' '*';";
- echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
- 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';";
- echo ' }';
- echo '';
- echo " alias $PEERTUBE_DIR/videos;";
- echo ' }';
- echo '';
- echo ' # Websocket tracker';
- echo ' location /tracker/socket {';
- echo ' # Peers send a message to the tracker every 15 minutes';
- echo ' # Dont close the websocket before this time';
- echo ' proxy_read_timeout 1200s;';
- echo " proxy_set_header Upgrade \$http_upgrade;";
- echo ' proxy_set_header Connection "upgrade";';
- echo ' proxy_http_version 1.1;';
- echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
- echo " proxy_set_header Host \$host;";
- echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
- echo ' }';
- echo '}'; } >> "$peertube_nginx_file"
- else
- echo -n '' > "$peertube_nginx_file"
- fi
- { echo 'server {';
- echo " listen 127.0.0.1:$PEERTUBE_ONION_PORT default_server;";
- echo " server_name $PEERTUBE_ONION_HOSTNAME;";
- echo '';
- echo ' location / {';
- echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
- echo " proxy_set_header X-Real-IP \$remote_addr;";
- echo " proxy_set_header Host \$host;";
- echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
- echo '';
- echo ' # For the video upload';
- echo ' client_max_body_size 2G;';
- echo ' }';
- echo '';
- echo ' location /static/webseed {';
- echo " if (\$request_method = 'OPTIONS') {";
- echo " add_header 'Access-Control-Allow-Origin' '*';";
- echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
- 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';";
- echo " add_header 'Access-Control-Max-Age' 1728000;";
- echo " add_header 'Content-Type' 'text/plain charset=UTF-8';";
- echo " add_header 'Content-Length' 0;";
- echo ' return 204;';
- echo ' }';
- echo '';
- echo " if (\$request_method = 'GET') {";
- echo " add_header 'Access-Control-Allow-Origin' '*';";
- echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
- 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';";
- echo ' }';
- echo '';
- echo " alias $PEERTUBE_DIR/videos;";
- echo ' }';
- echo '';
- echo ' # Websocket tracker';
- echo ' location /tracker/socket {';
- echo ' # Peers send a message to the tracker every 15 minutes';
- echo ' # Dont close the websocket before this time';
- echo ' proxy_read_timeout 1200s;';
- echo " proxy_set_header Upgrade \$http_upgrade;";
- echo ' proxy_set_header Connection "upgrade";';
- echo ' proxy_http_version 1.1;';
- echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
- echo " proxy_set_header Host \$host;";
- echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
- echo ' }';
- echo '}'; } >> "$peertube_nginx_file"
-
- # CSP currently causes an error
- sed -i '/Content-Security-Policy/d' "$peertube_nginx_file"
-
- function_check create_site_certificate
- create_site_certificate "$PEERTUBE_DOMAIN_NAME" 'yes'
-
- function_check nginx_ensite
- nginx_ensite "$PEERTUBE_DOMAIN_NAME"
- }
-
- function mesh_peertube_setup_web {
- # shellcheck disable=SC2154
- peertube_nginx_file=$rootdir/etc/nginx/sites-available/peertube
-
- { echo 'server {';
- echo " listen $MESH_PEERTUBE_PORT http2;";
- echo " listen [::]:\$MESH_PEERTUBE_PORT http2;";
- echo " server_name \$HOSTNAME;";
- echo '';
- echo ' location / {';
- echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
- echo " proxy_set_header X-Real-IP \$remote_addr;";
- echo " proxy_set_header Host \$host;";
- echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
- echo '';
- echo ' # For the video upload';
- echo ' client_max_body_size 2G;';
- echo ' }';
- echo '';
- echo ' location /static/webseed {';
- echo " if (\$request_method = 'OPTIONS') {";
- echo " add_header 'Access-Control-Allow-Origin' '*';";
- echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
- 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';";
- echo " add_header 'Access-Control-Max-Age' 1728000;";
- echo " add_header 'Content-Type' 'text/plain charset=UTF-8';";
- echo " add_header 'Content-Length' 0;";
- echo ' return 204;';
- echo ' }';
- echo '';
- echo " if (\$request_method = 'GET') {";
- echo " add_header 'Access-Control-Allow-Origin' '*';";
- echo " add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';";
- 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';";
- echo ' }';
- echo '';
- echo " alias $PEERTUBE_DIR/videos;";
- echo ' }';
- echo '';
- echo ' # Websocket tracker';
- echo ' location /tracker/socket {';
- echo ' # Peers send a message to the tracker every 15 minutes';
- echo ' # Dont close the websocket before this time';
- echo ' proxy_read_timeout 1200s;';
- echo " proxy_set_header Upgrade \$http_upgrade;";
- echo " proxy_set_header Connection \"upgrade\";";
- echo ' proxy_http_version 1.1;';
- echo " proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;";
- echo " proxy_set_header Host \$host;";
- echo " proxy_pass http://localhost:${PEERTUBE_PORT};";
- echo ' }';
- echo '}'; } > "$peertube_nginx_file"
- }
-
- function peertube_create_config {
- peertube_prefix=$1
-
- peertube_config_file=$peertube_prefix$PEERTUBE_DIR/config/production.yaml
-
- { echo 'listen:';
- echo " port: $PEERTUBE_PORT";
- echo '';
- echo '# Correspond to your reverse proxy "listen" configuration';
- echo 'webserver:'; } > "$peertube_config_file"
- if [ ! "$peertube_prefix" ]; then
- if [[ "$ONION_ONLY" == 'no' ]]; then
- { echo ' https: true';
- echo " hostname: '$PEERTUBE_DOMAIN_NAME'";
- echo ' port: 443'; } >> "$peertube_config_file"
- else
- { echo ' https: false';
- echo " hostname: '$PEERTUBE_ONION_HOSTNAME'";
- echo ' port: 80'; } >> "$peertube_config_file"
- fi
- else
- { echo ' https: false';
- echo " hostname: ''";
- echo " port: $MESH_PEERTUBE_PORT"; } >> "$peertube_config_file"
- fi
- { echo '';
- echo '# Your database name will be "peertube"+database.suffix';
- echo 'database:';
- echo " hostname: 'localhost'";
- echo ' port: 5432';
- echo " suffix: ''";
- echo " username: 'peertube'"; } >> "$peertube_config_file"
- if [ ! "$peertube_prefix" ]; then
- echo " password: '$PEERTUBE_ADMIN_PASSWORD'" >> "$peertube_config_file"
- else
- echo " password: ''" >> "$peertube_config_file"
- fi
- { echo '';
- echo '# From the project root directory';
- echo 'storage:';
- echo " certs: 'certs/'";
- echo " videos: 'videos/'";
- echo " logs: 'logs/'";
- echo " previews: 'previews/'";
- echo " thumbnails: 'thumbnails/'";
- echo " torrents: 'torrents/'";
- echo " cache: 'cache/'";
- echo '';
- echo 'cache:';
- echo ' previews:';
- echo ' size: 10 # Max number of previews you want to cache';
- echo '';
- echo 'admin:';
- # This is deliberately a dummy email address
- echo " email: 'testuser@testdomain.net'";
- echo '';
- echo 'signup:';
- echo ' enabled: true';
- echo ' limit: 5 # When the limit is reached, registrations are disabled. -1 == unlimited';
- echo '';
- echo 'user:';
- echo ' # Default value of maximum video BYTES the user can upload (does not take into account transcoded files).';
- echo ' # -1 == unlimited';
- echo ' video_quota: -1';
- echo '';
- echo '# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag';
- echo '# Uses a lot of CPU!';
- echo 'transcoding:';
- echo ' enabled: false';
- echo ' threads: 2';
- echo ' resolutions: # Only created if the original video has a higher resolution';
- echo ' 240p: true';
- echo ' 360p: false';
- echo ' 480p: false';
- echo ' 720p: false';
- echo ' 1080p: false'; } >> "$peertube_config_file"
- }
-
- function mesh_install_peertube {
- # shellcheck disable=SC2153
- if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
- return
- fi
- if [[ "$ARCHITECTURE" != 'x86_64' && "$ARCHITECTURE" != 'amd64' && "$ARCHITECTURE" != 'i386' ]]; then
- return
- fi
-
- chroot "$rootdir" apt-get -yq install ffmpeg curl redis-tools redis-server
-
- function_check install_postgresql
- install_postgresql
-
- if [ -d "$rootdir$PEERTUBE_DIR" ]; then
- rm -rf "$rootdir$PEERTUBE_DIR"
- fi
-
- git clone "$PEERTUBE_REPO" "$rootdir$PEERTUBE_DIR"
-
- chroot "$rootdir" groupadd peertube
- chroot "$rootdir" useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
-
- cd "$rootdir$PEERTUBE_DIR" || exit 246824524
- git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
-
- get_npm_arch
-
- cat <<EOF > "$rootdir/usr/bin/install_peertube"
- #!/bin/bash
- cd $PEERTUBE_DIR
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
- apt-get -y update
- apt-get -yq install yarn
-
- #if ! npm install --arch=$NPM_ARCH -g yarn@1.5.1; then
- # echo $'PeerTube Failed to install yarn'
- # exit 79353234
- #fi
- #if ! npm install --arch=$NPM_ARCH webpack@3.10.0 --no-optional; then
- # echo $'PeerTube failed to install webpack'
- # exit 68386353
- #fi
- yarn install
- yarn run build:prod
- if ! yarn add -D webpack; then
- echo $'PeerTube failed to add webpack'
- exit 67342823
- fi
- if ! yarn install --ignore-optional; then
- echo $'PeerTube failed to run yarn install'
- exit 63754235
- fi
- if ! npm install --arch=$NPM_ARCH -g npm@4; then
- # https://github.com/KraigM/homebridge-harmonyhub/issues/119
- echo $'Failed to downgrade npm'
- exit 3476835
- fi
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- if ! npm install --arch=$NPM_ARCH; then
- echo $'PeerTube failed to install peertube'
- exit 7835243
- fi
- if ! npm install --arch=$NPM_ARCH -g "npm@${NPM_VERSION}"; then
- echo $'Failed to restore npm after downgrade'
- exit 5737583
- fi
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- if ! npm run build --arch=$NPM_ARCH; then
- echo $'PeerTube failed to build peertube'
- exit 5293593
- fi
- EOF
- chmod +x "$rootdir/usr/bin/install_peertube"
- if ! chroot "$rootdir" /usr/bin/install_peertube; then
- echo $'PeerTube install failed'
- exit 735638
- fi
-
- { echo '[Unit]';
- echo 'Description=PeerTube Decentralized video streaming platform';
- echo 'After=syslog.target';
- echo 'After=network.target';
- echo '';
- echo '[Service]';
- echo 'User=peertube';
- echo 'Group=peertube';
- echo "WorkingDirectory=$PEERTUBE_DIR";
- echo "ExecStart=/usr/local/bin/npm start";
- echo "ExecStop=/usr/local/bin/npm stop";
- echo 'StandardOutput=syslog';
- echo 'StandardError=syslog';
- echo 'SyslogIdentifier=peertube';
- echo 'Restart=always';
- echo "Environment=NODE_ENV=production";
- echo '';
- echo '[Install]';
- echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/peertube.service"
-
- peertube_create_config "$rootdir"
-
- chroot "$rootdir" chown -R peertube:peertube $PEERTUBE_DIR
-
- mesh_peertube_setup_web
- }
-
- function install_peertube {
- if [[ $VARIANT == "mesh"* ]]; then
- mesh_install_peertube
- return
- fi
- if [[ $ARCHITECTURE != 'x86_64' && $ARCHITECTURE != 'amd64' ]]; then
- return
- fi
-
- if [ ! $ONION_ONLY ]; then
- ONION_ONLY='no'
- fi
-
- if [ ! "$PEERTUBE_DOMAIN_NAME" ]; then
- echo $'The peertube domain name was not specified'
- exit 783523
- fi
-
- apt-get -yq install ffmpeg redis-tools redis-server
-
- function_check install_postgresql
- install_postgresql
-
- if [ ! -d "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs" ]; then
- mkdir -p "/var/www/$PEERTUBE_DOMAIN_NAME/htdocs"
- fi
-
- if [ -d $PEERTUBE_DIR ]; then
- rm -rf $PEERTUBE_DIR
- fi
-
- groupadd peertube
- useradd -c "PeerTube system account" -d $PEERTUBE_DIR -m -r -g peertube peertube
-
- peertube_create_database
-
- function_check install_nodejs
- install_nodejs peertube
-
- if [ -d /repos/peertube ]; then
- mkdir -p $PEERTUBE_DIR
- cp -r -p /repos/peertube/. $PEERTUBE_DIR
- cd "$PEERTUBE_DIR" || exit 642874682
- git pull
- else
- function_check git_clone
- git_clone $PEERTUBE_REPO $PEERTUBE_DIR
- fi
-
- cd "$PEERTUBE_DIR" || exit 27492742
- git checkout $PEERTUBE_COMMIT -b $PEERTUBE_COMMIT
- set_completion_param "peertube commit" "$PEERTUBE_COMMIT"
-
- if ! npm install -g yarn@1.5.1; then
- echo $'Failed to install yarn'
- exit 79353234
- fi
- yarn add -D webpack --network-concurrency 1
- if ! yarn install; then
- echo $'Failed to run yarn install'
- exit 63754235
- fi
- if ! npm install -g npm@4; then
- # https://github.com/KraigM/homebridge-harmonyhub/issues/119
- echo $'Failed to downgrade npm'
- exit 3476835
- fi
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- if ! npm install; then
- echo $'Failed to install peertube'
- exit 7835243
- fi
- if ! npm install -g "npm@${NPM_VERSION}"; then
- echo $'Failed to restore npm after downgrade'
- exit 5737583
- fi
- cp /root/.npm-global/bin/npm /usr/local/bin/npm
- npm run build
-
- PEERTUBE_ONION_HOSTNAME=$(add_onion_service peertube 80 ${PEERTUBE_ONION_PORT})
-
- { echo '[Unit]';
- echo 'Description=PeerTube Decentralized video streaming platform';
- echo 'After=syslog.target';
- echo 'After=network.target';
- echo '';
- echo '[Service]';
- echo 'User=peertube';
- echo 'Group=peertube';
- echo "WorkingDirectory=$PEERTUBE_DIR";
- echo "ExecStart=/usr/local/bin/npm start";
- echo "ExecStop=/usr/local/bin/npm stop";
- echo 'StandardOutput=syslog';
- echo 'StandardError=syslog';
- echo 'SyslogIdentifier=peertube';
- echo 'Restart=always';
- echo "Environment=NODE_ENV=production";
- echo '';
- echo '[Install]';
- echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/peertube.service
-
- peertube_create_config
-
- chown -R peertube:peertube $PEERTUBE_DIR
-
- peertube_setup_web
-
- "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a peertube -p "$PEERTUBE_ADMIN_PASSWORD"
-
- function_check add_ddns_domain
- add_ddns_domain "$PEERTUBE_DOMAIN_NAME"
-
- systemctl enable peertube
- systemctl daemon-reload
- systemctl start peertube
- systemctl restart nginx
-
- # wait for the database to get generated after initial peertube daemon start
- sleep 10
-
- # update the admin email address after creation of the database
- sed -i "s|email: .*|email: '$MY_EMAIL_ADDRESS'|g" $PEERTUBE_DIR/config/production.yaml
-
- peertube_import_from_syncthing
-
- set_completion_param "peertube domain" "$PEERTUBE_DOMAIN_NAME"
- APP_INSTALLED=1
- }
-
- # NOTE: deliberately no exit 0
|