XZM module creation

Non release banter
Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#1 by Vic » 26 Nov 2023, 04:38

Hi everyone.

Am having a great time with PorteuX. For me it is equal to Porteus 3.1 back in the old days. It did everything I wanted and needed.

KDE is my favorite desktop. I have been trying to expand the service menus to the point of not needing to use the terminal at all. Lazy I am.

While messing with a .tgz script, I noticed that the tgz code made a compressed nested folder group all the way up to /. Not what I wanted but it created a folder hierarchy from the source folder on up that looked suitable for making a .xzm module.

The code is:

Code: Select all

file=%f; tar cf %f-"$(date +%y-W%W-%e_%H-%M-%S-%b)".tgz %f
I normally have to manually create the nested folders for whatever module I want. I keep an empty directory from / on down to draw what I need.

At first there was just a .tgz file with the name and date like I wanted. Too bad the guts were wrong.

I extracted the file and started to think about how I could use this to make the creation of .xzm modules a bit easier.

Once extracted, the result was all I needed to place into an appropriately named folder to transform into a .xzm module.

Then I realized I could automate stuff. I added to the code little by little and trying each change.

After getting the archive I extracted it to a folder, then removed the archive and what was left is the nested folder hierarchy under /.

Here is the result:

Code: Select all

file=%f; tar cf %f.tgz %f && tar -xf *.tgz && rm *.tgz %f &
The original file is now in the nested folders, the .tgz file is gone and all I need to do is create the folder with whatever name I want and move the new folder hierarchy into it.

The only thing I do not like is having to mess with the .tgz aspect at all. I do not know enough about this stuff to deal with that. If anyone has suggestions they would be really cool to know. At least I got what I wanted and had some fun with the cli.

Vic

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XZM module creation

Post#2 by Rava » 26 Nov 2023, 06:08

Why not look into how txz2xzm manages the module creation and use txz2xzm as template for creating a tgz2xzm?
At least I would not re-invent the wheel for the umpteenth of time but use free and open sources to build what I want. Image
Cheers!
Yours Rava

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#3 by Vic » 26 Nov 2023, 06:27

I looked at all of the converter files in opt and got dizzy. Think I will use what I have for a while.

I was just asking for a little info about tgz. Sounds like alot of work, lazy and all.

Thanks

Vic

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XZM module creation

Post#4 by Rava » 26 Nov 2023, 06:33

Code: Select all

root@rava:/# wc /opt/porteus-scripts/txz2xzm
 103  357 2544 /opt/porteus-scripts/txz2xzm
103 lines of code is not that much to parse, especially when you use an editor with syntax highlighting (like geany or mousepad)

But that might be just me. :D
Cheers!
Yours Rava

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#5 by Vic » 26 Nov 2023, 06:37

You and others here like you are awesome Rava.

Outta my league.

Vic

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

XZM module creation

Post#6 by Ed_P » 26 Nov 2023, 06:51

Vic this is a script I use to create a module of my nemo bookmarks. It's rather simple and basic, to match my skill set. :D

Code: Select all

#!/bin/bash

# Save changes as a mod file 

# https://forum.porteus.org/viewtopic.php?f=81&t=5981&start=15#p46643

MOD=mynemochanges   # mychanges-$(date +%Y%m%d)
TO=Modules
SYSTM=

# http://forum.porteus.org/viewtopic.php?f=53&t=3801&start=30#p28472
BOOT=`grep -A1 "Porteus data found in:" /var/log/porteus-livedbg|tail -n1|sed 's^//^/^g'`
DRV=${BOOT:5:4}
if [ "$DRV" == "isol" ]; then
   ISOBOOT=`grep -A1 "//porteus" /var/log/porteus-livedbg|tail -n2|sed 's^//^/^g'`
   SYSTM="${ISOBOOT:10:10}/"
   DRV=${ISOBOOT:5:4}
fi
if [ "$DRV" == "nvme" ]; then
   SYSTM="${ISOBOOT:15:10}/"
   DRV=${ISOBOOT:5:9}
fi

CHANGES=/mnt/$DRV/$SYSTM$TO/$MOD

if [ "$1" == "r" ] && [ "$2" != "" ] ; then
   CHANGES="$2"
fi

# Color definitions               # ups.sh
txtbld=$(tput bold)               # Bold
txtred=${txtbld}$(tput setaf 1)   # Bold Red
txtgreen=${txtbld}$(tput setaf 2) # Bold Green 
txtcyan=${txtbld}$(tput setaf 6)  # Bold Cyan
rst=$(tput sgr0)                  # Reset

function redpswd() {
  echo -E "$1" $txtred  
}
function cyan() {
  echo -E "$1" $txtcyan
}

if [ `whoami` != "root" ]; then
   echo toor | sudo -S  echo "******"
   sudo sh $0 $1 $2
   exit
fi
#echo $rst

if [ -d /tmp/mod/ ]; then
   rm -rf /tmp/mod
fi
mkdir -p /tmp/mod

# copy modified files

#                  -- File Manager - nemo - bookmarks --
cp -a --parents          /root/.config/nemo*                      /tmp/mod/
cp -a --parents          /root/.config/gtk-3.0/*                  /tmp/mod/
cp -a --parents    /home/guest/.config/nemo/*                     /tmp/mod/
cp -a --parents    /home/guest/.config/gtk-3.0/*                  /tmp/mod/

du -h    /tmp/mod/   | grep "[0-9]M"
echo
echo Changed files copied. Press Enter to create module, Ctrl+C to exit.
echo

if [ -f $CHANGES*.xzm ]; then
   CF=`ls -lght --time-style long-iso $CHANGES*.xzm | awk '{print $5,$6}'`
   if [ ${CF:11:2} -lt 12 ]; then
      CF=$CF"am"
   else
      PM=$((${CF:11:2} - 12))
      if [ $PM == 0 ]; then PM=12; fi
      CF=${CF:0:11}$PM${CF:13}"pm"
   fi
   CFS=`ls -lght --time-style long-iso $CHANGES.xzm | awk '{print $4}'`
   echo Current file:  $CFS $CF
fi
read

dir2xzm  /tmp/mod /tmp/$MOD.xzm   &&   rm -rf /tmp/mod

echo 
ls -sh   /tmp/*.xzm

DIR () {
ls -lght --time-style long-iso $1 | awk '{print $5,$6,$4,$7}'
}

echo
echo Press Enter to copy /tmp/$MOD.xzm to $SYSTEM$TO, Ctrl+C to exit.
DIR     /tmp/$MOD.xzm 
if [ -f $CHANGES*.xzm ]; then
   DIR     $CHANGES*.xzm
fi 
read
if [ -f $CHANGES*.xzm ]; then
   mv      $CHANGES*.xzm $CHANGES.xyzm
fi
cp      /tmp/$MOD.xzm  /mnt/$DRV/$SYSTM$TO
sleep 1
rm      /tmp/$MOD.xzm
echo Finished!
sleep 1
The code is rather simple and if there's a section you don't understand ask for an explanation.

The top determines what drive I've booted from. ISO, SSD, USB.
The middle determines if I've signed in as root. With colors.
The bottom makes the module and asks if I want to copy the module to my Modules folder.
Ed

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#7 by Vic » 26 Nov 2023, 12:46

Thanks Ed.

After Rava said "103 lines of code is not that much" I realized I was not ready for that rabbit hole. So I hit the sack.

This morning I took a look at your offering.

Your script is also over 100 lines, so I guess I just need to buckle down and dig in.

Thanks to you both.

Vic

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XZM module creation

Post#8 by Rava » 26 Nov 2023, 15:15

Vic wrote:
26 Nov 2023, 12:46
Your script is also over 100 lines, so I guess I just need to buckle down and dig in.
Consider that some lines will be comments. And coders often use descriptive names for variables. Both make editing and enhancing a script much more easy.

And remember: the time it takes you to create a script is rewarded hundredfold in the future when you just execute that one script and it does all the work for you all by itself in mere seconds.

And please do post your result in here. Others will learn by your example, and some of us might have suggestion to make an already working script even better. :friends:
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 8374
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

XZM module creation

Post#9 by Ed_P » 26 Nov 2023, 16:21

Vic wrote:
26 Nov 2023, 12:46
Your script is also over 100 lines
Yes but a third of the lines are blank or start with a # . :D

Added in 21 minutes 57 seconds:
82 functional lines. And you can delete this group of 13 that aren't used in this script.

Code: Select all

# Color definitions               # ups.sh
txtbld=$(tput bold)               # Bold
txtred=${txtbld}$(tput setaf 1)   # Bold Red
txtgreen=${txtbld}$(tput setaf 2) # Bold Green 
txtcyan=${txtbld}$(tput setaf 6)  # Bold Cyan
rst=$(tput sgr0)                  # Reset

function redpswd() {
  echo -E "$1" $txtred  
}
function cyan() {
  echo -E "$1" $txtcyan
}
So that leaves you only ~70 lines to figure out and the key ones for your module are the cp -a lines. :happy62:
Ed

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#10 by Vic » 26 Nov 2023, 17:28

So my goal is to make a .desktop file in servicemenus that creates a module for any folder or file I right click on. Two clicks of the mouse.

Whether it points to a *.sh file or the code is in the .desktop file does not matter.

The new module will have the name of the target folder or file. Inside will be the file hierarchy for the target.

Save it to /tmp. If it works it will be moved into the porteux folder somewhere.

I just need to adapt some of what code is available to do what I want.

Thanks you two for trying to soften the blow. All I saw was 100 plus lines. I will be ok now.

I will get back after fiddling for a while.

Vic

rych
Warlord
Warlord
Posts: 622
Joined: 04 Jan 2014, 04:27
Distribution: Porteus 5.0 x64 OpenBox
Location: NZ
Contact:

XZM module creation

Post#11 by rych » 27 Nov 2023, 09:43

Vic wrote:
26 Nov 2023, 17:28
So my goal is to make a .desktop file in servicemenus that creates a module for any folder or file I right click on
Take a look at my one-liner script and .desktop file for context menu invocation in why modules (Post by rych #91537) :
rych wrote:
19 Nov 2022, 06:59
let's make an entry for turning any folder into a .squashfs image. We could build an zstd module and change the extension, but the invoked command is slow for large folders, as it uses the hardest compression parameter. Also, it's interesting to see how one turns a folder into an AppImage https://docs.appimage.org/packaging-guide/manual.html. Anyway, we can write our own one-liner script squashfs_create below and add another context menu command:

Code: Select all

root@porteus:~# cat /usr/share/applications/squashfs-create.desktop
[Desktop Entry]
Name=Build SquashFS
Icon=cdr
MimeType=inode/directory
NoDisplay=true
Terminal=true
Exec=squashfs_create %F

and the squashfs_create script is just:

Code: Select all

#!/bin/bash
mksquashfs $1 $1.sqfs -noappend -comp zstd -b 256K
XZM modules are Squashfs containers, so just edit the above: $1.sqfs --> $1.xzm and so on.

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#12 by Vic » 27 Nov 2023, 16:53

Hi rych.

I do not want to deal with anything big so size is not a problem.

It looks like everything I want to do is already existing so all I need to do is figure it out.

Making any file or folder an XZM is easy with the Porteus tools. And fun too.

I already have a right click context menu for XZM creation that looks like this:
ANY-2-XZM
-------DIRECTORY-2-XZM
-------XZM-2-DIRECTORY
-------RPM-2-XZM
-------TGZ-2-XZM
-------DEB-2-XZM

I want to add something like this:
-------SERVICE-MENU-2-XZM
-------DESKTOP-2-XZM
-------ROOT-CONFIG-2-XZM
-------ROOT-2-XZM

Basically anywhere I want the specific file or folder to go will be automagically done witk 2 clicks.
Sweet.

So I will be able to click on the .mozilla folder in /root and choose --ROOT-2-XZM-- in the menu and a module will be created wherever I choose.
The module , when activated, will place the .mozilla folder in /root whether at boot time or anytime I want.

Still fiddling.

Vic

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#13 by Vic » 28 Nov 2023, 00:22

Ok Rava, you said to post my progress, so here it is.

I am now able to right click any file or folder that I have tested in the usual directories (/root , /root/.config and such) and have the xzm module appear in porteux/optional.

I use my name in caps to make it easier to see in the code. Not 100 lines yet but all good.

Code: Select all

[Desktop Action 3]
Name=DIR-4-XZM
Icon=password-copy
Exec=file=%f; mkdir /root/Desktop/VIC && cd /root/Desktop/VIC && tar cf %f.tgz %f && tar -xf %f.tgz && rm %f.tgz && /opt/porteux-scripts/dir2xzm /root/Desktop/VIC && cp -f /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional &
file=%f -- is the folder or file that I right click on

mkdir /root/Desktop/VIC -- makes a directory on the Desktop - I picked the Desktop because it resets at boot

cd /root/Desktop/VIC -- Just changes the working directory

tar cf %f.tgz %f -- tars the file or folder that I right clicked. I was messing with .tar archiving on another project and noticed how it saves directories inside, making me think I could do .xzm building a little easier, so I put it here until I know more about getting the directories some other way

tar -xf %f.tgz -- extracts the tar archive with the directory hierarchy all the way up to root, which is what I want

rm %f.tgz -- removes the tar archive

/opt/porteux-scripts/dir2xzm /root/Desktop/VIC -- engages the dir2xzm from PorteuX on the new directory

cp -f /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional -- copies the new xzm module to porteux/optional

And that is it. Boy is this fun. I do not really know anything about bashing but bringing all the pieces together is a blast.

Thanks to everybody for your help and handholding.

Vic

User avatar
Rava
Contributor
Contributor
Posts: 5416
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

XZM module creation

Post#14 by Rava » 28 Nov 2023, 01:57

Vic wrote:
28 Nov 2023, 00:22

Code: Select all

[Desktop Action 3]
Name=DIR-4-XZM
Icon=password-copy
Exec=file=%f; mkdir /root/Desktop/VIC && cd /root/Desktop/VIC && tar cf %f.tgz %f && tar -xf %f.tgz && rm %f.tgz && /opt/porteux-scripts/dir2xzm /root/Desktop/VIC && cp -f /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional &
file=%f -- is the folder or file that I right click on

mkdir /root/Desktop/VIC -- makes a directory on the Desktop - I picked the Desktop because it resets at boot

cd /root/Desktop/VIC -- Just changes the working directory

tar cf %f.tgz %f -- tars the file or folder that I right clicked. I was messing with .tar archiving on another project and noticed how it saves directories inside, making me think I could do .xzm building a little easier, so I put it here until I know more about getting the directories some other way

tar -xf %f.tgz -- extracts the tar archive with the directory hierarchy all the way up to root, which is what I want

rm %f.tgz -- removes the tar archive

/opt/porteux-scripts/dir2xzm /root/Desktop/VIC -- engages the dir2xzm from PorteuX on the new directory

cp -f /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional -- copies the new xzm module to porteux/optional
Nice one-liner you created there. Thanks for sharing, and special thanks for the detailed explanation.

Vic
Samurai
Samurai
Posts: 122
Joined: 10 Aug 2016, 05:36
Distribution: Porteux V-0.1 64 KDE
Location: Utopia in Tampa, Florida, USA

XZM module creation

Post#15 by Vic » 28 Nov 2023, 04:20

Welp, I was not happy with the working folder remaining on the Desktop, and I wanted to add the date and time to the .xzm module. So I made some adjustments to the "one liner". When does a "one liner" need to become more lines?

Code: Select all

[Desktop Action 3]
Name=DIR-4-XZM
Icon=password-copy
Exec=file=%f; mkdir /root/Desktop/VIC && cd /root/Desktop/VIC && tar cf %f.tgz %f && tar -xf %f.tgz && rm %f.tgz && /opt/porteux-scripts/dir2xzm /root/Desktop/VIC && mv /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional/VIC-$(date +%y-W%W-%e_%H-%M-%S-%b).xzm && rm -rf yes /root/Desktop/VIC &
I removed --
cp -f /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional

and replaced it with --
mv /root/Desktop/VIC/VIC.xzm /mnt/nvme0n1p3/porteux/optional/VIC-$(date +%y-W%W-%e_%H-%M-%S-%b).xzm

which adds the date and time to the new .xzm module.

I Duck searched how to rename the .xzm so I could put the date and time on. This website did the trick:

https://phoenixnap.com/kb/rename-file-linux

Instead of renaming the file you need to move it. Even in the same directory if a different name is specified then the mv command works.

As far as removing the working folder on the Desktop this website showed the magic:

https://stackoverflow.com/questions/683 ... -directory

removing the folder from the Desktop --
rm -rf yes /root/Desktop/VIC

Now the Desktop is free to perform another operation without needing to manually delete the old working folder.

I open two dolphin windows, one on the target to xzm-ize and the other showing porteux/optional. I figured that is the best place until I decide otherwise.

The working folder on the Desktop does not even show up because the operation is so fast. Wow. And the shiny new .xzm now has the date and time before the extension.

Still fiddling...

Vic

Post Reply