Newer
Older
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# scuttlebot pub application
# https://scuttlebot.io
# Problem: on occasion uses 100% of the CPU, severely impacting other services
#
# License
# =======
#
# Copyright (C) 2017 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/>.
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=0
SHOW_ICANN_ADDRESS_ON_ABOUT=0
SCUTTLEBOT_VERSION='9.8.0'
invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
clear
echo -e '\n\nYour Scuttlebot invite code is:\n\n'${invite_string}'\n\n'
read -n1 -r -p $"Press any key to continue..." key
}
function configure_interactive_scuttlebot {
while true
do
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Scuttlebot" \
--radiolist $"Choose an operation:" 10 50 2 \
1 $"Create an invite" off \
2 $"Exit" on 2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
case $(cat $data) in
1) scuttlebot_create_invite;;
2) break;;
esac
done
}
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function remove_user_scuttlebot {
remove_username="$1"
}
function add_user_scuttlebot {
new_username="$1"
new_user_password="$2"
echo '0'
}
function install_interactive_scuttlebot {
echo -n ''
APP_INSTALLED=1
}
function change_password_scuttlebot {
new_username="$1"
new_user_password="$2"
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 {
if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
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
npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save
if [ ! "$?" = "0" ]; then
return
fi
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
cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
systemctl start scuttlebot
fi
}
function backup_remote_scuttlebot {
if [ -d /etc/scuttlebot/.ssb ]; then
systemctl stop scuttlebot
function_check backup_directory_to_friend
backup_directory_to_friend /etc/scuttlebot/.ssb scuttlebot
systemctl start scuttlebot
fi
}
function restore_remote_scuttlebot {
if [ -d /etc/scuttlebot ]; then
systemctl stop scuttlebot
temp_restore_dir=/root/tempscuttlebot
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir scuttlebot
cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
systemctl start scuttlebot
fi
}
function remove_scuttlebot {
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
sed -i '/scuttlebot /d' $COMPLETION_FILE
}
function install_scuttlebot {
function_check install_nodejs
install_nodejs scuttlebot
npm install -g scuttlebot@${SCUTTLEBOT_VERSION}
if [ ! -f /usr/local/bin/sbot ]; then
exit 528253
fi
if [ ! -d /etc/scuttlebot ]; then
mkdir -p /etc/scuttlebot
fi
# an unprivileged user to run as
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# daemon
echo '[Unit]' > /etc/systemd/system/scuttlebot.service
echo 'Description=Scuttlebot (messaging system)' >> /etc/systemd/system/scuttlebot.service
echo 'After=syslog.target' >> /etc/systemd/system/scuttlebot.service
echo 'After=network.target' >> /etc/systemd/system/scuttlebot.service
echo '' >> /etc/systemd/system/scuttlebot.service
echo '[Service]' >> /etc/systemd/system/scuttlebot.service
echo 'Type=simple' >> /etc/systemd/system/scuttlebot.service
echo 'User=scuttlebot' >> /etc/systemd/system/scuttlebot.service
echo 'Group=scuttlebot' >> /etc/systemd/system/scuttlebot.service
echo "WorkingDirectory=/etc/scuttlebot" >> /etc/systemd/system/scuttlebot.service
echo 'ExecStart=/usr/local/bin/sbot server' >> /etc/systemd/system/scuttlebot.service
echo 'Restart=always' >> /etc/systemd/system/scuttlebot.service
echo 'Environment="USER=scuttlebot"' >> /etc/systemd/system/scuttlebot.service
echo '' >> /etc/systemd/system/scuttlebot.service
echo '[Install]' >> /etc/systemd/system/scuttlebot.service
echo 'WantedBy=multi-user.target' >> /etc/systemd/system/scuttlebot.service
chown -R scuttlebot:scuttlebot /etc/scuttlebot
# files gw_name myhostname mdns4_minimal [NOTFOUND=return] dns
sed -i "s|hosts:.*|hosts: files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
# start the daemon
systemctl enable scuttlebot.service
systemctl daemon-reload
systemctl start scuttlebot.service
sleep 3
if [ ! -d /etc/scuttlebot/.ssb ]; then
echo $'Scuttlebot config not generated'
exit 73528
fi
echo '{' > /etc/scuttlebot/.ssb/config
echo " \"host\": \"${DEFAULT_DOMAIN_NAME}\"," >> /etc/scuttlebot/.ssb/config
echo " \"port\": ${SCUTTLEBOT_PORT}," >> /etc/scuttlebot/.ssb/config
echo ' "timeout": 30000,' >> /etc/scuttlebot/.ssb/config
echo ' "pub": true,' >> /etc/scuttlebot/.ssb/config
echo ' "local": true,' >> /etc/scuttlebot/.ssb/config
echo ' "friends": {' >> /etc/scuttlebot/.ssb/config
echo ' "dunbar": 150,' >> /etc/scuttlebot/.ssb/config
echo ' "hops": 3' >> /etc/scuttlebot/.ssb/config
echo ' },' >> /etc/scuttlebot/.ssb/config
echo ' "gossip": {' >> /etc/scuttlebot/.ssb/config
echo ' "connections": 2' >> /etc/scuttlebot/.ssb/config
echo ' },' >> /etc/scuttlebot/.ssb/config
echo ' "master": [],' >> /etc/scuttlebot/.ssb/config
echo ' "logging": {' >> /etc/scuttlebot/.ssb/config
echo ' "level": "error"' >> /etc/scuttlebot/.ssb/config
echo ' }' >> /etc/scuttlebot/.ssb/config
echo '}' >> /etc/scuttlebot/.ssb/config
chown scuttlebot:scuttlebot /etc/scuttlebot/.ssb/config
systemctl restart scuttlebot.service
if ! grep -q "scuttlebot version:" ${COMPLETION_FILE}; then
echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> ${COMPLETION_FILE}
else
sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
fi
APP_INSTALLED=1
}
# NOTE: deliberately no exit 0