You are not logged in.

#1 2011-05-15 04:32:00

xaer0knight
Member
Registered: 2010-02-06
Posts: 9

create script in /usr/bin called pacclean?

#!/bin/bash

su -c 'pacman -Qdt'
su -c 'pacman -Scc && pacman-optimize'
yaourt -Syua

this script was created to show
1) To list all packages no longer required as dependencies (orphans) (pacman -Qdt)
2) Clean the package cache of packages that are not currently installed (/var/cache/pacman/pkg) and removes all packages from the cache. (pacman -Scc)
3) Improving database access speeds reduces the time taken in database-related tasks, e.g. searching packages and resolving package dependencies. (pacman-optimize)
4) You can update your system including AUR packages (yaourt -Syua)

I think this is a good script i think, but is there a way to streamline it by not entering my password over 3 times? this script i created in /usr/bin and called it pacclean which i made it executable.

Offline

#2 2011-05-15 04:47:37

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: create script in /usr/bin called pacclean?

Do you really need a password for 'pacman -Qdt'? There are other ways to run pacman w/o entering the password e.g. visudo + NOPASSWD.
'pacman -Scc' will remove all packages from the cache, not only those that aren't installed - point 2 is not clear about this.

I think you still need to 'chmod +x pacclean' to make it executable. You placed it in a folder that's in your $PATH, so you can call it from every folder, just like cp, mv etc.

Last edited by karol (2011-05-15 05:08:48)

Offline

#3 2011-05-15 20:10:56

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: create script in /usr/bin called pacclean?

Why not just create an alias

alias paclean='sudo pacman -Qdt && sudo pacman -Sc && sudo pacman-optimize'

And as karol mentioned, note the difference between -Sc and -Scc


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#4 2011-05-15 21:16:42

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: create script in /usr/bin called pacclean?

Inxsible wrote:

Why not just create an alias

alias paclean='sudo pacman -Qdt && sudo pacman -Sc && sudo pacman-optimize'

And as karol mentioned, note the difference between -Sc and -Scc

It would be nice to have a way of acting on the output of 'pacman -Qdt' before 'sudo pacman -Sc' :-)

Offline

#5 2011-05-15 22:06:01

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: create script in /usr/bin called pacclean?

I have a script that has much the same concept as this one, but much longer. I'm sure I posted it in this forum before, but as it's changed a little recently, I'll repost here. It may give someone some ideas for how they'd like to wrap pacman themselves, or some coding style thoughts. I install this in /usr/local/sbin/pu and add that same path to sudoers with NOPASSWD set. Note that you don't have to run it with sudo yourself, as it will detect if you are not root and re-run itself in sudo for you if not. Note that this will produce a large amount of noise output on the first run, as the saved state data (/var/lib/pu) won't be populated yet, and so all the comparisons from last run to now will run as if everything in the world is brand new.

#!/bin/bash
# vim:set filetype=sh: *

if [[ "$(/usr/bin/id -u)" != "0" ]] ; then
    exec /usr/bin/sudo $0 "$@"
fi

libdir=/var/lib/pu

umask 0022

export LANG=en_US.utf8
export LC_COLLATE=C

# Recreate $libdir
/bin/install -d -o root -g root -m 755 "$libdir"
/bin/rm -rf "$libdir"/*.out

if /usr/bin/tty -s ; then
    # Upgrade packages
    /usr/bin/pacman -Syu
else
    # Update repos
    /usr/bin/pacman -Sy

    # List upgradeable packages
    /usr/bin/pacman -Qqu | /bin/sed -e 's/^/upgradeable /'
fi

echo

# List new packages in repos
/usr/bin/pacman -Slq | /usr/bin/sort -u > "$libdir/avail.out"

[[ -f "$libdir/avail.prev" ]] || /bin/touch "$libdir/avail.prev"
/usr/bin/comm -13 "$libdir/avail.prev" "$libdir/avail.out" | /usr/bin/xargs -r /usr/bin/pacman -Si
/bin/mv -f "$libdir/avail.out" "$libdir/avail.prev"

echo

# List stray dependencies
/usr/bin/pacman -Qqdt | /bin/sed -e 's/^/stray dep /'

# List pacsave/pacorig/pacnew files in /etc
/usr/bin/find /etc \( -name \*.pacnew -o -name \*.pacsave -o -name \*.pacorig \) | /bin/sed -e 's/^/pacfile /'

# List files missing from packages
/usr/bin/pacman -Qqk | /bin/sed -e 's/^/missing file /'

# List new explicit packages
# This also catches removals from base and base-devel
/usr/local/bin/pacexp | /usr/bin/sort > "$libdir/pacexp.out"

[[ -f "$libdir/pacexp.prev" ]] || /bin/touch "$libdir/pacexp.prev"
/usr/bin/comm -13 "$libdir/pacexp.prev" "$libdir/pacexp.out" | /bin/sed -e 's/^/pacexp /'
/bin/mv -f "$libdir/pacexp.out" "$libdir/pacexp.prev"

# List new base / base-devel packages not installed
/usr/bin/comm -13 <(/usr/bin/pacman -Qgq base base-devel | /usr/bin/sort -u) <(/usr/bin/pacman -Sgq base base-devel | /usr/bin/sort -u) > "$libdir/base.out"

[[ -f "$libdir/base.prev" ]] || /bin/touch "$libdir/base.prev"
/usr/bin/comm -13 "$libdir/base.prev" "$libdir/base.out" | /bin/sed -e 's/^/base-add /'
/bin/mv -f "$libdir/base.out" "$libdir/base.prev"

# List new version-mismatched AUR packages and new foreign packages
for pkg in $(/usr/bin/pacman -Qqm | /usr/bin/sort | /usr/bin/tee "$libdir/foreign.out") ; do
    localver=$(/usr/bin/pacman -Q $pkg | /bin/cut -d\  -f2)
    aurver=$(/usr/bin/curl -s "http://aur.archlinux.org/rpc.php?type=info&arg=$pkg" | /bin/cut -d\" -f18)

    [[ -z "$aurver" ]] && continue

    [[ "$localver" != "$aurver" ]] && echo "$pkg: $localver -> $aurver"
done > "$libdir/aur.out"

[[ -f "$libdir/foreign.prev" ]] || /bin/touch "$libdir/foreign.prev"
/usr/bin/comm -13 "$libdir/foreign.prev" "$libdir/foreign.out" | /bin/sed -e 's/^/foreign /'
/bin/mv -f "$libdir/foreign.out" "$libdir/foreign.prev"

[[ -f "$libdir/aur.prev" ]] || /bin/touch "$libdir/aur.prev"
/usr/bin/comm -13 "$libdir/aur.prev" "$libdir/aur.out" | /bin/sed -e 's/^/aur /'
/bin/mv -f "$libdir/aur.out" "$libdir/aur.prev"

# Clean out old packages if cache gets too big
if [[ $(/bin/du -sm /var/cache/pacman/pkg/ | /bin/cut -f1) -gt 1000 ]] ; then
    /usr/bin/pacman -Sc --noconfirm > /dev/null
    echo "clean cache"
fi

# Whack perms on pacman cache into shape
/usr/bin/find /var/cache/pacman/pkg -type f ! -perm 644 -exec /bin/chmod 644 {} +

Offline

#6 2011-05-15 22:54:01

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: create script in /usr/bin called pacclean?

karol wrote:
Inxsible wrote:

Why not just create an alias

alias paclean='sudo pacman -Qdt && sudo pacman -Sc && sudo pacman-optimize'

And as karol mentioned, note the difference between -Sc and -Scc

It would be nice to have a way of acting on the output of 'pacman -Qdt' before 'sudo pacman -Sc' :-)

Since this script calls yaourt, it seems worthwhile to point out that yaourt -Qdt prints the output of pacman -Qdt and then offers to remove the listed packages, should the user wish to do so.  I just use aliases for these:

alias pacor='yaourt -Qdt' # List (and remove) orphaned packages
alias paccl='yaourt -Sc' # Clean unused packages from PacMan cache
alias pacem='yaourt -Scc' # Empty PacMan cache

I don't like the idea of completely automating something that digs around my system, or eliminates something I just might need later.  smile

Offline

#7 2011-05-15 23:29:16

xaer0knight
Member
Registered: 2010-02-06
Posts: 9

Re: create script in /usr/bin called pacclean?

thanks guys for all your help. ill try em all smile

Offline

#8 2011-09-03 18:36:53

xaer0knight
Member
Registered: 2010-02-06
Posts: 9

Re: create script in /usr/bin called pacclean?

this works well with Yapan (Yet Another Package mAnager Notifier.)
Note: This work well with Yapan but the only issue is that su -c 'pacman-optimize' command in your /usr/paclean will ask for your password.

1. Make a file called /usr/paclean

 #sudo nano /usr/paclean

Add the following code to /usr/paclean:

 #!/bin/bash

yaourt -Qdt
yaourt -Scc
yaourt -Syua
su -c 'pacman-optimize'

2. The make /usr/paclean executable by

sudo chmod +x /usr/paclean

3. Install  Yapan (Yet Another Package mAnager Notifier.) In your terminal program type:

 #yaourt -S yapan 

4. In Yapan's settings, under the Package Manger Tab, change the following :
Synchronize: yaourt -Syy --aur --dbpath /tmp/yapan/ &> /dev/null
List package to update: yaourt -Qqu --aur --dbpath /tmp/yapan/
Update: /usr/paclean --dbpath /tmp/yapan/

Offline

Board footer

Powered by FluxBB