Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
# scuttlebot pub application. Enables nat traversal for SSB.
# This is deprecated for now because it appears that Patchwork
# Is moving to DHT invites, which presumably eliminates the
# need for separate pubs. Invites generated by scuttlebot
# are currently incompatible with the new DHT format.
#
#
# 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/>.
SHOW_CLEARNET_ADDRESS_ON_ABOUT=0
SCUTTLEBOT_ONION_PORT=8623
SCUTTLEBOT_SHORT_DESCRIPTION=$'Scuttlebot Pub'
SCUTTLEBOT_DESCRIPTION=$'Scuttlebot Pub'
SCUTTLEBOT_MOBILE_APP_URL='https://f-droid.org/en/packages/se.manyver/'
function change_default_domain_name_scuttlebot {
new_default_domain_name="$1"
{ echo '{';
echo " \"host\": \"${new_default_domain_name}\",";
echo ' "tor-only": false,'; } > /etc/scuttlebot/.ssb/config
systemctl restart scuttlebot
}
function logging_on_scuttlebot {
echo -n ''
}
function logging_off_scuttlebot {
echo -n ''
}
invite_string=$(su -c "/etc/scuttlebot/node_modules/.bin/sbot invite.create 1" - scuttlebot | sed 's/"//g')
if [ ! "$invite_string" ]; then
echo $'Unable to create scuttlebot invite'
fi
write_config_param SCUTTLEBOT_INVITE "$invite_string"
}
function scuttlebot_create_invite {
scuttlebot_create_single_invite
echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${SCUTTLEBOT_INVITE}\\n\\n"
read -n1 -r -p $"Press any key to continue..." key
}
function configure_interactive_scuttlebot {
# shellcheck disable=SC2068
selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Scuttlebot" --menu $"Choose an operation, or ESC to exit:" 10 60 2 "${W[@]}" 3>&2 2>&1 1>&3)
if [ ! "$selection" ]; then
break
fi
case $selection in
1) scuttlebot_create_invite;;
esac
done
}
# This doesn't have users
echo '0'
}
function install_interactive_scuttlebot {
if [[ $ONION_ONLY != "no" ]]; then
SCUTTLEBOT_DOMAIN_NAME='scuttlebot.local'
write_config_param "SCUTTLEBOT_DOMAIN_NAME" "$SCUTTLEBOT_DOMAIN_NAME"
else
function_check interactive_site_details
interactive_site_details scuttlebot
fi
APP_INSTALLED=1
}
function change_password_scuttlebot {
echo '0'
}
function reconfigure_scuttlebot {
if [ -d /etc/scuttlebot/.ssb ]; then
systemctl stop scuttlebot
rm -rf /etc/scuttlebot/.ssb
systemctl start scuttlebot
fi
}
function upgrade_scuttlebot {
return
fi
CURR_SCUTTLEBOT_VERSION=$(get_completion_param "scuttlebot version")
echo "scuttlebot current version: ${CURR_SCUTTLEBOT_VERSION}"
echo "scuttlebot app version: ${SCUTTLEBOT_VERSION}"
if [[ "${CURR_SCUTTLEBOT_VERSION}" == "${SCUTTLEBOT_VERSION}" ]]; then
return
fi
cat <<EOF > /usr/bin/upgrade_scuttlebot
#!/bin/bash
cd /etc/scuttlebot || exit 1
if ! npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save; then
exit 2
fi
exit 0
EOF
chmod +x /usr/bin/upgrade_scuttlebot
su -c '/usr/bin/upgrade_scuttlebot' - scuttlebot
rm /usr/bin/upgrade_scuttlebot
sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
}
function backup_local_scuttlebot {
if [ -d /etc/scuttlebot/.ssb ]; then
systemctl stop scuttlebot
function_check backup_directory_to_usb
backup_directory_to_usb /etc/scuttlebot/.ssb scuttlebot
systemctl start scuttlebot
fi
}
function restore_local_scuttlebot {
if [ -d /etc/scuttlebot ]; then
systemctl stop scuttlebot
temp_restore_dir=/root/tempscuttlebot
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir scuttlebot
if [ -d $temp_restore_dir/etc/scuttlebot/.ssb ]; then
cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
else
cp -r $temp_restore_dir/* /etc/scuttlebot/.ssb/*
fi
systemctl stop scuttlebot
systemctl disable scuttlebot
rm /etc/systemd/system/scuttlebot.service
userdel -r scuttlebot
if [ -d /etc/scuttlebot ]; then
rm -rf /etc/scuttlebot
fi
remove_completion_param install_scuttlebot
if [[ "$VARIANT" != "meshclient" && "$VARIANT" != "meshusb" ]]; then
return
fi
SCUTTLEBOT_ONION_HOSTNAME=
# shellcheck disable=SC2086
chroot "$rootdir" $INSTALL_PACKAGES libsodium23
if [ ! -d "$rootdir/etc/scuttlebot" ]; then
mkdir -p "$rootdir/etc/scuttlebot"
fi
# an unprivileged user to install and run as
chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
chroot "$rootdir" chown -R scuttlebot:scuttlebot /etc/scuttlebot
cd /etc/scuttlebot || exit 1
if ! npm install --arch=$NPM_ARCH scuttlebot@${SCUTTLEBOT_VERSION}; then
exit 2
EOF
chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
chroot "$rootdir" sudo -u scuttlebot /usr/bin/install_scuttlebot
if [ ! -f "$rootdir/etc/scuttlebot/node_modules/.bin/sbot" ]; then
echo $'Scuttlebot was not installed'
exit 528253
fi
# daemon
{ echo '[Unit]';
echo 'Description=Scuttlebot (messaging system)';
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=scuttlebot';
echo 'Group=scuttlebot';
echo "WorkingDirectory=/etc/scuttlebot";
echo 'ExecStart=/etc/scuttlebot/node_modules/scuttlebot/bin.js server';
echo 'PrivateTmp=true';
echo 'PrivateDevices=false';
echo 'NoNewPrivileges=true';
echo 'CapabilityBoundingSet=~CAP_SYS_ADMIN';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > "$rootdir/etc/systemd/system/scuttlebot.service"
function install_scuttlebutt-notification {
cat <<EOF > /usr/bin/install_scuttlebutt_notification
#!/bin/bash
if ! git clone https://github.com/ssbc/ssb-example-pm notification; then
echo $'ssb-example-pm was not cloned'
exit 2
fi
if [ ! -d /etc/scuttlebot/notification ]; then
echo $'/etc/scuttlebot/notification not found'
exit 3
fi
cd /etc/scuttlebot/notification || exit 4
npm install
exit 0
EOF
chmod +x /usr/bin/install_scuttlebutt_notification
su -c '/usr/bin/install_scuttlebutt_notification' - scuttlebot
rm /usr/bin/install_scuttlebutt_notification
if [ ! -f /etc/scuttlebot/notification/ssb-example-pm.js ]; then
echo $'ssb-example-pm.js was not cloned'
function install_scuttlebot {
function_check install_nodejs
install_nodejs scuttlebot
if [ -d /etc/scuttlebot ]; then
rm -rf /etc/scuttlebot
# an unprivileged user to install and run as
useradd -d /etc/scuttlebot/ scuttlebot
chown -R scuttlebot:scuttlebot /etc/scuttlebot
cat <<EOF > /usr/bin/install_scuttlebot
#!/bin/bash
cd /etc/scuttlebot || exit 1
if ! npm install scuttlebot@${SCUTTLEBOT_VERSION}; then
exit 2
fi
if ! npm install ssb-dht-invite@0.9.0; then
exit 3
fi
exit 0
EOF
chmod +x /usr/bin/install_scuttlebot
su -c '/usr/bin/install_scuttlebot' - scuttlebot
rm /usr/bin/install_scuttlebot
if [ ! -f /etc/scuttlebot/node_modules/.bin/sbot ]; then
echo $'Scuttlebot was not installed'
{ echo '[Unit]';
echo 'Description=Scuttlebot (messaging system)';
echo 'After=syslog.target';
echo 'After=network.target';
echo '';
echo '[Service]';
echo 'Type=simple';
echo 'User=scuttlebot';
echo 'Group=scuttlebot';
echo "WorkingDirectory=/etc/scuttlebot";
echo 'ExecStart=/etc/scuttlebot/node_modules/scuttlebot/bin.js server';
echo 'Restart=always';
echo 'Environment="USER=scuttlebot"';
echo '';
echo '[Install]';
echo 'WantedBy=multi-user.target'; } > /etc/systemd/system/scuttlebot.service
SCUTTLEBOT_ONION_HOSTNAME=$(add_onion_service scuttlebot 80 ${SCUTTLEBOT_ONION_PORT})
if [[ "$ONION_ONLY" == 'no' ]]; then
{ echo '{';
echo " \"host\": \"${DEFAULT_DOMAIN_NAME}\",";
echo ' "tor-only": false,'; } > /etc/scuttlebot/.ssb/config
else
{ echo '{';
echo " \"host\": \"${SCUTTLEBOT_ONION_HOSTNAME}\",";
echo ' "tor-only": true,'; } > /etc/scuttlebot/.ssb/config
fi
{ echo " \"port\": ${SCUTTLEBOT_PORT},";
echo ' "timeout": 30000,';
echo ' "pub": true,';
echo ' "local": true,';
echo ' "friends": {';
echo " \"dunbar\": ${SCUTTLEBOT_REPLICATE_NODES},";
echo ' "hops": 1';
echo ' },';
echo ' "gossip": {';
echo ' "connections": 2';
echo ' },';
echo ' "master": [],';
echo ' "logging": {';
echo ' "level": "error"';
echo ' }';
chown -R scuttlebot:scuttlebot /etc/scuttlebot
# start the daemon
systemctl enable scuttlebot.service
systemctl daemon-reload
if [ -f /etc/scuttlebot/.ssb/manifest.json ]; then
break
fi
ctr=$((ctr+1))
sleep 3
done
if [ ! -f /etc/scuttlebot/.ssb/manifest.json ]; then
echo $'scuttlebot manifest was not generated'
install_scuttlebutt-notification
if ! grep -q "scuttlebot version:" "${COMPLETION_FILE}"; then
echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> "${COMPLETION_FILE}"
sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" "${COMPLETION_FILE}"
fi
APP_INSTALLED=1
}
# NOTE: deliberately no exit 0