This is the old XigmaNAS forum in read only mode,
it will taken offline by the end of march 2021!



I like to aks Users and Admins to rewrite/take over important post from here into the new fresh main forum!
Its not possible for us to export from here and import it to the main forum!

[HOWTO] Install GNU Screen (embedded)

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
ginggs
Starter
Starter
Posts: 31
Joined: 27 Jun 2012 14:30
Status: Offline

[HOWTO] Install GNU Screen (embedded)

Post by ginggs »

GNU Screen is useful on NAS4Free for starting processes like long copy or move operations over SSH and allowing one to disconnect and reconnect at a later time without the process being terminated.

[-]Screen requires libulog.so.0 which is found in base.txz, but this archive is around 68MB in size so I've hosted the i386 and amd64 versions of the library on my website.
I couldn't attach them to this post as 'the extension tbz is not allowed'.[/-]

Edit: libulog.so.0 was included in NAS4Free rev 684.
Last edited by ginggs on 10 Aug 2013 08:23, edited 3 times in total.

User avatar
killermist
NewUser
NewUser
Posts: 4
Joined: 22 Jul 2012 19:38
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by killermist »

Though I think it could encourage people to do things that a NAS probably shouldn't be doing, this is a pretty nifty trick.
Wrapping a long-running copy in a screen session so you don't have to keep (and possibly worry about) the SSH session, is a good asset.

I won't pretend to understand everything you did in the script, and will instead ask a few dumb questions.

Where does it store and install the program and dependencies?

How hard would it be to adapt the location-checking so that it just verifies that the destination will have plenty of space (like maybe a check for 1Gb or more free space...)? I ask because none of my pools or mount points are on /mnt (which I understand bucks the standard method), so /mnt is generally pretty limited, since it is on a ram drive.

And, is it possible for the script to check and see if it has already downloaded the tarballs (or whatever), and not download again?

fsbruva
Advanced User
Advanced User
Posts: 378
Joined: 21 Sep 2012 14:50
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by fsbruva »

killermist wrote: I won't pretend to understand everything you did in the script.
Why not? No, I mean seriously, why not? What is stopping you? :roll:
killermist wrote:Where does it store and install the program and dependencies?
It creates two directories in the same directory that the script is run from, bin and lib, when it untars the tarball. Then it symlinks those files to the existing /lib, /usr/bin and /usr/local/share.
killermist wrote:How hard would it be to adapt the location-checking so that it just verifies that the destination will have plenty of space (like maybe a check for 1Gb or more free space...)?
Not hard. But why? The total size of this package is quite small.

Googled "bash available space current directory." Found: http://unix.stackexchange.com/questions ... ry-in-bash
However, this will give us human readable output (hard to deal with the M). So, we can choose to not do it that way.

Code: Select all

FREE=`df -P . | tail -1 | awk '{print $4}'`
Next we need to understand that the freespace is given with the default blocksize of 512. If you want to check the number of free kilobytes, you use:

Code: Select all

FREE=`df -Pk . | tail -1 | awk '{print $4}'`
For free gigs:

Code: Select all

FREE=`df -Pg . | tail -1 | awk '{print $4}'`
Then, you need to compare that:

Code: Select all

if [ $FREE -lt 1 ]; then
Sites I used to come up with this answer:
http://tldp.org/LDP/abs/html/comparison-ops.html
http://unix.stackexchange.com/questions ... ry-in-bash


The location checking actually only checks for an absolute path by looking for /mnt in the pathname, to ensure that the symlinks it creates are going to be created properly. A better solution to get the full path is this:

Code: Select all

# Method adapted from user apokalyptik at http://hintsforums.macworld.com/archive/index.php/t-73839.html
STAT=$(procstat -f $$ | grep -E "/"$(basename $0)"$")
DIR=$(echo $STAT | sed -r s/'^([^\/]+)\/'/'\/'/1 2>/dev/null)
killermist wrote:And, is it possible for the script to check and see if it has already downloaded the tarballs (or whatever), and not download again?
It already does. It first checks if the relative directories bin and lib exist. If they do, then this is taken to mean that the tarball has already been extracted once before.

Code: Select all

if [ ! -d ${DIR}/lib ]; then
If they directories do exist, it checks if the tarball is there or not.

Code: Select all

if [ ! -e ${DIR}/${FILE} ];
If the file exists (following a fetch, or not), then untar it.

Code: Select all

if [ -f ${DIR}/${FILE} ]
It then checks afterwards to see if the desired folder exists. It not existing would indicate the something went awry with the installation.

Code: Select all

if [ ! -d ${DIR}/lib ] ;

ginggs
Starter
Starter
Posts: 31
Joined: 27 Jun 2012 14:30
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by ginggs »

killermist wrote:Though I think it could encourage people to do things that a NAS probably shouldn't be doing, this is a pretty nifty trick.
Wrapping a long-running copy in a screen session so you don't have to keep (and possibly worry about) the SSH session, is a good asset.
Sorry for the late reply, I didn't get a notifcation that this thread had been updated.
I see fsbruva already answered your questions, thanks.

I just wanted to add that this script is based on danmero's script for installing Midnight Commander Light. I see there are still references to mc-light in the comments of the script. :P
Last edited by ginggs on 30 Dec 2018 08:09, edited 4 times in total.

User avatar
zoon01
Developer
Developer
Posts: 724
Joined: 20 Jun 2012 21:06
Location: Netherlands
Contact:
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by zoon01 »

Please include /lib/libulog.so.0 was a request and is now done at rev 684 at its default location /lib/libulog.so.0.

Regards,
zoon01
System specs: XigmaNAS 11.2.0.4 -embedded on Samsung 860 EVO 256GB and Supermicro X10SL7-F w / Bios v3.2, IPMI v.03.86 / CPU E3-1241 v3 @ 3.50GHz - 32GB Crucial DDR3L 1600mhz ECC 1.35v , LSI 2308 on PH20.00.07.00 IT mode, Storage: 5x Western Digital Red (WD30EFRX) raidz

Development system is same system in virtualbox.

ginggs
Starter
Starter
Posts: 31
Joined: 27 Jun 2012 14:30
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by ginggs »

zoon01 wrote:Please include /lib/libulog.so.0 was a request and is now done at rev 684 at its default location /lib/libulog.so.0.
Great, thank you! :D

I've updated gnuscreen.sh for NAS4Free 9.1.0.1 revision 687:

Code: Select all

#!/bin/sh
# filename:     gnuscreen.sh
# author:       Graham Inggs <graham@nerve.org.za>
# date:         2013-02-09 ; Initial release
# date:         2013-05-05 ; Updated for NAS4Free 9.1.0.1 revision 687 which includes /lib/libulog.so.0
# purpose:      Install GNU Screen on NAS4Free (embedded version).
# Note:         Check the end of the page.
#
#----------------------- Set variables ------------------------------------------------------------------
DIR=`dirname $0`;
PLATFORM=`uname -m`
RELEASE=`uname -r | cut -d- -f1`
URL="ftp://ftp.freebsd.org/pub/FreeBSD/ports/${PLATFORM}/packages-9-current/All"
GNUSCREENFILE="screen-4.0.3_14.tbz"
#----------------------- Set Errors ---------------------------------------------------------------------
_msg() { case $@ in
  0) echo "The script will exit now."; exit 0 ;;
  1) echo "No route to server, or file do not exist on server"; _msg 0 ;;
  2) echo "Can't find ${FILE} on ${DIR}"; _msg 0 ;;
  3) echo "GNU Screen       installed and ready! (ONLY USE DURING A SSH SESSION)"; exit 0 ;;
  4) echo "Always run this script using the full path: /mnt/.../directory/gnuscreen.sh"; _msg 0 ;;
esac ; exit 0; }
#----------------------- Check for full path ------------------------------------------------------------
if [ ! `echo $0 |cut -c1-5` = "/mnt/" ]; then _msg 4; fi
cd $DIR;
#----------------------- Download and decompress gnu screen files if don't exist ------------------------
FILE=${GNUSCREENFILE}
if [ ! -d ${DIR}/bin ]; then
  if [ ! -e ${DIR}/${FILE} ]; then fetch ${URL}/${FILE} || _msg 1; fi
  if [ -f ${DIR}/${FILE} ]; then tar xzf ${DIR}/${FILE} || _msg 2; rm ${DIR}/+*; rm -R ${DIR}/man; rm -R ${DIR}/info; fi
  if [ ! -d ${DIR}/bin ] ; then _msg 4; fi
fi
#----------------------- Create symlinks ----------------------------------------------------------------
if [ ! -e /usr/local/share/screen ]; then ln -s ${DIR}/share/screen /usr/local/share; fi
for i in `ls $DIR/bin/`
   do if [ ! -e /usr/local/bin/${i} ]; then ln -s ${DIR}/bin/$i /usr/local/bin; fi; done
_msg 3 ; exit 0;
#----------------------- End of Script ------------------------------------------------------------------
# 1. Keep this script in his own directory.
# 2. chmod the script u+x,
# 3. Always run this script using the full path: /mnt/share/directory/gnuscreen
# 4. You can add this script to WebGUI: Advanced: Commands as Post command (see 3).
# 5. To run GNU Screen from shell type 'screen'.
# 6. Create ~/.screenrc with the following contents to set your preferred shell:
#    shell "/bin/bash"

AlexJ
NewUser
NewUser
Posts: 12
Joined: 13 Sep 2012 22:00
Location: US
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by AlexJ »

Guys, I seriously advise you to switch to http://tmux.sourceforge.net/ from screen.
It is BSD based and has much more features than GNU screen

Dependencies(taken from FreeBSD 7.4 box) :

Code: Select all

# ldd tmux
tmux:
        libutil.so.7 => /lib/libutil.so.7 (0x280bd000)
        libm.so.5 => /lib/libm.so.5 (0x280cb000)
        libncurses.so.7 => /lib/libncurses.so.7 (0x280e1000)
        libevent-1.4.so.4 => /usr/local/lib/libevent-1.4.so.4 (0x28120000)
        libc.so.7 => /lib/libc.so.7 (0x28136000)

User avatar
siftu
Moderator
Moderator
Posts: 71
Joined: 17 Oct 2012 06:36
Status: Offline

Re: [HOWTO] Install GNU Screen

Post by siftu »

I want to give a +1 to AlexJ's suggestion of using tmux. I have been a screen user for many years. I made a port for tmux and have it on my custom build, and find it easy to use with the advantages AlexJ mentioned.
System specs: NAS4Free amd64-embedded on ASUSTeK. M5A78L-M LX PLUS - AMD Phenom(tm) II X3 720 Processor - 8GB ECC Ram, Storage: 2x ZFS mirrors with 4x Western Digital Green (WDC WD10EADS)
My NAS4Free related blog - http://n4f.siftusystems.com/

ginggs
Starter
Starter
Posts: 31
Joined: 27 Jun 2012 14:30
Status: Offline

Re: [HOWTO] Install GNU Screen (embedded)

Post by ginggs »

[HOWTO] Install tmux (embedded)
Thanks AlexJ and siftu.
Last edited by ginggs on 30 Dec 2018 08:11, edited 2 times in total.

ginggs
Starter
Starter
Posts: 31
Joined: 27 Jun 2012 14:30
Status: Offline

Re: [HOWTO] Install GNU Screen (embedded)

Post by ginggs »

Updated to fetch files from packages-9.1-release:

Code: Select all

#!/bin/sh
# filename:     gnuscreen.sh
# author:       Graham Inggs <graham@nerve.org.za>
# date:         2013-02-09 ; Initial release
# date:         2013-05-05 ; Updated for NAS4Free 9.1.0.1 revision 687 which includes /lib/libulog.so.0
# date:         2013-08-23 ; Fetch files from packages-9.1-release
# purpose:      Install GNU Screen on NAS4Free (embedded version).
# Note:         Check the end of the page.
#
#----------------------- Set variables ------------------------------------------------------------------
DIR=`dirname $0`;
PLATFORM=`uname -m`
RELEASE=`uname -r | cut -d- -f1`
URL="ftp://ftp.freebsd.org/pub/FreeBSD/ports/${PLATFORM}/packages-9.1-release/All"
GNUSCREENFILE="screen-4.0.3_14.tbz"
#----------------------- Set Errors ---------------------------------------------------------------------
_msg() { case $@ in
  0) echo "The script will exit now."; exit 0 ;;
  1) echo "No route to server, or file do not exist on server"; _msg 0 ;;
  2) echo "Can't find ${FILE} on ${DIR}"; _msg 0 ;;
  3) echo "GNU Screen       installed and ready! (ONLY USE DURING A SSH SESSION)"; exit 0 ;;
  4) echo "Always run this script using the full path: /mnt/.../directory/gnuscreen.sh"; _msg 0 ;;
esac ; exit 0; }
#----------------------- Check for full path ------------------------------------------------------------
if [ ! `echo $0 |cut -c1-5` = "/mnt/" ]; then _msg 4; fi
cd $DIR;
#----------------------- Download and decompress gnu screen files if don't exist ------------------------
FILE=${GNUSCREENFILE}
if [ ! -d ${DIR}/bin ]; then
  if [ ! -e ${DIR}/${FILE} ]; then fetch ${URL}/${FILE} || _msg 1; fi
  if [ -f ${DIR}/${FILE} ]; then tar xzf ${DIR}/${FILE} || _msg 2; rm ${DIR}/+*; rm -R ${DIR}/man; rm -R ${DIR}/info; fi
  if [ ! -d ${DIR}/bin ] ; then _msg 4; fi
fi
#----------------------- Create symlinks ----------------------------------------------------------------
if [ ! -e /usr/local/share/screen ]; then ln -s ${DIR}/share/screen /usr/local/share; fi
for i in `ls $DIR/bin/`
   do if [ ! -e /usr/local/bin/${i} ]; then ln -s ${DIR}/bin/$i /usr/local/bin; fi; done
_msg 3 ; exit 0;
#----------------------- End of Script ------------------------------------------------------------------
# 1. Keep this script in his own directory.
# 2. chmod the script u+x,
# 3. Always run this script using the full path: /mnt/share/directory/gnuscreen
# 4. You can add this script to WebGUI: Advanced: Commands as Post command (see 3).
# 5. To run GNU Screen from shell type 'screen'.
# 6. Create ~/.screenrc with the following contents to set your preferred shell:
#    shell "/bin/bash"

Digi-Quick
Advanced User
Advanced User
Posts: 198
Joined: 19 Jul 2013 04:21
Status: Offline

Re: [HOWTO] Install GNU Screen (embedded)

Post by Digi-Quick »

the script isn't working anymore

User avatar
MikeMac
Forum Moderator
Forum Moderator
Posts: 429
Joined: 07 Oct 2012 23:12
Location: Moscow, Russia
Contact:
Status: Offline

Re: [HOWTO] Install GNU Screen (embedded)

Post by MikeMac »

Digi-Quick wrote:the script isn't working anymore
tmux is available from the box

dragon788
NewUser
NewUser
Posts: 1
Joined: 02 May 2016 05:23
Status: Offline

Re: [HOWTO] Install GNU Screen (embedded)

Post by dragon788 »

I would heartily second using tmux over screen. Not only does it give you more than just session attach and resume, but it lets you split the terminal, run multiple commands, script your sessions and do so much more. The one thing I'd recommend if you are used to screen is changing the default "prefix" to Ctrl+A from the default of Ctrl+B, this will make things seem a lot more familiar. There are also some other tweaks that can be done to make it use Vim keybindings which will also make it much nicer to use as a purely keyboard driven tool (though you can enable mouse mode, it makes less sense over SSH).

I actually just went so far as to change my user's default shell to tmux. I'd recommend having a spare user in case it goes wrong, but it wasn't too hard, even though I couldn't select tmux from the dropdown on the user's page. I simply edited the /etc/master.passwd for my user, changed the /bin/bash entry to /bin/tmux, and then ran

Code: Select all

sudo pwd_mkdb /etc/master.passwd
to sync it to the binary database (that provides faster lookups and so is referenced rather than the master.passwd file directly).

The other thing I'm going to have to do now that I have tmux as my default shell, is tell tmux which shell to use as it's default shell, which will probably end up being bash. I can do that by adding a

Code: Select all

set -g default-shell /bin/bash
entry in my ~/.tmux.conf file.

Post Reply

Return to “Scripts and shell tips”