Browse Source

scuttlebot app

Bob Mottram 7 years ago
parent
commit
1048b39f65
1 changed files with 204 additions and 0 deletions
  1. 204
    0
      src/freedombone-app-scuttlebot

+ 204
- 0
src/freedombone-app-scuttlebot View File

@@ -0,0 +1,204 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# scuttlebot pub application
12
+# https://scuttlebot.io
13
+#
14
+# License
15
+# =======
16
+#
17
+# Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
18
+#
19
+# This program is free software: you can redistribute it and/or modify
20
+# it under the terms of the GNU Affero General Public License as published by
21
+# the Free Software Foundation, either version 3 of the License, or
22
+# (at your option) any later version.
23
+#
24
+# This program is distributed in the hope that it will be useful,
25
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+# GNU Affero General Public License for more details.
28
+#
29
+# You should have received a copy of the GNU Affero General Public License
30
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+
32
+VARIANTS='full full-vim chat'
33
+
34
+IN_DEFAULT_INSTALL=0
35
+SHOW_ON_ABOUT=0
36
+SHOW_ICANN_ADDRESS_ON_ABOUT=0
37
+
38
+SCUTTLEBOT_VERSION='9.8.0'
39
+
40
+scuttlebot_variables=(MY_USERNAME
41
+                      SYSTEM_TYPE)
42
+
43
+
44
+#function configure_interactive_scuttlebot {
45
+#    echo -n ''
46
+#}
47
+
48
+function remove_user_scuttlebot {
49
+    remove_username="$1"
50
+}
51
+
52
+function add_user_scuttlebot {
53
+    new_username="$1"
54
+    new_user_password="$2"
55
+    echo '0'
56
+}
57
+
58
+function install_interactive_scuttlebot {
59
+    echo -n ''
60
+    APP_INSTALLED=1
61
+}
62
+
63
+function change_password_scuttlebot {
64
+    new_username="$1"
65
+    new_user_password="$2"
66
+    echo '0'
67
+}
68
+
69
+function reconfigure_scuttlebot {
70
+    if [ -d /etc/scuttlebot/.ssb ]; then
71
+        systemctl stop scuttlebot
72
+        rm -rf /etc/scuttlebot/.ssb
73
+        systemctl start scuttlebot
74
+    fi
75
+}
76
+
77
+function upgrade_scuttlebot {
78
+    if ! grep -q 'scuttlebot version:' $COMPLETION_FILE; then
79
+        return
80
+    fi
81
+
82
+    CURR_SCUTTLEBOT_VERSION=$(get_completion_param "scuttlebot version")
83
+    echo "scuttlebot current version: ${CURR_SCUTTLEBOT_VERSION}"
84
+    echo "scuttlebot app version: ${SCUTTLEBOT_VERSION}"
85
+    if [[ "${CURR_SCUTTLEBOT_VERSION}" == "${SCUTTLEBOT_VERSION}" ]]; then
86
+        return
87
+    fi
88
+
89
+    npm upgrade -g scuttlebot@${SCUTTLEBOT_VERSION} --save
90
+    if [ ! "$?" = "0" ]; then
91
+        return
92
+    fi
93
+    sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
94
+}
95
+
96
+function backup_local_scuttlebot {
97
+    if [ -d /etc/scuttlebot/.ssb ]; then
98
+        systemctl stop scuttlebot
99
+        function_check backup_directory_to_usb
100
+        backup_directory_to_usb /etc/scuttlebot/.ssb scuttlebot
101
+        systemctl start scuttlebot
102
+    fi
103
+}
104
+
105
+function restore_local_scuttlebot {
106
+    if [ -d /etc/scuttlebot ]; then
107
+        systemctl stop scuttlebot
108
+        temp_restore_dir=/root/tempscuttlebot
109
+        function_check restore_directory_from_usb
110
+        restore_directory_from_usb $temp_restore_dir scuttlebot
111
+        cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
112
+        systemctl start scuttlebot
113
+    fi
114
+}
115
+
116
+function backup_remote_scuttlebot {
117
+    if [ -d /etc/scuttlebot/.ssb ]; then
118
+        systemctl stop scuttlebot
119
+        function_check backup_directory_to_friend
120
+        backup_directory_to_friend /etc/scuttlebot/.ssb scuttlebot
121
+        systemctl start scuttlebot
122
+    fi
123
+}
124
+
125
+function restore_remote_scuttlebot {
126
+    if [ -d /etc/scuttlebot ]; then
127
+        systemctl stop scuttlebot
128
+        temp_restore_dir=/root/tempscuttlebot
129
+        function_check restore_directory_from_friend
130
+        restore_directory_from_friend $temp_restore_dir scuttlebot
131
+        cp -r $temp_restore_dir/etc/scuttlebot/.ssb /etc/scuttlebot/
132
+        systemctl start scuttlebot
133
+    fi
134
+}
135
+
136
+function remove_scuttlebot {
137
+    systemctl stop scuttlebot
138
+    systemctl disable scuttlebot
139
+    rm /etc/systemd/system/scuttlebot.service
140
+
141
+    userdel -r scuttlebot
142
+
143
+    if [ -d /etc/scuttlebot ]; then
144
+        rm -rf /etc/scuttlebot
145
+    fi
146
+
147
+    remove_completion_param install_scuttlebot
148
+    sed -i '/scuttlebot /d' $COMPLETION_FILE
149
+}
150
+
151
+function install_scuttlebot {
152
+    function_check install_nodejs
153
+    install_nodejs scuttlebot
154
+
155
+    npm install -g scuttlebot@${SCUTTLEBOT_VERSION}
156
+    if [ ! -f /usr/local/bin/sbot ]; then
157
+        exit 528253
158
+    fi
159
+
160
+    if [ ! -d /etc/scuttlebot ]; then
161
+        mkdir -p /etc/scuttlebot
162
+    fi
163
+
164
+    # an unprivileged user to run as
165
+    useradd -d /etc/scuttlebot/ -s /bin/false scuttlebot
166
+
167
+    # daemon
168
+    echo '[Unit]' > /etc/systemd/system/scuttlebot.service
169
+    echo 'Description=Scuttlebot (messaging system)' >> /etc/systemd/system/scuttlebot.service
170
+    echo 'After=syslog.target' >> /etc/systemd/system/scuttlebot.service
171
+    echo 'After=network.target' >> /etc/systemd/system/scuttlebot.service
172
+    echo '' >> /etc/systemd/system/scuttlebot.service
173
+    echo '[Service]' >> /etc/systemd/system/scuttlebot.service
174
+    echo 'Type=simple' >> /etc/systemd/system/scuttlebot.service
175
+    echo 'User=scuttlebot' >> /etc/systemd/system/scuttlebot.service
176
+    echo 'Group=scuttlebot' >> /etc/systemd/system/scuttlebot.service
177
+    echo "WorkingDirectory=/etc/scuttlebot" >> /etc/systemd/system/scuttlebot.service
178
+    echo 'ExecStart=/usr/local/bin/sbot server' >> /etc/systemd/system/scuttlebot.service
179
+    echo 'Restart=always' >> /etc/systemd/system/scuttlebot.service
180
+    echo 'Environment="USER=scuttlebot"' >> /etc/systemd/system/scuttlebot.service
181
+    echo '' >> /etc/systemd/system/scuttlebot.service
182
+    echo '[Install]' >> /etc/systemd/system/scuttlebot.service
183
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/scuttlebot.service
184
+
185
+    chown -R scuttlebot:scuttlebot /etc/scuttlebot
186
+
187
+    # files gw_name myhostname mdns4_minimal [NOTFOUND=return] dns
188
+    sed -i "s|hosts:.*|hosts:          files mdns4_minimal dns mdns4 mdns|g" /etc/nsswitch.conf
189
+
190
+    # start the daemon
191
+    systemctl enable scuttlebot.service
192
+    systemctl daemon-reload
193
+    systemctl start scuttlebot.service
194
+
195
+    if ! grep -q "scuttlebot version:" ${COMPLETION_FILE}; then
196
+        echo "scuttlebot version:${SCUTTLEBOT_VERSION}" >> ${COMPLETION_FILE}
197
+    else
198
+        sed -i "s|scuttlebot version.*|scuttlebot version:${SCUTTLEBOT_VERSION}|g" ${COMPLETION_FILE}
199
+    fi
200
+
201
+    APP_INSTALLED=1
202
+}
203
+
204
+# NOTE: deliberately no exit 0