WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: script to uninstall extension and resulting orphan dependencies  (Read 4366 times)

Offline GNUser

  • Full Member
  • ***
  • Posts: 140
I see that this topic has been discussed at length in various threads through the years, so I won't belabor the issue.

I wanted a no-frills script that assumes I know what I'm doing and simply uninstalls the extensions I tell it to, then also uninstalls any orphan dependencies that result. I don't want the script to check anything for me--it's up to me to not uninstall something that I'm currently using. I don't know if something like this already exists, but figured it would be faster and easier for me to roll my own than to search.

In case it is useful to someone, here is the script:

Code: [Select]
#!/bin/sh

# Purpose: uninstall the specified extension(s) and any orphaned dependencies that result
# Example: $ uninstall lftp openvpn

main()
{
create_notrequired_original
create_arg_hitlist "$@"
while [ -s hitlist ]; do
while read extension; do
uninstall "$extension"
done <hitlist
create_orphan_hitlist
done
exit
}

create_notrequired_original()
{
tce-audit builddb >/dev/null && tce-audit notrequired | sed 's/\.tcz$//' >notrequired-original
}

create_arg_hitlist()
{
cat /dev/null >hitlist
for arg in "$@"; do
echo "$arg" >>hitlist
done
}

create_orphan_hitlist()
{
tce-audit builddb >/dev/null && tce-audit notrequired | sed 's/\.tcz$//' >notrequired-now
comm -13 notrequired-original notrequired-now >hitlist
}

uninstall()
{
echo "Uninstalling ${1}..."

# this would be sufficient if followed by a reboot:
rm /etc/sysconfig/tcedir/optional/${1}.tcz*
sed -i "/^${1}\.tcz/ d" /etc/sysconfig/tcedir/onboot.lst

# current boot considerations:
link=$(which $1); [ "$link" ] && sudo rm $link
sudo umount -d /tmp/tcloop/$1
sudo rmdir /tmp/tcloop/$1
sudo rm /usr/local/tce.installed/$1
}

cd /tmp
main "$@"




Offline GNUser

  • Full Member
  • ***
  • Posts: 140
Re: script to uninstall extension and resulting orphan dependencies
« Reply #1 on: July 09, 2019, 08:28:48 AM »
I just realized that both the script and one of its functions are called "uninstall". It works but is confusing. Perhaps a better name for the script would be tce-uninstall.

(Maybe the GUI version of TC provides this script's functionality, but I'm running without X and couldn't find something like it among the CLI tools.)

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 6850
Re: script to uninstall extension and resulting orphan dependencies
« Reply #2 on: July 09, 2019, 08:52:40 AM »
Hi GNUser
(Maybe the GUI version of TC provides this script's functionality, but I'm running without X and couldn't find something like it among the CLI tools.)
tce-audit  provides that function, but it marks the extensions for removal and deletes them when you reboot. There is no mechanism
for removing installed extensions from a running system.

Offline GNUser

  • Full Member
  • ***
  • Posts: 140
Re: script to uninstall extension and resulting orphan dependencies
« Reply #3 on: July 09, 2019, 09:06:48 AM »
Yes, I noticed tce-audit's "mark-then-reboot" approach. However, during intense tinkering sessions I need to test different versions of an extension. Having to reboot between tests makes me a sad panda.

Well, now we have this mechanism for removing installed extensions from a running system ;) I have already put my script through some abuse and it works exactly as advertised. After uninstalling an extension with the script, one can immediately re-install it as usual (with tce-load or tce-ab) if one so desires.
« Last Edit: July 09, 2019, 09:11:28 AM by GNUser »

Offline GNUser

  • Full Member
  • ***
  • Posts: 140
Re: script to uninstall extension and resulting orphan dependencies
« Reply #4 on: July 26, 2019, 08:33:54 AM »
I cleaned the script up a bit. Here is the new version:

Code: [Select]
#!/bin/sh

# Purpose: uninstall the specified extension(s) and any orphaned dependencies that result
# Example: $ tce-uninstall lftp openvpn

main()
{
create_notrequired_original
create_arg_hitlist "$@"
while [ -s hitlist ]; do
while read extension; do
uninstall "$extension"
done <hitlist
create_orphan_hitlist
done
exit
}

create_notrequired_original()
{
tce-audit builddb >/dev/null && tce-audit notrequired | sed 's/\.tcz$//' | sort >notrequired-original
}

create_arg_hitlist()
{
cat /dev/null >hitlist
for arg in "$@"; do
echo "$arg" >>hitlist
done
}

create_orphan_hitlist()
{
tce-audit builddb >/dev/null && tce-audit notrequired | sed 's/\.tcz$//' | sort >notrequired-now
comm -13 notrequired-original notrequired-now >hitlist
}

uninstall()
{
if [ -e /etc/sysconfig/tcedir/optional/${1}.tcz ]; then
echo "Uninstalling ${1}..."
# this would be sufficient if followed by a reboot:
rm /etc/sysconfig/tcedir/optional/${1}.tcz* 2>/dev/null
sed -i "/^${1}\.tcz/ d" /etc/sysconfig/tcedir/onboot.lst 2>/dev/null
# current boot considerations:
link=$(which $1); [ "$link" ] && sudo rm $link
sudo umount -d /tmp/tcloop/$1 2>/dev/null
sudo rmdir /tmp/tcloop/$1 2>/dev/null
sudo rm /usr/local/tce.installed/$1 2>/dev/null
else
echo "${1} is not installed."
fi
}

cd /tmp
main "$@"

Online Rich

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 6850
Re: script to uninstall extension and resulting orphan dependencies
« Reply #5 on: July 26, 2019, 08:57:10 AM »
Hi GNUser
There are a few things that don't get cleaned up:
1. Entries for the  wbar  (/usr/local/tce.icons).
2. Desktop menu entries.
3. Changes a  /usr/local/tce.installed/ExtensionName  script may have performed.
4. Other items that I missed.

This is not a criticism since the script meets your needs. Merely a heads up to others that there may be some unexpected side effects.

Offline GNUser

  • Full Member
  • ***
  • Posts: 140
Re: script to uninstall extension and resulting orphan dependencies
« Reply #6 on: July 26, 2019, 09:23:00 AM »
Thank you, Rich.

I wrote this to solve a simple problem: I was in a CLI-only environment, didn't want to reboot, and wanted to remove an extension (from tce/optional/ and tce/onboot.lst) and recursively remove any orphaned dependencies that pop up as a result. The script solved this problem beautifully and is careful to remove only orphans that pop up after the extension(s) named on the command line are removed.

The minimal cleanup that the script does is just a bonus and more than enough for my purposes. But I'm glad you spoke up so that folks have an idea of what the script doesn't do.

Online Greg Erskine

  • Sr. Member
  • ****
  • Posts: 269
Re: script to uninstall extension and resulting orphan dependencies
« Reply #7 on: July 26, 2019, 02:41:31 PM »
Hi GNUser.

Nice scripting.

I used to do similar things but eventually came to the conclusion that using the existing TC tools was the "right" way to do it, even if it required a reboot.

To me "Uninstall" means remove from .onboot.lst but do not delete the extensions from media. On piCore, there are extensions for the various versions of the RPi (single core, quad core) but are not installed during a boot but are just waiting for you to move the SD card to another RPi. I think of these extensions as "uninstalled".

Does this script work for ondemand loaded extensions?

regards
Greg

Offline GNUser

  • Full Member
  • ***
  • Posts: 140
Re: script to uninstall extension and resulting orphan dependencies
« Reply #8 on: July 26, 2019, 04:26:24 PM »
Thank you, Greg.

No, other than the fancy way it recursively finds new orphans, the script it pretty primitive. It only deals with tce/optional/ and tce/onboot.lst.

I used to do similar things but eventually came to the conclusion that using the existing TC tools was the "right" way to do it, even if it required a reboot.

But then you'll never break anything and that's no fun ;)