Bläddra i källkod

Don't install scuttlebot as root

Bob Mottram 7 år sedan
förälder
incheckning
6aefd00751
2 ändrade filer med 39 tillägg och 31 borttagningar
  1. 38
    30
      src/freedombone-app-scuttlebot
  2. 1
    1
      src/freedombone-image-customise

+ 38
- 30
src/freedombone-app-scuttlebot Visa fil

@@ -56,7 +56,7 @@ function logging_off_scuttlebot {
56 56
 }
57 57
 
58 58
 function scuttlebot_create_invite {
59
-    invite_string=$(su -c "sbot invite.create 1" - scuttlebot | sed 's/"//g')
59
+    invite_string=$(su -c "/etc/scuttlebot/node_modules/.bin/sbot invite.create 1" - scuttlebot | sed 's/"//g')
60 60
 
61 61
     clear
62 62
     echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
@@ -382,37 +382,35 @@ function mesh_install_scuttlebot {
382 382
     get_npm_arch
383 383
     mesh_setup_npm
384 384
 
385
+    if [ ! -d "$rootdir/etc/scuttlebot" ]; then
386
+        mkdir -p "$rootdir/etc/scuttlebot"
387
+    fi
388
+
389
+    # an unprivileged user to install and run as
390
+    chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
391
+
385 392
     cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
386 393
 #!/bin/bash
387
-export PATH=~/.npm-global/bin:$PATH
388
-export NPM_CONFIG_PREFIX=~/.npm-global
389
-source ~/.profile
390
-if ! npm install --unsafe-perm --verbose --arch=$NPM_ARCH -g scuttlebot@${SCUTTLEBOT_VERSION}; then
391
-    exit 1
394
+cd /etc/scuttlebot || exit 1
395
+if ! npm install --arch=$NPM_ARCH scuttlebot@${SCUTTLEBOT_VERSION}; then
396
+    exit 2
392 397
 fi
393 398
 if ! npm install --arch=$NPM_ARCH -g git-ssb; then
394
-    exit 2
399
+    exit 3
395 400
 fi
396 401
 if ! npm install --arch=$NPM_ARCH -g git-remote-ssb; then
397
-    exit 3
402
+    exit 4
398 403
 fi
399 404
 EOF
400 405
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
401
-    chroot "$rootdir" /usr/bin/install_scuttlebot
406
+    chroot "$rootdir" su -c '/usr/bin/install_scuttlebot' - scuttlebot
402 407
     rm "$rootdir/usr/bin/install_scuttlebot"
403 408
 
404
-    if [ ! -f "$rootdir/usr/local/bin/sbot" ]; then
409
+    if [ ! -f "$rootdir/etc/scuttlebot/node_modules/.bin/sbot" ]; then
405 410
         echo $'Scuttlebot was not installed'
406 411
         exit 528253
407 412
     fi
408 413
 
409
-    if [ ! -d "$rootdir/etc/scuttlebot" ]; then
410
-        mkdir -p "$rootdir/etc/scuttlebot"
411
-    fi
412
-
413
-    # an unprivileged user to run as
414
-    chroot "$rootdir" useradd -d /etc/scuttlebot/ scuttlebot
415
-
416 414
     # daemon
417 415
     { echo '[Unit]';
418 416
       echo 'Description=Scuttlebot (messaging system)';
@@ -424,7 +422,7 @@ EOF
424 422
       echo 'User=scuttlebot';
425 423
       echo 'Group=scuttlebot';
426 424
       echo "WorkingDirectory=/etc/scuttlebot";
427
-      echo 'ExecStart=/usr/local/bin/sbot server';
425
+      echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
428 426
       echo 'Restart=always';
429 427
       echo 'Environment="USER=scuttlebot"';
430 428
       echo '';
@@ -439,8 +437,27 @@ function install_scuttlebot {
439 437
     function_check install_nodejs
440 438
     install_nodejs scuttlebot
441 439
 
442
-    npm install -g scuttlebot@${SCUTTLEBOT_VERSION}
443
-    if [ ! -f /usr/local/bin/sbot ]; then
440
+    if [ ! -d /etc/scuttlebot ]; then
441
+        mkdir -p /etc/scuttlebot
442
+    fi
443
+
444
+    # an unprivileged user to install and run as
445
+    useradd -d /etc/scuttlebot/ scuttlebot
446
+
447
+    cat <<EOF > /usr/bin/install_scuttlebot
448
+#!/bin/bash
449
+cd /etc/scuttlebot || exit 1
450
+if ! npm install scuttlebot@${SCUTTLEBOT_VERSION}; then
451
+    exit 2
452
+fi
453
+exit 0
454
+EOF
455
+    chmod +x /usr/bin/install_scuttlebot
456
+    su -c '/usr/bin/install_scuttlebot' - scuttlebot
457
+    rm /usr/bin/install_scuttlebot
458
+
459
+    if [ ! -f /etc/scuttlebot/node_modules/.bin/sbot ]; then
460
+        echo $'Scuttlebot was not installed'
444 461
         exit 528253
445 462
     fi
446 463
 
@@ -448,15 +465,6 @@ function install_scuttlebot {
448 465
     npm install -g git-ssb
449 466
     npm install -g git-remote-ssb
450 467
 
451
-    if [ ! -d /etc/scuttlebot ]; then
452
-        mkdir -p /etc/scuttlebot
453
-    fi
454
-
455
-    npm install -g dat
456
-
457
-    # an unprivileged user to run as
458
-    useradd -d /etc/scuttlebot/ scuttlebot
459
-
460 468
     # daemon
461 469
     { echo '[Unit]';
462 470
       echo 'Description=Scuttlebot (messaging system)';
@@ -468,7 +476,7 @@ function install_scuttlebot {
468 476
       echo 'User=scuttlebot';
469 477
       echo 'Group=scuttlebot';
470 478
       echo "WorkingDirectory=/etc/scuttlebot";
471
-      echo 'ExecStart=/usr/local/bin/sbot server';
479
+      echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
472 480
       echo 'Restart=always';
473 481
       echo 'Environment="USER=scuttlebot"';
474 482
       echo '';

+ 1
- 1
src/freedombone-image-customise Visa fil

@@ -945,7 +945,7 @@ initialise_mesh() {
945 945
     #install_librevault
946 946
     install_patchwork
947 947
     install_web_server
948
-    #mesh_install_scuttlebot
948
+    mesh_install_scuttlebot
949 949
     #install_ferment
950 950
 
951 951
     chroot "$rootdir" apt-get clean