i hacked and slashed some lines from different scripts mostly found in porteus done some edit to it way i like.
maybe someone finds it useful.
at lest name and name-version extraction...
its heavy commented, its for me, this is my first script so....
pacman --cachedir /path/to/dir -Sw <some packages>
goes before this script
call script from dir where .pkgs are
>>not recommended for people skimmin' around forum just copy/pasting stuff and expect it to work << like i do
Code: Select all
#!/bin/bash
## convert cached .pkg.tar.xz(s) from $PWD to xzm module
## for molokaii
## from pkg2xzm script
## process downloaded packages.pkg.tar.xz and convert to xzm
## Create custom pacman db dir at working/temp location
#tmpdir=/tmp/pacmancached-$UID
tmpdir=$PWD
mkdir -p $tmpdir/cached-install/var/lib/pacman/local
## Mount the local pacman database at working/temp dir
## so that custom location update operation sees it (pacman -Uddr needs)
mount --rbind /var/lib/pacman $tmpdir/cached-install/var/lib/pacman
## Monkey around with db files, hold them outside mount binded
## /var/lib/pacman db dir
## to be put back where they need to be after unmounting
## this shit-around requiers extraction of package name-version below
dbhold="$tmpdir/dbhold.$$"
mkdir -p $dbhold
## use pacman -U to unpack packages from cached pkgs dir
## make install destination dir
#mkdir -p $tmpdir/cached-install ##already done recursively earlier
for i in $(ls *.pkg.tar.xz *.pkg.tar.gz *.pkg.tar 2>/dev/null); do
#used this before no doing in loop
#pacman -Uddr $tmpdir/cached-install $tmpdir/*.pkg.tar.xz
pacman --noconfirm -Uddr $tmpdir/cached-install $tmpdir/$i
done
## build package.lst with name and version for db monkeying
## remove starting characters with grep, tr '\n'... borowed never used it
pacman --print-format %n-%v -Upddr $tmpdir/cached-install $tmpdir/*.pkg.tar.xz \
| grep -v "loading packages..." | tr '\n' ' ' > package.lst
arr=($(<$tmpdir/package.lst))
## ${arr[@]} this is how array is declared for iteration
## package list with multiple entries space separated
## dont know if it makes difference
for y in ${arr[@]}; do
cp -a $tmpdir/cached-install/var/lib/pacman/local/$y $dbhold
done
## build name list fore module naming same as above only %n this time
pacman --print-format %n -Upddr $tmpdir/cached-install $tmpdir/*.pkg.tar.xz \
| grep -v "loading packages..." | tr '\n' ' ' > name.lst
arrg=($(<$tmpdir/name.lst))
# replace spaces with underscores and assign to variable lst content
# maybe for naming output module not using yet
#MODULE=$(for i in ${arrg[@]}; do echo $(echo $i | sed 's| |_|g'); done)
MODULE="build.$$"
# remove db entries, from --rbind mounted system db, of just unpacked/installed
# packages to cached-install. So it stays as it was before it was mounted.
# cleanup stuff. use already created variable with package.lst
for a in ${arr[@]}; do
rm -r $tmpdir/cached-install/var/lib/pacman/local/$a
done
## Unmount local db
umount $tmpdir/cached-install/var/lib/pacman
## Finish monkey around with db entries Copy packages to module package db
cp -a $dbhold/* $tmpdir/cached-install/var/lib/pacman/local
echo -e $BGreen"==> "$BWhite"Running script dir2xzm to make $MODULE"$Color_Off
## pass two arguments to dir2xzm contiue there
dir2xzm $tmpdir/cached-install $tmpdir/$MODULE.xzm