[Bundle]Simple Newbies Module Script

Post tutorials, HOWTO's and other useful resources here.
Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

[Bundle]Simple Newbies Module Script

Post#1 by Bogomips » 10 Sep 2014, 18:18

Dabbling with a script to take drudgery out of making modules from '.txz' files independently for testing, using method shown here. As a newbie one wishes to quickly make modules, juggling dependencies, for one's preferred programs from all sorts of sites, to try out. (Have to have kdelibs, and somehow or other managed to avoid KDE, the full monty.) Script is geared to system where space is sparse. Uses temporary installation(fakeroot) directory by default. (Don't expect production standard coding.)

Running without arguments (-q quiet):

Code: Select all

guest@porteus:~$ sh p10/Por/xzmod.sh 
Usage
=====
xzmod  [-q]  <File with '.txz' Package List>  [ <Fakeroot Directory>  [<Module File>] ]

1st Par: [<path>/]<file name>[.<ext>]   Text file holding list of '.txz' package files, one per line. If no extension try with '.txt', then without. Default module name set to basename minus extension.

2nd Par: [<path>[/<Assigned Dir>]]      Existing path for Temporary Fakeroot Dir, otherwise new Fakeroot Dir. Default module name reset to name of new Fakeroot Directory.

3rd Par: [<path>[/<Module Name>.xzm]]   Existing/Non-existing path for xzm Module File.
Also more options in comments, but KISS for now.

Sample Scenarios

Using as example, file with short packages list, required to create an Abiword dependencies module.

Code: Select all

guest@porteus:~$ cat abw_080914.txt 
p10/Por/Space/gtk+3-3.8.2-i486-2.txz
/tmp/usm/at-spi2-atk-2.8.1-i486-1.txz
at-spi2-core-2.8.0-i486-1.txz
Files listed one per line with relative or absolute paths.
  1. Current directory as work directory and module directory: Module name taken from packages' text file name.

    Code: Select all

    root@porteus:/home/guest# sh p10/Por/xzmod.sh abw_080914.txt
    Text File = abw_080914.txt
    Basename without Extension = abw_080914
    Default Module Name: abw_080914.xzm
    
    Installing to Fakeroot Directory
    
    gtk+3-3.8.2-i486-2: GTK+ version 3 multi-platform GUI toolkit            [57M] 
    at-spi2-atk-2.8.1-i486-1: AT-SPI2 bridge to ATK                          [280K]
    at-spi2-core-2.8.0-i486-1: Assistive Technology Service Provider Interfa [2.1M]
    
    Creating Module abw_080914.xzm
    
    Parallel mksquashfs: Using 1 processor
    Creating 4.0 filesystem on ./abw_080914.xzm, block size 262144.
    [=========================================================================/] 1534/1534 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 10787.27 Kbytes (10.53 Mbytes)
            17.77% of uncompressed filesystem size (60717.78 Kbytes)
    Inode table size 13830 bytes (13.51 Kbytes)
            24.27% of uncompressed inode table size (56995 bytes)
    Directory table size 15960 bytes (15.59 Kbytes)
            36.45% of uncompressed directory table size (43787 bytes)
    Number of duplicate files found 28
    Number of inodes 1759
    Number of files 1450
    Number of fragments 181
    Number of symbolic links  14
    Number of device nodes 0
    Number of fifo nodes 0
    Number of socket nodes 0
    Number of directories 295
    Number of ids (unique uids + gids) 1
    Number of uids 1
            root (0)
    Number of gids 1
            root (0)
    guest@porteus:~$ ls -lh abw_080914.xzm
    -rw-r--r-- 1 root root 11M Sep  9 17:10 abw_080914.xzm
    
    • Current directory as work directory. Different module directory. (Note: could simply use 'dot', but for visibility '.' or "." or ./)

      Code: Select all

      root@porteus:/home/guest# sh p10/Por/xzmod.sh abw_080914  '.' /tmp
      Text File = abw_080914.txt
      Basename without Extension = abw_080914
      Default Module Name: abw_080914.xzm
      
      Installing to Fakeroot Directory
      
      gtk+3-3.8.2-i486-2: GTK+ version 3 multi-platform GUI toolkit            [57M] 
      at-spi2-atk-2.8.1-i486-1: AT-SPI2 bridge to ATK                          [280K]
      at-spi2-core-2.8.0-i486-1: Assistive Technology Service Provider Interfa [2.1M]
      
      Creating Module abw_080914.xzm
      
      Parallel mksquashfs: Using 1 processor
      Creating 4.0 filesystem on /tmp/abw_080914.xzm, block size 262144.
      [=========================================================================/] 1534/1534 100%
      ...
      
      • Assign work directory; module in current directory; quiet.

        Code: Select all

        guest@porteus:~$ ls -ld /mnt/sda4/tmp
        drwxrwxrwt 47 root root 2568 Sep 10 01:10 /mnt/sda4/tmp/
        ______________________________________________________________________________
        root@porteus:/home/guest# sh p10/Por/xzmod.sh -q abw_080914  /mnt/sda4/tmp  
        Default Module Name: abw_080914.xzm
        
        Installing to Fakeroot Directory
        
        gtk+3-3.8.2-i486-2: GTK+ version 3 multi-platform GUI toolkit            [57M] 
        at-spi2-atk-2.8.1-i486-1: AT-SPI2 bridge to ATK                          [280K]
        at-spi2-core-2.8.0-i486-1: Assistive Technology Service Provider Interfa [2.1M]
        
        Creating Module abw_080914.xzm
        
        Parallel mksquashfs: Using 1 processor
        Creating 4.0 filesystem on ./abw_080914.xzm, block size 262144.
        [=========================================================================/] 1534/1534 100%
        ...
        
        • New module directory. New installation directory => Kept. Default module name references assigned installation directory, defaulting to that name.

          Code: Select all

          guest@porteus:~$ ls /mnt/sda4/tmp/abw0809
          /bin/ls: cannot access /mnt/sda4/tmp/abw0809: No such file or directory
          guest@porteus:~$ ls /mnt/sda1/mods/abw
          /bin/ls: cannot access /mnt/sda1/mods/abw: No such file or directory
          ______________________________________________________________________________
          
          root@porteus:/home/guest# sh p10/Por/xzmod.sh -q abw_080914  /mnt/sda4/tmp/abw0809 /mnt/sda1/mods/abw
          Assigned Installation Directory Created: /mnt/sda4/tmp/abw0809
          Default Module Name: abw0809.xzm
          
          Installing to Fakeroot Directory
          
          gtk+3-3.8.2-i486-2: GTK+ version 3 multi-platform GUI toolkit            [57M] 
          at-spi2-atk-2.8.1-i486-1: AT-SPI2 bridge to ATK                          [280K]
          at-spi2-core-2.8.0-i486-1: Assistive Technology Service Provider Interfa [2.1M]
          
          Creating Module abw0809.xzm
          
          Parallel mksquashfs: Using 1 processor
          Creating 4.0 filesystem on /mnt/sda1/mods/abw/abw0809.xzm, block size 262144.
          [=========================================================================\] 1534/1534 100%
          ...
          guest@porteus:~$ ls -ld /mnt/sda4/tmp/abw0809
          drwxr-xr-x 5 root root 120 Sep  9 17:36 /mnt/sda4/tmp/abw0809/
          guest@porteus:~$ sudo du -sh /mnt/sda4/tmp/abw0809
          63M     /mnt/sda4/tmp/abw0809
          
          • New installation directory => Kept. Default module name references assigned installation directory. Module pathname assigned. Assigned module name overrides default name.

            Code: Select all

            guest@porteus:~$ ls  /mnt/sda1/mods/abw_deps.xzm
            /bin/ls: cannot access /mnt/sda1/mods/abw_deps.xzm: No such file or directory
            guest@porteus:~$ ls -ld /mnt/sda4/tmp/abw
            /bin/ls: cannot access /mnt/sda4/tmp/abw: No such file or directory
            guest@porteus:~$ ls -ld /mnt/sda1/mods
            drwxrwxrwx 4 root root 320 Sep  9 17:36 /mnt/sda1/mods/
            ______________________________________________________________________________
            
            root@porteus:/home/guest# sh p10/Por/xzmod.sh -q abw_080914 /mnt/sda4/tmp/abw/fake_rt0809 /mnt/sda1/mods/abw_deps.xzm
            Assigned Installation Directory Created: /mnt/sda4/tmp/abw/fake_rt0809
            Assigned Module Name: abw_deps.xzm
            
            Installing to Fakeroot Directory
            
            gtk+3-3.8.2-i486-2: GTK+ version 3 multi-platform GUI toolkit            [57M] 
            at-spi2-atk-2.8.1-i486-1: AT-SPI2 bridge to ATK                          [280K]
            at-spi2-core-2.8.0-i486-1: Assistive Technology Service Provider Interfa [2.1M]
            
            Creating Module abw_deps.xzm
            
            Parallel mksquashfs: Using 1 processor
            Creating 4.0 filesystem on /mnt/sda1/mods/abw_deps.xzm, block size 262144.
            [=========================================================================/] 1534/1534 100%
            ...
            
            • Work directory assigned; new module directory together with module file name; packages text file not in current directory (relative path) with extension of sorts.

              Code: Select all

              guest@porteus:~$ ls -ld /mnt/sda4/tmp
              drwxrwxrwt 47 root root 2568 Sep 10 01:10 /mnt/sda4/tmp/
              guest@porteus:~$ ls -ld /tmp/abw/
              /bin/ls: cannot access /tmp/abw/: No such file or directory
              ______________________________________________________________________________
              
              root@porteus:/home/guest# sh p10/Por/xzmod.sh -q p10/Por/Abiword/Abi_xzm_tst.cpy /mnt/sda4/tmp /tmp/abw/abi_tst.xzm
              Assigned Module Name: abi_tst.xzm
              
              Installing to Fakeroot Directory
              
              gtk+3-3.8.2-i486-2: GTK+ version 3 multi-platform GUI toolkit            [57M] 
              at-spi2-atk-2.8.1-i486-1: AT-SPI2 bridge to ATK                          [280K]
              at-spi2-core-2.8.0-i486-1: Assistive Technology Service Provider Interfa [2.1M]
              
              Creating Module abi_tst.xzm
              
              Parallel mksquashfs: Using 1 processor
              Creating 4.0 filesystem on /tmp/abw/abi_tst.xzm, block size 262144.
              [=========================================================================|] 1534/1534 100%
              ...
              
            Run xzmod as root. Sudo edit will follow. Feel free to give file any name of choice. Run at own risk, especially when not testing after minor alteration. :evil:

            Code: Select all

            #!/bin/bash
            # 2014-09-07 17:37:21
            # Author: Bogomips
            # ©2014 GPL
            # xzmod	<File with Pkg List>	<Transitional Install Dir>	<XZM file>
            # Script geared to using a temporary fake root directory
            
            # File with Pkg List:		[<path>/]<Text File Basename>
            # Transitional Install Dir:	[<path>[/<Dir Name>]]
            # XZM file:			[<path>[/<Module Name>[.xzm]]]
            
            # 1.	<Text File Basename>:		<Text File Name>[.ext]
            # 2.	Install (Fakeroot)Directory:	[<path>]
            #	a) Exists  =>  [<path>/]<Temp Dir>
            #	b) Otherwise Create: <Assigned Fakeroot Dir>
            # 3.	xzm file:	<Pathname> expected: [ <Pathname> | <Path> ]
            #	1. Create directory tree if non-existent.
            #	2. Module Name: Basename if Pathname has Extension of 'xzm'. 
            #	3. Otherwise: { <Assigned Fakeroot Dir Name>.xzm | <Text File Name>.xzm }
            #
            #set -vx		# Useful?
            #set -x		# Useful
            #set -vn	# Useful at Start
            
            # VARIABLE DEFINITIONS		2014-08-28 23:16:38
            # xt: Extension		bn: Basename	fle: Basename without Extension
            # pn: Pathname		mn: Default Module Name		pth: Path	td: Temporary Dir
            # xzd: Root directory for txz files	xzm: Module pathname	tf: Text File
            
            # PROLOG
            if [ "$1" = -q ]; then v=0; shift; else v=1; fi
            readonly v; # declare -p v;
            #	echo $#
            if ! (($#)); then echo 'Usage';echo '====='; y=${0%.sh};
              echo "${y##*/}  [-q]  <File with '.txz' Package List>  [ <Fakeroot Directory>  [<Module File>] ]"
              echo ''
              echo "1st Par: [<path>/]<file name>[.<ext>]	Text file holding list of '.txz' package files, one per line. If no extension try with '.txt', then without. Default module name set to basename minus extension."
              echo
              echo "2nd Par: [<path>[/<Assigned Dir>]]	Existing path for Temporary Fakeroot Dir, otherwise new Fakeroot Dir. Default module name reset to name of new Fakeroot Directory."
              echo
              echo "3rd Par: [<path>[/<Module Name>.xzm]]	Existing/Non-existing path for xzm Module File."
              exit
            fi
            
            # PROCESS
              # 1st Par
            #	[<path>/]<file name>[.<ext>]
            # Text file holding list of '*.txz' package files, one per line. Abs/Rel paths
            # If there is no Extension, look for file with '.txt' extension, otherwise see
            # if file without extension exists. Default module name set to basename minus 
            # extension.
            # Extension:	Remove pathname without extension from pathname.
            #	echo Pathname = $1
            pn=$1; xt=${1#${1%.*}};
            if [ ${#xt} -gt 4 ]; then xt=; fi	# Disregard as Extension e.g. '.jpeg'
            #	echo xt=$xt
            # 1st Par Tests		pn:	<pathname> = [<path>/]<basename>
            # No extension defaults to '.txt' firstly, before trying without estension.
            if ! ((${#xt})); then pn=$1.txt; fi	# 2014-08-31 02:58:58
            while [ ! -f $pn ]; do 
              if [ $pn = $1 ]; then echo Non-existent file:	${1%$xt}${xt:-.txt};  
                if ! ((${#xt})); then echo Also non-existent: $1; fi
                y=${0%.sh}; echo ${y##*/} terminated.; exit;
              fi
              pn=$1;
            done					# 2014-08-31 02:59:19
            # Test for Incorrect Parameter Values		2014-09-04 22:26:06
            if [[ "${2#${2%.*}}" = ".xzm" && "$3" != "" ]] ; then 
              echo "Error!! 3rd Par Value '$3' not defaulted. 2nd Par Value: '$2' should be Path.";
              exit;
            fi
            # Basename:	<name>[.<ext>]
            bn=${1##*/}
            fle=${bn%$xt}	# Basename without Extension
            # Set Default Module Name Switch
            if ! [[ "${2#${2%.*}}" = ".xzm" || "${3#${3%.*}}" = ".xzm" ]] ; then mn=$fle; fi
            #	echo mn = $mn;
            tf=$pn; if ((v)); then echo Text File  =  $tf; fi
            if ((v)); then echo Basename without Extension = $fle; fi
            
            # 2nd Par: Default & Remove trailing slash	2014-08-25 22:17:22
            #	[<path>[/<dir name>]]
            #	{ [<path>] | [<path>/]<mod name>.xzm }	2014-08-30 17:33:31
            # Fake Root directory expected here. If directory exists then a temporary dir 
            # to hold fake root is created. Otherwise the assigned directory is created, and
            # its name becomes new module name default. The assigned directory is saved.
            # Null 2nd Par defaults to '.', current directory.
            pth=${2:-.}; if [ .${2##*.} = .xzm ]; then pth=.; fi
            pth=${pth%/}; 
            # 2nd Par Tests
            if [ -d $pth ]; then td=$pth/tmp.$$; xzd=$td; readonly td; fi
            mkdir -p ${xzd:=$pth};
            if [ $? -ne 0 ]; then dn=Assigned; if [ -v td ]; then dn=Temporary; fi
            echo "Failed to Create $dn Installation Directory!"; exit; fi
            # Set module name default if applicable
            if [ ! -v td ]; then echo Assigned Installation Directory Created: $xzd;
              if [ -v mn ]; then mn=${pth##*/}; fi
            fi
            if [ -v mn ]; then echo Default Module Name: $mn.xzm; fi
            
            # 3rd Par:	2014-08-27 22:50:42
            #	[<path>[/<Module Name>.xzm]]
            # Module path created if not already existing. 
            # If pathname does not have extension 'xzm', it is treated as directory, and
            # has '<Default Module Name>.xzm' appended as Basename.
            # Null 3rd Par defaults to '.', current directory, with module being created in
            # this directory. Before exiting, delete any temporary directory created.
            # Retrieve Extension if Exists:
            if [ .${2##*.} != .xzm ]; then shift; fi
            
            ## 2nd Par  <-  3rd Par
            xt=${2#${2%.xzm}};
            if let ${#xt}; then pn=$2; xzm=$pn; pth=${pn%${pn##*/}}; echo Assigned Module Name: ${2##*/}; fi
            # No extension
            if ! ((${#xt})); then pth=${2:-.}; xzm=$pth/$mn.xzm; fi
            # Create directory if path non-existent
            if [ ! -d $pth ]; then mkdir -p $pth; fi
            if (($?)); then echo Failed to Create Module Directory!; fi
            if [ -d $pth ]; then echo ; echo Installing to Fakeroot Directory; echo ;
              em[0]="Error installing to Fakeroot Directory."; y=${xzm##*/};
              em[1]="Error creating Module ${y%m}m.";
              ip=0; xargs -a $tf -i installpkg --root $xzd --terse {} && { ip=1; echo; echo "Creating Module ${xzm##*/}"&& echo; dir2xzm $xzd $xzm; }
              if (($?)); then echo ; echo ${em[ip]}; fi
            fi
            # EPILOG
            if [ -v td ]; then rm -r $td; fi
            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