Porteus module activation status

For discussions about programming and projects not necessarily associated with Porteus.
User avatar
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#16 by Ed_P » 05 Oct 2016, 02:04

jssouza wrote:Here you go. Let me know if this works for you. The same script should also work in 3.2rc5!
It works with 3.0.1. :good: Will try 3.2rc5 later.

Code: Select all

guest@porteus:~$ sh /mnt/sda5/porteus3.2/Guest/modules.sh
find: `/mnt/isoloop': No such file or directory
grep: /tmp/11372_port_modules: No such file or directory
find: `/mnt/isoloop': No such file or directory
Updating shared library links:  /sbin/ldconfig
/sbin/ldconfig: /usr/lib/libv4lconvert.so.0 is not a symbolic link

/sbin/ldconfig: /usr/lib/libv4l2.so.0 is not a symbolic link

/sbin/ldconfig: /usr/lib/libv4l1.so.0 is not a symbolic link

Updating Razor menu: update-desktop-database
find: `/mnt/isoloop': No such file or directory
grep: /tmp/11372_port_modules: No such file or directory
ENTRIES="25
"
ENTRY=""
EXIT="0"
This is possible if the activated module is not part of the porteus base/modules/optional directory. The script only keeps track of these directories. Any external module would only be shown, and would disappear from the script once deactivated (as mentioned in an earlier post).
You should consider including support for modules added via the extramod= cheatcode which can be found with the following command:

Code: Select all

guest@porteus:~$ cat /proc/cmdline
quiet from=/ISOs/Porteus-RazorQT-v3.0.1-x86_64-nu.iso changes=EXIT:/porteus3.0/changes/porteussave.dat extramod=/porteus3.0/Modules volume=40 reboot=cold ramsize=80%
Edit: I just saw that you could run the losetup command without being root. Was losetup not in /sbin in Porteus 3.0.2? If it was, how are you able to access commands from /sbin?

Code: Select all

guest@porteus:~$ which losetup
/sbin/losetup
guest@porteus:~$ ls -l /sbin | grep losetup
-rwxr-xr-x 1 root root   41992 Aug  3  2014 losetup*
guest@porteus:~$ 
I just run what the system allows me to run. If it's a security problem you should talk to one of the developers. :)
Ed

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

Re: Porteus module activation status

Post#17 by Bogomips » 05 Oct 2016, 02:37

Ed_P wrote:

Code: Select all

guest@porteus:~$ which losetup
/sbin/losetup
guest@porteus:~$ ls -l /sbin | grep losetup
-rwxr-xr-x 1 root root   41992 Aug  3  2014 losetup*
guest@porteus:~$ 

Code: Select all

guest@porteus:~$ which losetup
which: no losetup in (/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts:/usr/lib/qt/bin:/usr/lib/qt/bin:/usr/lib/qt/bin)
guest@porteus:~$ ls -l /sbin/losetup 
-rwxr-xr-x 1 root root 73400 Sep  2 21:26 /sbin/losetup*
This is the programming section after all. 8)
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

jssouza
Samurai
Samurai
Posts: 172
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm
Location: Liechtenstein

Re: Porteus module activation status

Post#18 by jssouza » 05 Oct 2016, 05:20

You should consider including support for modules added via the extramod= cheatcode
Good point. I have never used it. May not be straightforward, since the extramod=path in your /proc/cmdline does not look like an absolute path. I will see.


Hi Bogomips,
From the timestamp of ls -l I assume this is on 3.2rc5? What about in 3.0.1?

The reason I had to elevate privileges of this script was because it needed to access losetup and losetup was in /sbin. If /sbin was accessible by a normal user in 3.0.1, then there is no need to give root access to the script in 3.0.1. But what does not make sense is why a system binary is accessible by normal user. Was guest also a super user during 3.0.1? :%)

User avatar
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#19 by Ed_P » 05 Oct 2016, 05:48

^ It works in 3.2rc5 too.

Code: Select all

guest@porteus:~$ ./modules.sh
glibtop(c=2495): [DEBUG] open.c:53 glibtop_open_l(): SIZEOF: 40 - 65648 - 248 - 65624 - 224 - 65624
glibtop(c=2495): [DEBUG] open.c:163 glibtop_open_l(): Calling sysdeps open function.
glibtop(c=2495): [DEBUG] init.c:229 glibtop_init_s(): init_s with features=0x7ffffff and flags=0
find: `/mnt/isoloop': No such file or directory
grep: /tmp/2508_port_modules: No such file or directory
find: `/mnt/isoloop': No such file or directory
Quiet mode: off
grep: /var/log/packages/pepperflash-23.0.0.162-x86_64-1: No such file or directory
Updating shared library links:  /sbin/ldconfig
find: `/mnt/isoloop': No such file or directory
grep: /tmp/2508_port_modules: No such file or directory
ENTRIES="14
"
ENTRY=""
EXIT="0"
You might want to tweak the ENTRIES= quote marks.

As for root access in 3.2rc5

Code: Select all

guest@porteus:~$ which losetup
which: no losetup in (/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts:/opt/kde3/lib64/qt3/bin:/opt/kde3/bin:/opt/kde3/lib64/qt3/bin:/opt/kde3/bin:/opt/kde3/lib64/qt3/bin:/opt/kde3/bin)
guest@porteus:~$ ls -l /sbin | grep losetup
-rwxr-xr-x 1 root root     70272 Dec 11  2015 losetup*
guest@porteus:~$ losetup --help
bash: losetup: command not found
guest@porteus:~$ /sbin/losetup --help

Usage:
 losetup [options] [<loopdev>]
 losetup [options] -f | <loopdev> <file>

Set up and control loop devices.

Options:
 -a, --all                     list all used devices
 -d, --detach <loopdev>...     detach one or more devices
 -D, --detach-all              detach all used devices
 -f, --find                    find first unused device
 -c, --set-capacity <loopdev>  resize the device
 -j, --associated <file>       list all devices associated with <file>

 -o, --offset <num>            start at offset <num> into file
     --sizelimit <num>         device is limited to <num> bytes of the file
 -P, --partscan                create a partitioned loop device
 -r, --read-only               set up a read-only loop device
     --show                    print device name after setup (with -f)
 -v, --verbose                 verbose mode

 -l, --list                    list info about all or specified (default)
 -O, --output <cols>           specify columns to output for --list
 -n, --noheadings              don't print headings for --list output
     --raw                     use raw --list output format
 -J, --json                    use JSON --list output format

 -h, --help     display this help and exit
 -V, --version  output version information and exit

Available --list columns:
         NAME  loop device name
    AUTOCLEAR  autoclear flag set
    BACK-FILE  device backing file
     BACK-INO  backing file inode number
 BACK-MAJ:MIN  backing file major:minor device number
      MAJ:MIN  loop device major:minor number
       OFFSET  offset from the beginning
     PARTSCAN  partscan flag set
           RO  read-only device
    SIZELIMIT  size limit of the file in bytes

For more details see losetup(8).
guest@porteus:~$ 
The which command isn't looking in the /sbin directory probably because it isn't in the default path. But losetup is certainly executable in 3.2rc5 as guest if it's path is specified.
jssouza wrote:
You should consider including support for modules added via the extramod= cheatcode
Good point. I have never used it. May not be straightforward, since the extramod=path in your /proc/cmdline does not look like an absolute path. I will see.
If a path doesn't specify a mounted device it defaults to the booted device. So for extramods= paths lacking the device you may need to manually add it to the path. This should do it for you.

Code: Select all

# http://forum.porteus.org/viewtopic.php?f=53&t=3801&start=30#p28472
BOOTDEV=`grep -A1 "Booting" /var/log/porteus-livedbg|tail -n1|sed 's^//^/^g'`
if [ "$BOOTDEV" == "/mnt/isoloop" ]; then
   BOOTDEV=`grep -A1 "ISO=" /var/log/porteus-livedbg`
   BOOTDEV=${BOOTDEV:4:9}
fi
TYPE=`grep "/dev/${BOOTDEV:5}" /var/log/porteus-livedbg`
Ed

jssouza
Samurai
Samurai
Posts: 172
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm
Location: Liechtenstein

Re: Porteus module activation status

Post#20 by jssouza » 05 Oct 2016, 07:20

This should do it for you.
Unfortunately it does not. This only shows the booted device, which I am already able to retrieve. Need to get the extramod path when it does not default to the boot device. But, thanks for the link. I see that the big guys are actually talking about the implementation there. I will go through it.
The which command isn't looking in the /sbin directory probably because it isn't in the default path. But losetup is certainly executable in 3.2rc5 as guest if it's path is specified.
Yes, you are right. But in 3.0.1 in your earlier post, you were able to run losetup -a without the full path, and as normal user. I was wondering how you could do it there.

EDIT:
Aha! Looks like someone has already commented about it! viewtopic.php?f=117&t=3205&p=27547#p27567. Also your reply in the next following post. I guess you have it set in your bashrc. Now it makes sense :)

User avatar
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#21 by Ed_P » 05 Oct 2016, 15:07

jssouza wrote:Need to get the extramod path when it does not default to the boot device.
If the extramod cheatcode refers to a directory other than on the boot device the user includes it in the extramod's path.

Some uses of the cheatcode I use.

Code: Select all

extramod=/porteus3.0/Modules 
extramod=/dev/sda5/porteus3.x/Modules
extramod=/porteus3.0/Optional;/porteus3.0/Modules;/porteus3.0/modsavedat 
Aha! Looks like someone has already commented about it! viewtopic.php?f=117&t=3205&p=27547#p27567. Also your reply in the next following post. I guess you have it set in your bashrc. Now it makes sense :)

:o Now I have to figure out how and why. :unknown:


The answer: https://forum.porteus.org/viewtopic.php ... 154#p23138
Ed

jssouza
Samurai
Samurai
Posts: 172
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm
Location: Liechtenstein

Re: Porteus module activation status

Post#22 by jssouza » 05 Oct 2016, 20:07

Here's the updated script that should work with extramod cheatcode. All the extramod formats (relative path, absolute path, UUID, LABEL) should work. I reused parts of some utility functions of linuxrc.

Code: Select all

#! /bin/bash

if [ "$UID" -ne 0 ]; then
  if [ "$DISPLAY" ]; then
    ktsuss $0
  else
    echo "Enter root password" 
    su -c $0
  fi
  exit
fi

export MODULE_LOAD_DIR="/mnt/live/memory/images"
export TMPFILE="/tmp/${$}_port_modules"
export LOADEDENTRIES="grep -c gtk-yes $TMPFILE"
export NUMENTRIES="wc -l $TMPFILE | cut -f 1 -d ' '"
export PORTROOTDIR=`grep -A1 "Porteus data found in" /var/log/porteus-livedbg | tail -n1`

trap sigint_handler INT
sigint_handler()
{
    rm -f "$TMPFILE"
}

function value() { egrep -o " $1=[^ ]+" /proc/cmdline | cut -d= -f2; }

function search() 
{
 local FOUND=""
 for x in `ls /mnt | tac`; do
  if [ -e /mnt/$x/$1 ]; then
   FOUND="$x"
   break
  fi
 done
 echo $FOUND
}

export EXTRAMODS=`value extramod | sed 's/;/ /g'`

function load_remaining_modules
{
  local PORTMODULES="$(ls $MODULE_LOAD_DIR | sort)"
  for PORTMODULE in $PORTMODULES
  do
     local MODNAME="$(basename -a $PORTMODULE)"
     if ! grep -q "$MODNAME" "$TMPFILE"; then
       local MODDIR="$(losetup  -a | grep $MODNAME | cut -d \( -f2 | cut -d \) -f1)"
	   echo "gtk-yes|${MODNAME}|${MODDIR}" >> "$TMPFILE"
     fi
  done   
}

function load_modules
{
  local PORTMODULES="$(find $PORTROOTDIR -name "*.xzm" | sort)"
  for PORTMODULE in $PORTMODULES
  do
     local MODNAME="$(basename -a $PORTMODULE)"
     local MODDIR="$(dirname $PORTMODULE)"
     local OUT="${MODNAME}|${MODDIR}"
  
     if [ -e "${MODULE_LOAD_DIR}/${MODNAME}" ]; then
       echo "gtk-yes|${OUT}" >> "$TMPFILE"
     else 
       echo "gtk-no|${OUT}" >> "$TMPFILE"
     fi
  done

  if [ "$EXTRAMODS" ]; then
   for EXTRAMOD in $EXTRAMODS; do
    EXTRAMOD="$(echo $EXTRAMOD | egrep -w '^\/mnt' || echo $EXTRAMOD | cut -d \/ -f2-)"
	RET=$(search $EXTRAMOD)
	if [ $RET ]; then
     PORTMODULES="$(find /mnt/${RET}/${EXTRAMOD} -name "*.xzm" | sort)"
    else
     PORTMODULES="$(find ${EXTRAMOD} -name "*.xzm" | sort)"
    fi     
	for PORTMODULE in $PORTMODULES
	do
	  local MODNAME="$(basename -a $PORTMODULE)"
	  local MODDIR="$(dirname $PORTMODULE)"
	  local OUT="${MODNAME}|${MODDIR}"
		  
	  if [ -e "${MODULE_LOAD_DIR}/${MODNAME}" ]; then
	   echo "gtk-yes|${OUT}" >> "$TMPFILE"
	  else 
	   echo "gtk-no|${OUT}" >> "$TMPFILE"
	  fi
	done
   done
  fi
  load_remaining_modules 
}

function activate_module
{
  if [ "$1" = "" ]; then return; fi

  local MODDIR="$(grep $1 $TMPFILE | cut -f 3 -d "|")"
  local MODULE="${MODDIR}/${1}"

  if [ -e "${MODULE_LOAD_DIR}/${1}" ]; then
   deactivate "$MODULE"
  else 
   activate "$MODULE"
  fi

  rm -f "$TMPFILE"
  load_modules
}

export -f load_modules
export -f load_remaining_modules
export -f activate_module
export -f value
export -f search

load_modules

export MODULES_MAIN='
<window window_position="1" title="Porteus Modules" default-height="550" default-width="500" icon-name="cdr" resizable="true">
<vbox>
 <text use-markup="true">
  <label>"<span weight='"'bold'"'>Modules Activated</span>"</label>
 </text>
 <text>
  <variable>ENTRIES</variable>
  <input>'$LOADEDENTRIES'</input>
 </text>
 <tree selection-mode="1" file-monitor="true">
  <variable>ENTRY</variable>
  <label>"Module Name                        |Containing Directory               "</label> 
  <input file icon_column="0">'$TMPFILE'</input>
  <action signal="row-activated">"activate_module $ENTRY"</action>
  <action signal="file-changed" type="refresh">ENTRY</action>
  <action signal="file-changed" type="refresh">ENTRIES</action>
 </tree> 
 <hseparator default-width="300"></hseparator> 
 <hbox> 
  <button space-fill="true">
   <label>Exit</label> 
   <action>exit:0</action> 
  </button>  
 </hbox> 
</vbox> 
</window>
'  

gtkdialog --program=MODULES_MAIN -c
rm -f $TMPFILE

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

Re: Porteus module activation status

Post#23 by Bogomips » 05 Oct 2016, 23:50

jssouza wrote:All the extramod formats (relative path, absolute path, UUID, LABEL) should work. I reused parts of some utility functions of linuxrc.
No problem with absolute path, UUID, LABEL, if by absolute path is meant /mnt/sdxY/Path/to/<Modules Directory>. However there is, I believe, a slight caveat regarding relative path.

If boot parameter extramod=p/mods stipulated, where p=/Path/to/<Modules Directory>, then should at boot time extra modules be loaded from /dev/sdbY/p/mods, and later another usb stick plugged in, where /mnt/sdcZ/p/mods is a directory of modules, modules originating from /mnt/sdbY/p/mods could be ascribed as being activated from /mnt/sdcZ/p/mods.
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
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#24 by Ed_P » 06 Oct 2016, 04:42

jssouza wrote:Here's the updated script that should work with extramod cheatcode. All the extramod formats (relative path, absolute path, UUID, LABEL) should work. I reused parts of some utility functions of linuxrc.
:good:

Code: Select all

guest@porteus:~$ ./modules.sh
glibtop(c=2902): [DEBUG] open.c:53 glibtop_open_l(): SIZEOF: 40 - 65648 - 248 - 65624 - 224 - 65624
glibtop(c=2902): [DEBUG] open.c:163 glibtop_open_l(): Calling sysdeps open function.
glibtop(c=2902): [DEBUG] init.c:229 glibtop_init_s(): init_s with features=0x7ffffff and flags=0
find: `/mnt/isoloop': No such file or directory
ENTRIES="15
"
ENTRY="009-caches.xzm"
EXIT="0"
guest@porteus:~$ 
Why are you looking for /mnt/isoloop? My isoloop is at /mnt/live/mnt/isoloop. And in fact I think you should list the modules found in it before the modules found in the extramod folders since that is the sequence they are loaded. 000-kernel, 001-core, 002-xorg and 003-cinnamon.

Directing the glibtop messages to /dev/null would yield a cleaner terminal look. But overall an impressive script. :good:
Ed

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

Porteus module activation status: extramod relative path

Post#25 by Bogomips » 06 Oct 2016, 13:24

Extramod Relative Path

Upon further deliberation, if there is no copy2ram the search could be modified to replace output of blkid by the Recognized devices list in /var/log/porteus-livedbg. :wink:

Edit

Or edit the search to reject devices not in the Recognized devices list, whichever is easier.
Last edited by Bogomips on 06 Oct 2016, 15:47, edited 1 time in total.
Reason: Edit
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
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#26 by Ed_P » 06 Oct 2016, 16:55

Interesting that /var/log/porteus-livedbg shows the Booting device: as /mnt/isoloop when it's true path for me is /mnt/live/mnt/isoloop.

Code: Select all

root@porteus:/home/guest# ls /mnt/isoloop
/bin/ls: cannot access '/mnt/isoloop': No such file or directory
root@porteus:/home/guest# ls /mnt/isoloop/
/bin/ls: cannot access '/mnt/isoloop/': No such file or directory
root@porteus:/home/guest# ls /mnt/isoloop/*
/bin/ls: cannot access '/mnt/isoloop/*': No such file or directory
root@porteus:/home/guest# ls /mnt/live/mnt/isoloop/
EFI/  USB_INSTALLATION.txt  boot/  porteus/
root@porteus:/home/guest# 
Ed

jssouza
Samurai
Samurai
Posts: 172
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm
Location: Liechtenstein

Re: Porteus module activation status

Post#27 by jssouza » 06 Oct 2016, 18:11

Bogomips wrote:If boot parameter extramod=p/mods stipulated, where p=/Path/to/<Modules Directory>, then should at boot time extra modules be loaded from /dev/sdbY/p/mods, and later another usb stick plugged in, where /mnt/sdcZ/p/mods is a directory of modules, modules originating from /mnt/sdbY/p/mods could be ascribed as being activated from /mnt/sdcZ/p/mods.
Good point Bogomips. Also thank you for the suggestions regarding the recognized devices list in /var/log/porteus-livedbg. I will try with that.
Ed_P wrote:Why are you looking for /mnt/isoloop?
I think this is losetup. I could not find a way to filter only squashfs, and I guess because you are booting directly from an iso, it also shown that. Moreover, as you mention, since it cannot find the actual path to it, it is complaining.
You can ignore it.
Ed_P wrote:And in fact I think you should list the modules found in it before the modules found in the extramod folders since that is the sequence they are loaded. 000-kernel, 001-core, 002-xorg and 003-cinnamon.
Are they not in that order? For me the base/modules/optional are shown first, then the extramods.

I will finally redirect the output. But you can always create a .desktop file and run it directly as a shortcut.

User avatar
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#28 by Ed_P » 06 Oct 2016, 18:32

jssouza wrote:
Ed_P wrote:Why are you looking for /mnt/isoloop?
I think this is losetup. I could not find a way to filter only squashfs, and I guess because you are booting directly from an iso, it also shown that.
Yes I am booting from an iso but the Boot device: path shown in cat /var/log/porteus-livedbg is misleading as are the paths it shows for the base modules, /mnt/isoloop/porteus/base/00*. The actual paths are /mnt/image/mnt/isoloop/.
Ed_P wrote:And in fact I think you should list the modules found in it before the modules found in the extramod folders since that is the sequence they are loaded. 000-kernel, 001-core, 002-xorg and 003-cinnamon.
Are they not in that order? For me the base/modules/optional are shown first, then the extramods.
I wouldn't mention it if they weren't. :D I'm seeing the mods in the extramods directory then the /mnt/live/mnt/isoloop/porteus/base mods and finally the changes= save.dat mod.
Ed

jssouza
Samurai
Samurai
Posts: 172
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm
Location: Liechtenstein

Re: Porteus module activation status

Post#29 by jssouza » 06 Oct 2016, 20:18

Updated the script to handle extramod parameters using porteus-livedbg. Also did some gtkdialog related changes.

Code: Select all

#! /bin/bash

if [ "$UID" -ne 0 ]; then
  if [ "$DISPLAY" ]; then
    ktsuss $0
  else
    echo "Enter root password" 
    su -c $0
  fi
  exit
fi

export MODULE_LOAD_DIR="/mnt/live/memory/images"
export TMPFILE="/tmp/${$}_port_modules"
export LOADEDENTRIES="grep -c gtk-yes $TMPFILE | tr -d '\n'"
export NUMENTRIES="wc -l $TMPFILE | cut -f 1 -d ' '"
export PORTROOTDIR=`grep -A1 "Porteus data found in" /var/log/porteus-livedbg | tail -n1`

trap sigint_handler INT
sigint_handler()
{
    rm -f "$TMPFILE"
}

function value() { egrep -o " $1=[^ ]+" /proc/cmdline | cut -d= -f2; }

function search() 
{
 local FOUND=""
 for x in `ls /mnt | tac`; do
  if [ -e /mnt/$x/$1 -a $(grep -c "/mnt/$x/$1" /var/log/porteus-livedbg) -ne 0 ]; then
   FOUND="$x"
   break
  fi
 done
 echo $FOUND
}

export EXTRAMODS=`value extramod | sed 's/;/ /g'`

function load_remaining_modules
{
  local PORTMODULES="$(ls $MODULE_LOAD_DIR | sort)"
  for PORTMODULE in $PORTMODULES
  do
     local MODNAME="$(basename -a $PORTMODULE)"
     if ! grep -q "$MODNAME" "$TMPFILE"; then
       local MODDIR="$(losetup  -a | grep $MODNAME | cut -d \( -f2 | cut -d \) -f1)"
	   echo "gtk-yes|${MODNAME}|${MODDIR}" >> "$TMPFILE"
     fi
  done   
}

function load_modules
{
  local PORTMODULES="$(find $PORTROOTDIR -name "*.xzm" | sort)"
  for PORTMODULE in $PORTMODULES
  do
     local MODNAME="$(basename -a $PORTMODULE)"
     local MODDIR="$(dirname $PORTMODULE)"
     local OUT="${MODNAME}|${MODDIR}"
  
     if [ -e "${MODULE_LOAD_DIR}/${MODNAME}" ]; then
       echo "gtk-yes|${OUT}" >> "$TMPFILE"
     else 
       echo "gtk-no|${OUT}" >> "$TMPFILE"
     fi
  done

  if [ "$EXTRAMODS" ]; then
   for EXTRAMOD in $EXTRAMODS; do
    echo $EXTRAMOD | egrep -q '^UUID|^LABEL' && EXTRAMOD="$(echo $EXTRAMOD | cut -d \/ -f2-)"
    echo $EXTRAMOD | egrep -q '^/mnt/' && EXTRAMOD="$(echo $EXTRAMOD | cut -d \/ -f4-)"
	RET=$(search $EXTRAMOD)
	if [ $RET ]; then
     PORTMODULES="$(find /mnt/${RET}/${EXTRAMOD} -name "*.xzm" | sort)"
    else
     PORTMODULES="$(find ${EXTRAMOD} -name "*.xzm" | sort)"
    fi     
	for PORTMODULE in $PORTMODULES
	do
	  local MODNAME="$(basename -a $PORTMODULE)"
	  local MODDIR="$(dirname $PORTMODULE)"
	  local OUT="${MODNAME}|${MODDIR}"
		  
	  if [ -e "${MODULE_LOAD_DIR}/${MODNAME}" ]; then
	   echo "gtk-yes|${OUT}" >> "$TMPFILE"
	  else 
	   echo "gtk-no|${OUT}" >> "$TMPFILE"
	  fi
	done
   done
  fi
  load_remaining_modules 
}

function activate_module
{
  if [ "$1" = "" ]; then return; fi

  local MODDIR="$(grep $1 $TMPFILE | cut -f 3 -d "|")"
  local MODULE="${MODDIR}/${1}"

  if [ -e "${MODULE_LOAD_DIR}/${1}" ]; then
   deactivate "$MODULE"
  else 
   activate "$MODULE"
  fi

  rm -f "$TMPFILE"
  load_modules
}

export -f load_modules
export -f load_remaining_modules
export -f activate_module
export -f value
export -f search

load_modules

export MODULES_MAIN='
<window window_position="1" title="Porteus Modules" default-height="550" default-width="500" icon-name="cdr" resizable="true" decorated="true">
<vbox>
 <hbox>
  <text>
   <label>"Modules Activated: "</label>
  </text>
  <text>
   <variable>ENTRIES</variable>
   <input>'$LOADEDENTRIES'</input>
  </text>
 </hbox>
 <tree homogeneous="true" selection-mode="1" file-monitor="true">
  <variable>ENTRY</variable>
  <label>"Module Name                        |Containing Directory               "</label> 
  <input file icon_column="0">'$TMPFILE'</input>
  <action signal="row-activated">"activate_module $ENTRY"</action>
  <action signal="file-changed" type="refresh">ENTRY</action>
  <action signal="file-changed" type="refresh">ENTRIES</action>
 </tree> 
 <hseparator default-width="300"></hseparator> 
 <hbox> 
  <button space-fill="true">
   <label>Exit</label> 
   <action>exit:0</action> 
  </button>  
 </hbox> 
</vbox> 
</window>
'  

gtkdialog --program=MODULES_MAIN -c
rm -f $TMPFILE
Ed_P wrote:Directing the glibtop messages to /dev/null would yield a cleaner terminal look.
This can be also be done by executing the script as

Code: Select all

./script.sh > /dev/null 2>&1

User avatar
Ed_P
Contributor
Contributor
Posts: 3058
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Porteus module activation status

Post#30 by Ed_P » 06 Oct 2016, 21:48

jssouza wrote:Updated the script to handle extramod parameters using porteus-livedbg. Also did some gtkdialog related changes.
Sequence is still extramods, then porteus/base mods, then changes.
Ed

Post Reply