Don't install scuttlebot as root

This commit is contained in:
Bob Mottram 2018-04-13 12:35:48 +01:00
parent c66933077f
commit 6aefd00751
2 changed files with 48 additions and 40 deletions

View File

@ -56,7 +56,7 @@ function logging_off_scuttlebot {
}
function scuttlebot_create_invite {
invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
invite_string=$(su -c "/etc/scuttlebot/node_modules/.bin/sbot invite.create 1" - scuttlebot | sed 's/"//g')
clear
echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
@ -382,37 +382,35 @@ function mesh_install_scuttlebot {
get_npm_arch
mesh_setup_npm
cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
#!/bin/bash
export PATH=~/.npm-global/bin:$PATH
export NPM_CONFIG_PREFIX=~/.npm-global
source ~/.profile
if ! npm install --unsafe-perm --verbose --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}; then
exit 1
fi
if ! npm install --arch=$NPM_ARCH -g git-ssb; then
exit 2
fi
if ! npm install --arch=$NPM_ARCH -g git-remote-ssb; then
exit 3
fi
EOF
chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
chroot "$rootdir" /usr/bin/install_scuttlebot
rm "$rootdir/usr/bin/install_scuttlebot"
if [ ! -f "$rootdir/usr/local/bin/sbot" ]; then
echo $'Scuttlebot was not installed'
exit 528253
fi
if [ ! -d "$rootdir/etc/scuttlebot" ]; then
mkdir -p "$rootdir/etc/scuttlebot"
fi
# an unprivileged user to run as
# an unprivileged user to install and run as
chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
#!/bin/bash
cd /etc/scuttlebot || exit 1
if ! npm install --arch=$NPM_ARCH scuttlebot@${SCUTTLEBOT_VERSION}; then
exit 2
fi
if ! npm install --arch=$NPM_ARCH -g git-ssb; then
exit 3
fi
if ! npm install --arch=$NPM_ARCH -g git-remote-ssb; then
exit 4
fi
EOF
chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
chroot "$rootdir" su -c '/usr/bin/install_scuttlebot' - scuttlebot
rm "$rootdir/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)';
@ -424,7 +422,7 @@ EOF
echo 'User=scuttlebot';
echo 'Group=scuttlebot';
echo "WorkingDirectory=/etc/scuttlebot";
echo 'ExecStart=/usr/local/bin/sbot server';
echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
echo 'Restart=always';
echo 'Environment="USER=scuttlebot"';
echo '';
@ -439,8 +437,27 @@ function install_scuttlebot {
function_check install_nodejs
install_nodejs scuttlebot
npm install -g scuttlebot@${SCUTTLEBOT_VERSION}
if [ ! -f /usr/local/bin/sbot ]; then
if [ ! -d /etc/scuttlebot ]; then
mkdir -p /etc/scuttlebot
fi
# an unprivileged user to install and run as
useradd -d /etc/scuttlebot/ scuttlebot
cat <<EOF > /usr/bin/install_scuttlebot
#!/bin/bash
cd /etc/scuttlebot || exit 1
if ! npm install scuttlebot@${SCUTTLEBOT_VERSION}; then
exit 2
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'
exit 528253
fi
@ -448,15 +465,6 @@ function install_scuttlebot {
npm install -g git-ssb
npm install -g git-remote-ssb
if [ ! -d /etc/scuttlebot ]; then
mkdir -p /etc/scuttlebot
fi
npm install -g dat
# an unprivileged user to run as
useradd -d /etc/scuttlebot/ scuttlebot
# daemon
{ echo '[Unit]';
echo 'Description=Scuttlebot (messaging system)';
@ -468,7 +476,7 @@ function install_scuttlebot {
echo 'User=scuttlebot';
echo 'Group=scuttlebot';
echo "WorkingDirectory=/etc/scuttlebot";
echo 'ExecStart=/usr/local/bin/sbot server';
echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
echo 'Restart=always';
echo 'Environment="USER=scuttlebot"';
echo '';

View File

@ -945,7 +945,7 @@ initialise_mesh() {
#install_librevault
install_patchwork
install_web_server
#mesh_install_scuttlebot
mesh_install_scuttlebot
#install_ferment
chroot "$rootdir" apt-get clean