[Solved] Activation Running Script at End.

Non release banter
Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

[Solved] Activation Running Script at End.

Post#1 by Bogomips » 12 Jun 2015, 12:34

Module Activation
  • How to get a script to be run at the end.
  • Possibility of setting an Environmental Variable?
    This does not seem to be a viable option as the user invoking the activation has to be known. Particular case in point is MANPATH, which is already set and overrides man configuration file.

    Code: Select all

    Currently KDE
    guest@porteus:~$ echo $MANPATH
    /usr/local/man:/usr/man
    Require
    guest@porteus:~$ MANPATH+=:/usr/share/man
    guest@porteus:~$ echo $MANPATH
    /usr/local/man:/usr/man:/usr/share/man
    
    Grateful for any ideas.
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

cttan
Shogun
Shogun
Posts: 333
Joined: 26 Jan 2011, 16:15
Distribution: Porteus 3.2 and 4.0 64bit KDE
Location: Malaysia

Re: Activation Running Script at End?

Post#2 by cttan » 18 Jun 2015, 23:30

Hi Bogomips,

Why don't you run a script to activate the module, copy settings file, set environment variable and start the program.

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Activation Running Script at End?

Post#3 by Bogomips » 18 Jun 2015, 23:52

Hi cttan

Unfortunately module not for me. So was trying to think of a way how to make it easy for someone who activates the module, so that they get man page for various programs straight away. Not keen on juggling around the man directories. Guess I'll just have to provide info with the module to set the MANPATH env var.
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Activation Running Script at End?

Post#4 by Bogomips » 02 Sep 2015, 23:39

Found it! /opt/porteus-scripts/xorg/aufs-insert. Relevant lines:

Code: Select all

# Find all rc scripts from the module:
find $MOD/etc/rc.d $MOD/etc/init.d $MOD/etc/rc.d/init.d -type f -executable -maxdepth 1 2>/dev/null | egrep -v 'rc.[0-9]|rc.K|rc.S|rc.M' | sed s^$MOD^^ | sort -u >> /mnt/live/tmp/caches/services
Reference Example

Code: Select all

mkdir sym
guest@porteus:~$ cp --parents -d /lib/liblzma.so.5 sym
guest@porteus:~$ cp --parents -d /lib/libgpg-error.so.0 sym
guest@porteus:~$ mkdir -p sym/etc/rc.d
guest@porteus:~$ cat > sym/etc/rc.d/symfix
#!/bin/sh
ln -sf /usr/lib/liblzma.so.5.2.1 /lib/liblzma.so.5
ln -sf /usr/lib/libgpg-error.so.0.15.0 /lib/libgpg-error.so.0
guest@porteus:~$ tree sym
sym
├── etc
│   └── rc.d
│       └── symfix
└── lib
    ├── libgpg-error.so.0 -> libgpg-error.so.0.9.0
    └── liblzma.so.5 -> liblzma.so.5.0.5
3 directories, 3 files
guest@porteus:~$ dir2xzm sym symfix.xzm
root@porteus:/home/guest# activate symfix.xzm 
Updating shared library links:  /sbin/ldconfig
guest@porteus:~$ ls -l /lib/liblzma.so.5
lrwxrwxrwx 1 root root 25 Aug 22 22:39 /lib/liblzma.so.5 -> /usr/lib/liblzma.so.5.2.1*
guest@porteus:~$ ls -l /lib/libgpg-error.so.0
lrwxrwxrwx 1 root root 31 Aug 22 22:39 /lib/libgpg-error.so.0 -> /usr/lib/libgpg-error.so.0.15.0*
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: [Solved] Activation Running Script at End?

Post#5 by brokenman » 03 Sep 2015, 03:58

You can use the rc script in the module. It will run when the module is activated.
How do i become super user?
Wear your underpants on the outside and put on a cape.

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: [Solved] Activation Running Script at End?

Post#6 by Bogomips » 03 Sep 2015, 23:17

brokenman wrote:You can use the rc script in the module. It will run when the module is activated.
This is not clear. :%) All I managed to work out is that the script symfix, given in the reference example above, runs when the module symfix.xzm is activated. Do you mean there is another script rc in the module?
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: [Solved] Activation Running Script at End?

Post#7 by brokenman » 04 Sep 2015, 20:50

If I understood what you want, it is to set a MANPATH environment variable when a module is activated?

Code: Select all

mkdir -p /tmp/module/etc/rc.d/{init.d,rc4.d}
cat >> /tmp/module/etc/rc.d/init.d/rc.runme << EOF
#!/bin/bash

export MANPATH+=:/tmp/manpath
echo "\$MANPATH" > /tmp/output.txt
EOF
chmod +x /tmp/module/etc/rc.d/init.d/rc.runme
ln -s /etc/rc.d/init.d/rc.runme /tmp/module/etc/rc.d/rc4.d/99runatstart
dir2xzm /tmp/module /tmp/test.xzm
Now activate the module and check that MANPATH was echoed to /tmp/output.txt
How do i become super user?
Wear your underpants on the outside and put on a cape.

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: [Solved] Activation Running Script at End?

Post#8 by Bogomips » 09 Sep 2015, 19:08

@brokenman
Thanks for providing a template for rc script. However, selecting the code from bulletin board followed by pasting into terminal does not work owing to leading spaces being inserted along the way, as a result of which, here file cannot detect end of text delimiter:

Code: Select all

root@porteus:/home/guest#     mkdir -p /tmp/module/etc/rc.d/{init.d,rc4.d}
root@porteus:/home/guest#     cat >> /tmp/module/etc/rc.d/init.d/rc.runme << EOF
>     #!/bin/bash
> 
>     export MANPATH+=:/tmp/manpath
>     echo "\$MANPATH" > /tmp/output.txt
>     EOF
>     chmod +x /tmp/module/etc/rc.d/init.d/rc.runme
>     ln -s /etc/rc.d/init.d/rc.runme /tmp/module/etc/rc.d/rc4.d/99runatstart
>     dir2xzm /tmp/module /tmp/test.xzm
> ^C
Have had to edit text to look like this:

Code: Select all

    mkdir -p /tmp/module/etc/rc.d/{init.d,rc4.d}
    cat >> /tmp/module/etc/rc.d/init.d/rc.runme << EOF
    #!/bin/bash

    export MANPATH+=:/tmp/manpath
    echo "\$MANPATH" > /tmp/output.txt
EOF
    chmod +x /tmp/module/etc/rc.d/init.d/rc.runme
    ln -s /etc/rc.d/init.d/rc.runme /tmp/module/etc/rc.d/rc4.d/99runatstart
    dir2xzm /tmp/module /tmp/test.xzm
Resulting in:

Code: Select all

root@porteus:/home/guest#     mkdir -p /tmp/module/etc/rc.d/{init.d,rc4.d}
root@porteus:/home/guest#     cat >> /tmp/module/etc/rc.d/init.d/rc.runme << EOF
>     #!/bin/bash
> 
>     export MANPATH+=:/usr/share/man
>     echo "\$MANPATH" > /tmp/output.txt
> EOF
root@porteus:/home/guest#     chmod +x /tmp/module/etc/rc.d/init.d/rc.runme
root@porteus:/home/guest#     ln -s /etc/rc.d/init.d/rc.runme /tmp/module/etc/rc.d/rc4.d/99runatstart
root@porteus:/home/guest#     dir2xzm /tmp/module /tmp/test.xzm
Parallel mksquashfs: Using 1 processor
Creating 4.0 filesystem on /tmp/test.xzm, block size 262144.
[===============================================================================|] 1/1 100%

Exportable Squashfs 4.0 filesystem, xz compressed, data block size 262144
        compressed data, compressed metadata, compressed fragments, compressed xattrs
        duplicates are removed
Filesystem size 0.60 Kbytes (0.00 Mbytes)
...
root@porteus:/home/guest# activate /tmp/test.xzm 
Updating shared library links:  /sbin/ldconfig
root@porteus:/home/guest# cat /tmp/output.txt 
/usr/local/man:/usr/man:/usr/share/man

root@porteus:/home/guest# echo $MANPATH
/usr/local/man:/usr/man
So, setting MANPATH environment variable upon module activation proves not to be a practical solution. Seems activation takes place in subshell, or in different shell, and user's MANPATH environmental variable remains untouched.

Going for heuristic solution:

Code: Select all

mkdir -p manmod/etc/rc.d/init.d
cp p10/Por/runman.sh manmod/etc/rc.d/init.d/rc.runman
chmod +x manmod/etc/rc.d/init.d/rc.runman
dir2xzm manmod manpage.xzm
activate manpage.xzm
runman.sh:

Code: Select all

#!/bin/bash
# Using non-existent English Language Directory 'en' in /usr/local/man to
# Bind to /usr/share/man		2015-09-09 20:05:27
# Flag this by creating directory 'flg' in /usr/share/man (not 2 letter language)
rum() {
#STOP
# If bound, unbind first of all
if [[ $1 == stop ]]; then [[ -d /usr/local/man/en/flg ]] && 
  umount /usr/share/man && rmdir /usr/local/man/en;
  # Unflag
  [[ -d /usr/share/man/flg && ! -d /usr/local/man/en ]] && rmdir /usr/share/man/flg;
  return;
fi
# START
# If not bound, create 'en' directory if non-existent and flag this.
if [[ ! -d /usr/local/man/en/flg ]]; then [[ ! -d /usr/local/man/en ]] &&
  { [[ ! -d /usr/share/man/flg ]] && mkdir /usr/share/man/flg;
  mkdir /usr/local/man/en; }
  [[ -d /usr/share/man/flg && ! -d /usr/local/man/en ]] && rmdir /usr/share/man/flg;
  [[ -d /usr/share/man/flg ]] && mount --bind /usr/share/man /usr/local/man/en;
fi
m="Access Module ManPages by Modification of MANPATH environmental variable:"$'\n'MANPATH+=:/usr/share/man;
# Unbound: Just post Message (=>  en Directory already Exists in /usr/local/man)
[[ ! -d /usr/local/man/en/flg ]] && Xdialog --left --msgbox "$m" 6 96;
}
rum $1
Robuster runman.sh 13-9-15

Code: Select all

#!/bin/bash
# Using non-existent English Language Directory 'en' in /usr/local/man to
# Bind to /usr/share/man		2015-09-09 20:05:27
# Flag this by creating directory 'flg' in /usr/share/man (not 2 letter language)
rum() {
#STOP
# If bound, decrement lock count	2015-09-13 22:10:38
if [[ $1 == stop && -d /usr/share/man/flg ]]; then read f g <<< $(echo /usr/share/man/flg/sem*);
  [[ -f $f ]] && rm $f && return;
fi
# Fall Through if no Semaphore File  ->  Unbind
if [[ $1 == stop ]]; then [[ -d /usr/local/man/en/flg ]] && 
  umount /usr/share/man && rmdir /usr/local/man/en;
  # Unflag
  [[ -d /usr/share/man/flg && ! -d /usr/local/man/en ]] && rmdir /usr/share/man/flg;
  return;
fi
# START
# If not bound, create 'en' directory if non-existent and flag this.
if [[ ! -d /usr/local/man/en/flg ]]; then [[ ! -d /usr/local/man/en ]] &&
  { [[ ! -d /usr/share/man/flg ]] && mkdir /usr/share/man/flg;
  mkdir /usr/local/man/en; }
  [[ -d /usr/share/man/flg && ! -d /usr/local/man/en ]] && rmdir /usr/share/man/flg;
  [[ -d /usr/share/man/flg ]] && mount --bind /usr/share/man /usr/local/man/en;
  return;			# After Setting Up	2015-09-13 21:33:48
fi
m="Access Module ManPages by Modification of MANPATH environmental variable:"$'\n'MANPATH+=:/usr/share/man;
# Unbound: Just post Message (=>  en Directory already Exists in /usr/local/man)
[[ ! -d /usr/local/man/en/flg ]] && Xdialog --left --msgbox "$m" 6 96;
# Already Bound on Entry			2015-09-13 21:43:28
if [[ -d /usr/local/man/en/flg ]]; then	read f g <<< $(echo /usr/local/man/en/flg/sem*);
  c=${f#*/sem};		# Semaphore lock count
  [[ ${f#*/sem} == "*" ]] && c=100; let c--;	# Initialise to 99
  touch /usr/share/man/flg/sem$c;	# Create Semaphore
fi
}
rum $1
Running On:

Code: Select all

guest@porteus:~$ man dpkg
No manual entry for dpkg
checking network resources...
guest@porteus:~$ deactivate manpage.xzm
guest@porteus:~$ sudo rmdir /usr/local/man/en	# Simulated Non-English Locale

guest@porteus:~$ activate manpage.xzm
guest@porteus:~$ man dpkg
guest@porteus:~$ deactivate manpage.xzm
guest@porteus:~$ man dpkg
No manual entry for dpkg
checking network resources...

guest@porteus:~$ activate manpage.xzm
guest@porteus:~$ man dpkg
guest@porteus:~$ deactivate manpage.xzm
guest@porteus:~$ man dpkg
No manual entry for dpkg
checking network resources...
# Both temporary directories now removed.
guest@porteus:~$ ls /usr/share/man/flg
/bin/ls: cannot access /usr/share/man/flg: No such file or directory
guest@porteus:~$ ls /usr/local/man/en
/bin/ls: cannot access /usr/local/man/en: No such file or directory
Afraid, fail to see point of having symbolic link of this nature:

Code: Select all

ln -s /etc/rc.d/init.d/rc.runman manmod/etc/rc.d/rc4.d/99runatstart
Update Edit: 13-9-15
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: [Solved] Activation Running Script at End.

Post#9 by brokenman » 06 Jun 2016, 23:43

Afraid, fail to see point of having symbolic link of this nature:
Sorry for super late reply. It's so you can put all scripts in init.d and then allow symbolic links in rcX to be run at different init levels. I guess the standard was that there was only one init directory, and over time the need to segregate came up and so rcX was integrated.
How do i become super user?
Wear your underpants on the outside and put on a cape.

Post Reply