SFS-Remover

Miscellaneous tools
Message
Author
stemsee

SFS-Remover

#1 Post by stemsee »

I often remaster and sometimes accidentally remaster in sfs modules which then have no method of removing/uninstalling as there is no record in ~/.packages . This script can build such a record (list of files installed). Providing the original or equivalent sfs module can be located. Typically for me this means removing the devx from a remastered.sfs. just point the script to the sfs module, it will be extracted to "its-name"-extracted then CDed into where 'find -f -F -i --noreport' followed by a series of sed commands to remove extraneous items, will create the list in /tmp, which will be be used to remove files from running system.


EDIT: Needs more testing and work done on the symlinks in the case of development libraries.

Code: Select all

#!/bin/sh
#sfs remover by stemsee
#copyright (c) 2015 Marcos Contant
#
#For removing all files in an sfs module that has been added to main sfs
#by remastering or added flat (manually copied in). Requires original
#( or any) sfs module for building list of files to be removed.
#for example a devx_vivid_beta.sfs to remove development files.
#The list that is built can also be used as an installed file list in
#~/.packages/ . So that running this script before creating an sfs module
#from a dir and saving the resultant list to ./$HOME/.packages/devx.files
#will give the option to uninstall files using ppm (i think) or slocategui
#and apptree.
#
echo "Enter /path/to/*.sfs module whose files you want to remove from system.
e.g. /mnt/home/devx.sfs
The sfs module will be decompressed then all files will be listed and removed
from running system."
read hit
if [ -f "$hit" ]; then
unsquashfs -dest "$hit"-extracted "$hit"
cd "$hit"-extracted
else
echo "'$hit' not found. press Enter to try again."
read U-dummy
exec "$0"
fi
[[ -f /tmp/rmsfs.lst ]] && rm -f /tmp/rmsfs.lst
touch /tmp/rmsfs.lst
tree -f -i -F --noreport | sed '/\/$/d' >> /tmp/rmsfs.lst
sed -i 's|./|/|' /tmp/rmsfs.lst
sed -i 1d /tmp/rmsfs.lst
sed -i 's/ .*//g' /tmp/rmsfs.lst
geany /tmp/rmsfs.lst &
echo "Ready to remove displayed files from running system. Press y or n."
read hut
case $hut in
y) while read line
	do
		rm -f $line
	done < /tmp/rmsfs.lst
	cd ../
	cp /tmp/rmsfs.lst "$hit"-extracted/root/.packages/"$hit".files;;
n) exit 0;;
*) exec "$0";;
esac

stemsee

#2 Post by stemsee »

Should have mounted module on loop (no need to extract). should use rm -rf $line instead of -f.

stemsee

#3 Post by stemsee »

So this is pretty much it
This generates .files list and a ppm db entry for removal by ppm if files were not already removed using the script. ldconfig is also invoked in case of devx being removed. Save in PATH as rmsfs and make executable. invoke in terminal. Probably should be a rox app for right click operation.

Code: Select all

rmsfs some.sfs

Code: Select all

#!/bin/sh
#sfs remover by stemsee
#copyright (c) 2015 Marcos Contant
#
#For removing all files in an sfs module that has been added to main sfs
#by remastering or added flat (manually copied in). Requires original
#( or any) sfs module for building list of files to be removed.
#for example a devx_vivid_beta.sfs to remove development files.
#The list that is built can also be used as an installed file list in
#~/.packages/ . So that running this script before creating an sfs module
#from a dir and saving the resultant list to ./$HOME//.packages/devx.files
#will give the option to uninstall files using ppm (i think) or slocategui
#and apptree.
#

if [ ! -z "$1" ]; then
hit="$1"
fi
if [ -z "$1" ]; then
echo "Enter /path/to/*.sfs module whose files you want to remove from system.
e.g. /mnt/home/devx.sfs
The sfs module will be mounted then all files will be listed and option to remove from running system given. Or a *.files list will be made for removal by ppm."
read hit
fi

rmfn ()
{
[[ -d /tmp/"$hit" ]] && umount -l /tmp/"$hit" 2&>/dev/null
sleep 3
[[ -d /tmp/"$hit" ]] && rm -rf /tmp/"$hit"
}
deps=`which tree`
if [ -z "$deps" ]; then
echo "Please install tree"
sleep 4
exit 0
fi
if [ -f "$hit" ]; then
rmfn
mkdir /tmp/"$hit"
mount -t squashfs -o loop "$hit" /tmp/"$hit" 2&>/dev/null
size=`du -chk /tmp/$hit | tail -1 | cut -f1 -d 't'`
size=`echo $size | cut -f1 -d '	'`k
sleep 2
cd /tmp/"$hit"
else
echo "'$hit' not found. press Enter to try again."
read Udummy
exec "$0"
fi
[[ -f /tmp/rmsfs.lst ]] && rm -f /tmp/rmsfs.lst
touch /tmp/rmsfs.lst
tree -fiF --noreport | sed '/\/$/d' >> /tmp/rmsfs.lst
sed -i 's|./|/|' /tmp/rmsfs.lst
sed -i 1d /tmp/rmsfs.lst
sed -i 's/ .*//g' /tmp/rmsfs.lst

geany /tmp/rmsfs.lst &
echo "Ready to remove displayed files from running system. 
If not then a '$hit'.files list will be made in '$HOME/'/.packages/.
Press y or n."
read hut
case $hut in
y) while read line
   do
      rm -rf $line
   done < /tmp/rmsfs.lst
   ldconfig
   cd ../;;
n) [[ /tmp/rmsfs.lst ]] && mv /tmp/rmsfs.lst $HOME/.packages/"$hit".files
	ins=`cat $HOME/.packages/user-installed-packages | grep "$hit"`
	if [[ -z "$ins" ]]; then
		echo "$hit|$hit|||Utility|$size||$hit||sfs module file list||||" >> $HOME/.packages/user-installed-packages
	fi
	rmfn
	exit 0;;
*) [[ /tmp/rmsfs.lst ]] && mv /tmp/rmsfs.lst $HOME/.packages/"$hit".files
	ins=`cat $HOME/.packages/user-installed-packages | grep "$hit"`
	if [[ -z "$ins" ]]; then
		echo "$hit|$hit|||Utility|$size||$hit||sfs module file list||||" >> $HOME/.packages/user-installed-packages
	fi	
	rmfn
	exec "$0";;
esac
rmfn
exit 0
Last edited by stemsee on Thu 03 Sep 2015, 07:44, edited 1 time in total.

Bindee

#4 Post by Bindee »

So this keeps the SFS files that have been loaded and just removes the SFS module that was used to load them?

stemsee

#5 Post by stemsee »

Not quite.
usage

Code: Select all

rmsfs devx.sfs
This will mount the sfs in tmp/devx.sfs directory and enter it and recursively list all files and save list as a ~/.packages/devx.sfs.files list and also make a database entry appended to ~/.packages/user-installed-packages so that ppm can be used to remove the files (not the sfs loop mount: the sfs is not mounted as a layer for use, by this script). This is in cases where an sfs has been remastered in and there is no uninstall info anywhere on the system.

To do what you said simply remaster with sfs loaded! But if you use this before the remaster selecting no at offer to remove files then the db and files list will be added to system so that after remaster there is the option to remove by ppm.

Bindee

#6 Post by Bindee »

Thankssssssss :)

stemsee

#7 Post by stemsee »

mount -loop error sorted.

Code: Select all

#!/bin/sh 
#sfs remover by stemsee 
#copyright (c) 2015 Marcos Contant 
# 
#For removing all files in an sfs module that has been added to main sfs 
#by remastering or added flat (manually copied in). Requires original 
#( or any) sfs module for building list of files to be removed. 
#for example a devx_vivid_beta.sfs to remove development files. 
#The list that is built can also be used as an installed file list in 
#~/.packages/ . So that running this script before creating an sfs module 
#from a dir and saving the resultant list to ./$HOME//.packages/devx.files 
#will give the option to uninstall files using ppm (i think) or slocategui 
#and apptree. 
# 

if [ ! -z "$1" ]; then 
hit="$1" 
fi 
if [ -z "$1" ]; then 
echo "Enter /path/to/*.sfs module whose files you want to remove from system. 
e.g. /mnt/home/devx.sfs 
The sfs module will be mounted then all files will be listed and option to remove from running system given. Or a *.files list will be made for removal by ppm." 
read hit 
fi 

rmfn () 
{ 
[[ -d /tmp/"$hit" ]] && umount -l /tmp/"$hit" 2&>/dev/null 
sleep 3 
[[ -d /tmp/"$hit" ]] && rm -rf /tmp/"$hit" 
} 
deps=`which tree` 
if [ -z "$deps" ]; then 
echo "Please install tree" 
sleep 4 
exit 0 
fi 
if [ -f "$hit" ]; then 
rmfn 
mkdir /tmp/"$hit" 
mount -loop -t squashfs "$hit" /tmp/"$hit"
size=`du -chk /tmp/$hit | tail -1 | cut -f1 -d 't'` 
size=`echo $size | cut -f1 -d '   '`k 
sleep 2 
cd /tmp/"$hit" 
else 
echo "'$hit' not found. press Enter to try again." 
read Udummy 
exec "$0" 
fi 
[[ -f /tmp/rmsfs.lst ]] && rm -f /tmp/rmsfs.lst 
touch /tmp/rmsfs.lst 
tree -fiF --noreport | sed '/\/$/d' >> /tmp/rmsfs.lst 
sed -i 's|./|/|' /tmp/rmsfs.lst 
sed -i 1d /tmp/rmsfs.lst 
sed -i 's/ .*//g' /tmp/rmsfs.lst 

geany /tmp/rmsfs.lst & 
echo "Ready to remove displayed files from running system. 
If not then a '$hit'.files list will be made in '$HOME/'/.packages/. 
Press y or n." 
read hut 
case $hut in 
y) while read line 
   do 
      rm -rf $line 
   done < /tmp/rmsfs.lst 
   ldconfig 
   cd ../;; 
n) [[ /tmp/rmsfs.lst ]] && mv /tmp/rmsfs.lst $HOME/.packages/"$hit".files 
   ins=`cat $HOME/.packages/user-installed-packages | grep "$hit"` 
   if [[ -z "$ins" ]]; then 
      echo "$hit|$hit|||Utility|$size||$hit||sfs module file list||||" >> $HOME/.packages/user-installed-packages 
   fi 
   rmfn 
   exit 0;; 
*) [[ /tmp/rmsfs.lst ]] && mv /tmp/rmsfs.lst $HOME/.packages/"$hit".files 
   ins=`cat $HOME/.packages/user-installed-packages | grep "$hit"` 
   if [[ -z "$ins" ]]; then 
      echo "$hit|$hit|||Utility|$size||$hit||sfs module file list||||" >> $HOME/.packages/user-installed-packages 
   fi    
   rmfn 
   exec "$0";; 
esac 
rmfn 
exit 0 

stemsee

#8 Post by stemsee »

Updated to support use in rightclick menu. link to (~/.config/rox.sourceforge.net/SendTo/.application_x-squashfs-image/rmsfs)

Code: Select all

#!/bin/sh 
#sfs remover by stemsee 
#copyright (c) 2015 Marcos Contant 
# 
#For removing all files in an sfs module that has been added to main sfs 
#by remastering or added flat (manually copied in). Requires original 
#( or any) sfs module for building list of files to be removed. 
#for example a devx_vivid_beta.sfs to remove development files. 
#The list that is built can also be used as an installed file list in 
#~/.packages/ . So that running this script before creating an sfs module 
#from a dir and saving the resultant list to ./root/.packages/devx.files 
#will give the option to uninstall files using ppm (i think) or slocategui. 
# 
if [ ! -z "$1" ]; then
	hit="$1"
else
	yaf-splash -text "The sfs module will be mounted then all files will be listed and option to remove from running system given. Or a *.files list will be made for removal by ppm." &
	hit=$(yad --title "Enter /path/to/*.sfs" --entry)
fi 
hitmd=`echo "$hit" | rev | cut -f1 -d '/' | rev`
rmfn () 
{ 
[[ -d /tmp/"$hitmd" ]] && umount -l /tmp/"$hitmd" 2&>/dev/null 
sleep 3 
[[ -d /tmp/"$hitmd" ]] && rm -rf /tmp/"$hitmd" 
} 
deps=`which tree` 
if [ -z "$deps" ]; then 
	echo "Please install tree" 
	sleep 4 
	exit 0 
fi 
if [ -f "$hit" ]; then 
	rmfn 
	mkdir /tmp/"$hitmd" 
	mount -loop -t squashfs "$hit" /tmp/"$hitmd"
	size=`du -chk /tmp/$hit | tail -1 | cut -f1 -d 't'` 
	size=`echo $size | cut -f1 -d '   '`k 
	sleep 2 
	cd /tmp/"$hitmd"
fi
tree -fiF --noreport | sed '/\/$/d' > /tmp/rmsfs.lst 
sed -i 's|./|/|' /tmp/rmsfs.lst 
sed -i 1d /tmp/rmsfs.lst 
sed -i 's/ .*//g' /tmp/rmsfs.lst 
geany /tmp/rmsfs.lst & 
yaf-splash -text "Ready to remove displayed files from running system. 
If not then a '$hitmd'.files list will be made in '/root/.packages/."
yad --title "Enter y or n or q to quit" --width=300 --entry
read hut
case $hut in 
y) while read line 
   do 
      rm -rf $line 
   done < /tmp/rmsfs.lst 
   ldconfig 
   cd ../;; 
n) [[ /tmp/rmsfs.lst ]] && mv /tmp/rmsfs.lst /root/.packages/"$hitmd".files 
   ins=`cat /root/.packages/user-installed-packages | grep "$hit"` 
   if [[ -z "$ins" ]]; then 
      echo "$hitmd|$hitmd|||Utility|$size||$hitmd||sfs module file list||||" >> /root/.packages/user-installed-packages 
   fi 
   rmfn 
   exit 0;; 
*) exit 0;; 
esac 
rmfn 
exit 0 

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#9 Post by greengeek »

Hi stemsee - are you aware of (or have you built...) any scripts that can be run manually prior to shutdown (or prior to remaster) to identify which sfs are currently loaded.

I continually try to unmout disks and shutdown having forgotten which blinkin' sfses I have clicked on and I get various errors (and "kill" windows) just because of the way I have my pup layered.

If there was some easy way to identify the list of loaded sfs (and preferably their disk locations) that would be very helpful. cheers

stemsee

#10 Post by stemsee »

Hi greengeek

try running in terminal at start of a session

Code: Select all

mount | grep 'squashfs' > ~/loaded-sfs-mods-start
and again at end of the session

then
if you know your adrv zdrv ydrv and main sfs (loop 0)
You just count them!

Code: Select all

mount | grep 'squashfs' > ~/loaded-sfs-mods-end
But sure I will come up with something, give me a couple days!

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#11 Post by slavvo67 »

Mikeb had something but I'm not sure if he shared it. It might be hidden in the depths of this board....

stemsee

#12 Post by stemsee »

Seems to me that only the script filemnt needs modifying to output a list of sfs modules that get 'installed' during a session but mount should unmount 'stray' filesystems during shutdown anyway!

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#13 Post by greengeek »

stemsee wrote:...mount should unmount 'stray' filesystems during shutdown anyway!
The problem I am getting is that I am in the habit of using pmount to manually unmount my disks before I do a shutdown. - and unfortunately it will not process the unmount while an sfs is in use - I end up with a forced "kill" of pmount and have to run it again after unloading all the sfses.

Generally by that time I have forgotten which sfses I have loaded, and on which of my disks those sfs are residing, so I have to go hunting and sometimes make wild guesses about it.

However - I realise now that I can run "menu, setup, load-sfs-on-the-fly" and it will identify what is already loaded and let me select what to unload from a list. That is an improvement anyway - I hadn't previously thought about doing it that way. I guess load-on-the-fly must be able to read a file somewhere that contains a list of loaded sfs.

What would be even better is to have an icon on the desktop that when clicked would unload any and every sfs currently loaded - regardless of location. That would save me the trouble of racking my brains to think back to what it was I did three hours ago.
:-)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#14 Post by greengeek »

I just had a look at the "filemnt" file you referred to and when I loaded the devx sfs an extra line appeared in filemnt but I can't make sense of it or see how I can use it to unload the sfs.

The extra line is:

Code: Select all

/dev/loop1 /initrd/pup_ro4 squashfs ro,noatime 0 0
I guess that means something to the shutdown routine.
.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#15 Post by greengeek »

Hi stemsee - please forgive me for cluttering your thread - I think I have a solution for my needs: There is a post here from jasper offering a pet written by forum member seaside, which I have now modified slightly so that it unloads all sfs immediately and without any questions.

EDIT : I should add a caveat from the original thread: "it will unload all/or any sfs files (that are not actually in use or minimised to a tray"
(I have more tests to do to better understand what constitutes "in use")

Hope you won't mind if I post it here:

NOTES :
1) This is not an sfs remover as offered by stemsee for remastering - it is an sfs unloader which unmounts all sfs.
2) It is experimental and possibly dangerous for some users or puppies
3) Although the sfs are successfully unloaded this script does not update the files that tell "sfs-load-on-the-fly" which sfs are loaded. This means that the sfs_load utility still thinks that the sfs might be loaded when it isnt. This is not a problem for me as I simply shut down at that point anyway.

How to use: The attached pet places the script "all_sfs_unloader_gg" in /root - and you can simply click on that script to have it immediately unload/unmount all of your sfs.
Put the script wherever you want.
Attachments
all_sfs_unloader_gg-0.0.pet
(1.04 KiB) Downloaded 264 times
Last edited by greengeek on Sat 20 Feb 2016, 00:31, edited 1 time in total.

stemsee

#16 Post by stemsee »

your .pet package has a superfluous directory level. Try this one!
Attachments
all_sfs_unloader.pet
(1.01 KiB) Downloaded 222 times

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#17 Post by greengeek »

stemsee wrote:your .pet package has a superfluous directory level
Thanks for the mod version - although I can't see any difference between the two pets. Can you explain what you meant by superfluous directory? Do you mean within the pet or within the script? cheers.

stemsee

#18 Post by stemsee »

when you extract the pet there is a sub-dir within which are the '/' dirs.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#19 Post by greengeek »

I'm a bit confused. I can't see the issue you are referring to. Here is a pic of what I see when I extract your pet and mine:
Attachments
stemsee_comparison.jpg
(87.52 KiB) Downloaded 183 times

Pelo

all_sfs_unloader.pet by stemsee downloaded.

#20 Post by Pelo »

all_sfs_unloader.pet by stemsee downloaded.
A quick check with pfind remains useful to clean traces remaining.

Post Reply