Explorar el Código

Don't install scuttlebot as root

Bob Mottram hace 7 años
padre
commit
6aefd00751
Se han modificado 2 ficheros con 39 adiciones y 31 borrados
  1. 38
    30
      src/freedombone-app-scuttlebot
  2. 1
    1
      src/freedombone-image-customise

+ 38
- 30
src/freedombone-app-scuttlebot Ver fichero

56
 }
56
 }
57
 
57
 
58
 function scuttlebot_create_invite {
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
     clear
61
     clear
62
     echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
62
     echo -e "\\n\\nYour Scuttlebot invite code is:\\n\\n${invite_string}\\n\\n"
382
     get_npm_arch
382
     get_npm_arch
383
     mesh_setup_npm
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
     cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
392
     cat <<EOF > "$rootdir/usr/bin/install_scuttlebot"
386
 #!/bin/bash
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
 fi
397
 fi
393
 if ! npm install --arch=$NPM_ARCH -g git-ssb; then
398
 if ! npm install --arch=$NPM_ARCH -g git-ssb; then
394
-    exit 2
399
+    exit 3
395
 fi
400
 fi
396
 if ! npm install --arch=$NPM_ARCH -g git-remote-ssb; then
401
 if ! npm install --arch=$NPM_ARCH -g git-remote-ssb; then
397
-    exit 3
402
+    exit 4
398
 fi
403
 fi
399
 EOF
404
 EOF
400
     chroot "$rootdir" /bin/chmod +x /usr/bin/install_scuttlebot
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
     rm "$rootdir/usr/bin/install_scuttlebot"
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
         echo $'Scuttlebot was not installed'
410
         echo $'Scuttlebot was not installed'
406
         exit 528253
411
         exit 528253
407
     fi
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
     # daemon
414
     # daemon
417
     { echo '[Unit]';
415
     { echo '[Unit]';
418
       echo 'Description=Scuttlebot (messaging system)';
416
       echo 'Description=Scuttlebot (messaging system)';
424
       echo 'User=scuttlebot';
422
       echo 'User=scuttlebot';
425
       echo 'Group=scuttlebot';
423
       echo 'Group=scuttlebot';
426
       echo "WorkingDirectory=/etc/scuttlebot";
424
       echo "WorkingDirectory=/etc/scuttlebot";
427
-      echo 'ExecStart=/usr/local/bin/sbot server';
425
+      echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
428
       echo 'Restart=always';
426
       echo 'Restart=always';
429
       echo 'Environment="USER=scuttlebot"';
427
       echo 'Environment="USER=scuttlebot"';
430
       echo '';
428
       echo '';
439
     function_check install_nodejs
437
     function_check install_nodejs
440
     install_nodejs scuttlebot
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
         exit 528253
461
         exit 528253
445
     fi
462
     fi
446
 
463
 
448
     npm install -g git-ssb
465
     npm install -g git-ssb
449
     npm install -g git-remote-ssb
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
     # daemon
468
     # daemon
461
     { echo '[Unit]';
469
     { echo '[Unit]';
462
       echo 'Description=Scuttlebot (messaging system)';
470
       echo 'Description=Scuttlebot (messaging system)';
468
       echo 'User=scuttlebot';
476
       echo 'User=scuttlebot';
469
       echo 'Group=scuttlebot';
477
       echo 'Group=scuttlebot';
470
       echo "WorkingDirectory=/etc/scuttlebot";
478
       echo "WorkingDirectory=/etc/scuttlebot";
471
-      echo 'ExecStart=/usr/local/bin/sbot server';
479
+      echo 'ExecStart=/etc/scuttlebot/node_modules/.bin/sbot server';
472
       echo 'Restart=always';
480
       echo 'Restart=always';
473
       echo 'Environment="USER=scuttlebot"';
481
       echo 'Environment="USER=scuttlebot"';
474
       echo '';
482
       echo '';

+ 1
- 1
src/freedombone-image-customise Ver fichero

945
     #install_librevault
945
     #install_librevault
946
     install_patchwork
946
     install_patchwork
947
     install_web_server
947
     install_web_server
948
-    #mesh_install_scuttlebot
948
+    mesh_install_scuttlebot
949
     #install_ferment
949
     #install_ferment
950
 
950
 
951
     chroot "$rootdir" apt-get clean
951
     chroot "$rootdir" apt-get clean