You are not logged in.

#1 2006-03-26 01:14:59

dswain
Member
From: Durham, New Hampshire
Registered: 2006-03-25
Posts: 10
Website

Pacman/Pacman.conf Scripts

I've been working on these two pieces for a while. For the most part, they're complete to my standards, but obviously they can always looked to be improved upon. I use the first one daily with no real problems (though I could add a little more error handling) and the other one does work for me though I don't need to call upon it too much.

My goal was really to provide an interface for pacman which was fast but still easy to use. I also realized that I can't write any GUI code, nor do I feel like it's nessisary to make something simple. It really only requires bash, a few coreutils, and pacman to be used, so if you're on a lower-end system and don't want to call upon a large GUI front end, this may be something good for you to try out.

Any feedback is appreciated too

Pacman Manager Script

#!/bin/bash
#Pacman Manager
#Author: Doug Swain (dswain@gmail.com)

###Defining Operations###

function install {
echo "Installing package now"
echo
sudo pacman -S $PACKAGE
echo
echo "The package ($PACKAGE) is now installed"
echo "Press enter to contiue"
read
}

function uninstall {
echo "Uninstalling package now"
echo
sudo pacman -R $PACKAGE
echo
echo "The package ($PACKAGE) has been removed."
echo "Press enter to contiue"
read
}

function sync {
echo "Syncing with servers"
echo
sudo pacman -Sy
echo
echo "Sync complete. Press enter to continue"
read
}

function update {
echo "    Updating your system now"
echo
sudo pacman -Syu --noconfirm
sudo pacman -Scc
echo
echo "Your system has been updated"
echo "Press enter to contiue"
read
}

function search {
clear
echo "What package would you like to search?"
read PACKAGE
sudo pacman -Ss $PACKAGE
echo "Would you like to search again?"
echo "[Y]es"
echo "[N]o"
read CHOICE
if [[ "$CHOICE" = [Yy] ]]; then
    search
elif [[ "$CHOICE" = [Nn] ]]; then
    echo "Search Finished. Press Enter to Continue"
    read
fi
}

function manage {
clear
if [ "$UID" != 0 ]; then
    echo "Error! Not running as the root user right now. Become a super user and try again"
    exit 1
fi
clear
echo "             Welcome to the Pacman Manager"
echo
echo "                What would you like to do?"

echo
}
###ENDDEFINE###

###MANAGER###

manage
OPTIONS="Install Uninstall Sync Update Search Exit"
select opt in $OPTIONS; do
    if [ "$opt" = "Install" ]; then
        clear
    echo "What package would you like to install?"
        read PACKAGE
        install
        manage
    elif [ "$opt" = "Uninstall" ]; then
        clear
        echo "What package would you like to uninstall?"
        read PACKAGE
        uninstall
        manage
    elif [ "$opt" = "Sync" ]; then
        clear
        sync
        manage
    elif [ "$opt" = "Update" ]; then
        clear
        update
        manage
    elif [ "$opt" = "Search" ]; then
        clear
        search
        manage
    elif [ "$opt" = "Exit" ]; then
        clear
        exit
    fi
done
###ENDMANAGER###

pacman.conf Script

#!/bin/bash
#Pacman Configurator
#Tool to configure and modify pacman and /etc/pacman.conf
#Pretty Stable from my tests, but use with caution
#Backup your /etc/pacman.conf file just in case. 
#Author: Doug Swain (dswain@gmail.com)

###DEFINE FUNCTIONS####

function srv_ctl {
clear
echo "Server Control"
echo "Selections:"
echo "[A]dd URL"
echo "[R]emove URL"
echo "[E]nable Resporitories"
echo "[D]isable Resporitories"
echo "[b]ack"
read CHOICE
if [ "$CHOICE" = "A" ]; then
    cat /etc/pacman.conf | grep "srv_ctl"
        if [ "$?" != "0" ]; then
            echo "[srv_ctl]" >> /etc/pacman.conf
            echo "Include = /etc/pacman.d/custom" >> /etc/pacman.conf
        fi
    clear
    echo "Enter URL"
    read URL
    echo "Adding"
    echo $URL >> /etc/pacman.d/custom
    cat /etc/pacman.d/custom | grep $URL
    echo "The server above has been added."
elif [ "$CHOICE" = "R" ]; then
    clear
    echo "Current Custom Server List:"
    cat /etc/pacman.d/custom
    echo "Enter URL"
    read URL
    echo "Removing"
    URLTEST=$(cat /etc/pacman.d/custom | grep $URL)
    if [ "$URL" = "$URLTEST" ]; then
        cat /etc/pacman.d/custom | grep -v $URL >> /etc/pacman.d/custom1
        mv /etc/pacman.d/custom1 /etc/pacman.d/custom
        echo "Address removed. Press enter to continue."
        read
        srv_ctl
    elif [ "$URL" != "$URLTEST" ]; then
        echo "Error! Address not found. Press Enter to continue"
        read
        srv_ctl
    fi
elif [ "$CHOICE" = "E" ]; then
    clear
    echo "Current Resporitiories available"
    ls /etc/pacman.d/
    echo "Enter Resporitory (example: current/custom/extra)"
    read RES
    echo "[$RES]" >> /etc/pacman.conf
    echo "Include = /etc/pacman.d/$RES" >> /etc/pacman.conf
    echo "Enabled. Press Enter to contiue"
    read
    srv_ctl
elif [ "$CHOICE" = "D" ]; then
    clear
    echo "Current Resporitiories available"
    ls /etc/pacman.d/
    echo "Enter Resporitory (example: current/custom/extra)"
    read RES
    cat /etc/pacman.conf | grep -v "$RES" >> /etc/pacman1.conf
    mv /etc/pacman1.conf /etc/pacman.conf
    echo "Disabled. Press Enter to continue."
    read
    srv_ctl
elif [ "$CHOICE" = "B" ]; then
    echo "Press enter to continue"
    read
    manage
fi
}

function pkg_ctl {
    clear
    echo "What would you like to do?"
    echo "[A]dd Package to Ignore List"
    echo "[R]emove Package from Ignore List"
    echo "[b]ack"
    read CHOICE
    if [ "$CHOICE" = "A" ]; then
        clear
        echo "Enter package name"
        read PKG
        echo "Adding"
        echo "IgnorePkg = $PKG" >> /etc/pacman.conf
        echo "HoldPkg = $PKG" >> /etc/pacman.conf
        echo "Package added. Press Enter to Continue"
        read
        pkg_ctl
    elif [ "$CHOICE" = "R" ]; then
        clear
        echo "Enter package name"
        read PKG
        echo "Removing"
        cat /etc/pacman.conf | grep -v "$PKG" >> /etc/pacman1.conf
        mv /etc/pacman1.conf /etc/pacman.conf
        echo "Package removed. Press Enter to Continue"
        read
        pkg_ctl
    elif [ "$CHOICE" = "B" ]; then
        echo "Press enter to continue"
        read
        manage
fi
}

function manage {
clear
if [ "$UID" != 0 ]; then
    echo "Error! Not running as the root user right now. Become a super user and try again"
    exit 1
fi
clear
echo "        Pacman Configuration"
echo "         What would you like to do?"
}

###END DEFINE####

###MANAGER####

manage
OPTIONS="Server_Control Package_Control Exit"
select opt in $OPTIONS; do
    if [ "$opt" = "Server_Control" ]; then
        srv_ctl
    elif [ "$opt" = "Package_Control" ]; then
        pkg_ctl
    elif [ "$opt" = "Exit" ]; then
        clear
        exit 0
    fi
done

###ENDMANAGER###

Sadly my webserver is down as of now, so I can't post these scripts directly from my site, but this should work fine anyway. Enjoy!

Offline

#2 2006-03-26 09:50:10

dma147
Member
From: Berlin
Registered: 2005-07-22
Posts: 43
Website

Re: Pacman/Pacman.conf Scripts

Hmmmm.... wink

First, I would explain, for what these scripts are and what they are doing. You've only said, that you want to create a fast and useful "gui" for pacman (are there not enough?)... and then you've posted these two scripts...

Second, I really don't see the sense in these two scripts.
The first one is really more than senseless, because the only thing it's doing is the change of the parameters for pacman. It is a wrapper script, which does exactly the same than pacman but with other parameters.

The second script seems to have a little bit more sense, because it (maybe) can *help* in configuring pacman. But you've still to know the urls of the repositories to give them to the script.

There already exists a script for this, which also gives the urls of the repositories, so that the user only have to choose one or more to add/remove. (it does much, much more, but this is not the point here).
Its name is qpkg and can be found on AUR.

Sorry for my critism, but I really don't see any sense in these two scripts.
Maybe I've overlooked something... than please correct me.

Offline

#3 2006-03-26 15:56:32

dswain
Member
From: Durham, New Hampshire
Registered: 2006-03-25
Posts: 10
Website

Re: Pacman/Pacman.conf Scripts

Oh no I understand. Hah I figured that'd be the case that somebody created something like this.

Well my main point with these scripts was really just for self-teaching and such. Essentially though, my idea was to make a script which can help somebody who is newer and doesn't quite know all the helpful syntax of pacman or somebody who just doesn't want to be bothered with it have a quick and easy way to do it. Since there are already GUI front ends to do something like this, I figured a scripted version would be nicer for somebody who may need something less resource intense. That's the first script

The second script was just to make it a little less painful to navigate the pacman.conf file without having to go through it and figure out the syntax for everything (if you don't already know it) because I figured it was easier to find just a URL than to know all the syntax of the config file, and this just fills in the voids for you.

I use it for myself daily and it does make it a bit easier when you just want to install a package or update real quickly. Like I said though, I'm not surprised that there's something better implimented already. I figured I'd just toss it out there to see who could enjoy it. I appreciate the questioning though as you're right; I didn't make myself very clear-cut. At any rate, useful or not for people, they're here haha. Like I also said, I wrote these just as a learning experience for coding and other things. So, if somebody can find a use for them, all the better. If not, um, sorry to waste thread space haha.

Offline

Board footer

Powered by FluxBB