Tuesday, December 21, 2010

sysupd.sh

System update script. Syncs pacman databases, optionally lists available updates, upgrades, prompts for abs sync, and updates mlocate database. Flags to download the updates without installing, list available updates, no-confirm, and force sync.

#!/bin/bash

# make sure the script is being run as root
/usr/local/bin/chkroot && [[ $? = 0 ]] || exit 1

# define script variables
dlonly=
fsync=
noconf=
list=0

# get optoins
args=`getopt dlny $*`

set -- $args
for i; do
    case "$1" in
        -d) dlonly="-w"                        ; shift ;;
        -l) list=1                                ; shift ;;
        -n) noconf="--noconfirm"    ; shift ;;
        -y)    fsync="-y"                        ; shift ;;
        --) shift                                    ; break ;;
    esac
done

pacman -Sy $fsync
[[ "$?" = "0" ]] || exit 1

if [[ "$list" = "1" ]]; then
    pacman -Qu --dbpath /var/lib/pacman
    exit 0
fi

pacman -Su $dlonly $noconf
echo "Sync ABS? [Y/n]"
read sync_abs
if [[ "$sync_abs" != {"N","n"} ]]; then
    abs
fi

echo; echo "updating mlocate database"
updatedb

exit 0

Tuesday, December 14, 2010

tarpac

Pacman cache archiving. Right now it just gzips everything in the /var/cache/pacman/pkg directory, then cleans the pacman cache. The only problem is that the --clean flag keeps the most current package tarballs, which have also been archived, so there's a going to be redundancy in the archives. I need to write in a way to ignore the most recent of the tarballs, just haven't figured that out yet.

#!/bin/bash
# create a dated archive of the pacman cache

chkroot && [[ $? = 0 ]] || exit 1

cd /var/cache/
tar pczf /home/jason/pacmancache-`date +%F`.tar.gz pacman/pkg
[[ $? = 0 ]] || echo "archive failed"; exit 1

echo "clearing old cache..."
pacman -S --clean
exit 0

Tuesday, December 7, 2010

syncscripts

Here's my script to manage systemwide scripts. The scripts and their destination files are held in the syncscripts.lst file. Scripts can be added. The script has be run from the folder where are all of the other scripts are developed. It checks the if the destination file exists, and copies it if it doesn't. If it does exist, it compares the md5sum of script with that of the destination file; if they differ, it copies the script to the destination file. The remove function has not yet been written.

#!/bin/bash

# pre-defined script variables
silent=1
verbose=1
addscript=1
remscript=1
scriptlist=syncscripts.lst

# display script usage
disphelp() {
    echo "Usage: $(basename $0) [OPTION] [SCRIPT]"
    echo
    echo "OPTIONS:"
    echo " -s          silent"
    echo " -v          verbose"
    echo " -a SCRIPT      add script"
    echo " -r SCRIPT      remove script"
    echo " -h         display this message"
}

###########################################################
args=`getopt svar $*`

set -- $args
for i; do
    case "$1" in
        -s) silent=0        ; shift    ;;
        -v) verbose=0     ; shift ;;
        -a) addscript=0 ; shift ;;
        -r) remscript=0 ; shift ;;
        -h) disphelp        ; exit 0 ;;
        --) shift                ; break ;;
    esac
done

# check for existence of syncscripts.lst, create an empty one if
#+one does not already exist
if [[ ! -f $scriptlist ]]; then
    [[ $silent = 1 ]] && echo "syncscripts.lst not found, creating a blank file"
    touch $scriptlist
fi

# add script to scriptlist
if [[ $addscript = 0 ]]; then
    # check to make sure script exists, the add script and destination
    #+to file.
    if [[ -f $1 ]]; then
        [[ $silent = 1 ]] && echo "$1 $2" >> $scriptlist
        exit 0
    fi
    [[ $silent = 1 ]] && echo "failed to add $1, no such file"
    exit 1
fi

# remove script from scriptlist
if [[ $remscript = 0 ]]; then
    [[ $silent = 1 ]] && echo "the remove function has not yet been written, nothing was removed"
    exit 0
fi

# step through lines of syncscripts.lst, every two lines contain an
#+entry the first line is the script, the second the path to move it to
while read line; do
    script=`echo $line | awk '{print $1}'`
    dest=`echo $line | awk '{print $2}'`

    # if destination path does not exist, copy without checking md5sums
    if [[ -z $dest ]]; then
        [[ $silent = 1 ]] && echo "$dest does not exist, copying $script to $dest"
        cp $script $dest
        continue
    fi
    # get the md5sum of the script and its destination, if no
    #+changes have been made, it doesn't need to be copied.
    scriptsum=`md5sum $script | awk '{print $1}'`
    destsum=`md5sum $dest | awk '{print $1}'`
    if [[ $scriptsum != $destsum ]]; then
        [[ $silent = 1 ]] && echo "detected changes in $script, copying to $dest"
        cp $script $dest
    fi
done <$scriptlist


exit 0

Wednesday, November 24, 2010

Scripts

Since some of my scripts should be used system wide (i.e. multiple users, the system itself, etc.), I'll be writing a script that will move all of the pertinent scripts to their system directories if they've been changed. This way, other users wont need access to my home directory to run certain scripts, like the wireless connection tool.

Tuesday, November 23, 2010

Slackware 13.1

Installed Slackware on my server today. Still working on configuring. Wrote a script to step through and vim every file within a given directory, which I'll be posting soon. Then it's on to learning the package build and installation process.

Wednesday, November 10, 2010

[update]gmail python script

The problem reminded me of my python script, which retrieves to number of unread e-mails in my mailbox. They also had some syntax errors. So, in ~/.conkyrc I changed the 'exec python gmailscript' to 'exec python2 gmailscript' and it worked out just fine.

[bug]chocolate-doom package build

A bug in the build for the chocolate-doom AUR package was brought to my attention recently:
  1. ./docgen -m manpage.template ../src > chocolate-doom.6
  2.   File "./docgen", line 392
  3.     print line.rstrip()
  4.              ^
  5. SyntaxError: invalid syntax
  6. make[2]: *** [chocolate-doom.6] Error 1
  7. make[2]: Leaving directory `/home/arin/Downloads/chocolate-doom/src/chocolate-doom-1.4.0/man'
  8. make[1]: *** [all-recursive] Error 1
  9. make[1]: Leaving directory `/home/arin/Downloads/chocolate-doom/src/chocolate-doom-1.4.0'
  10. make: *** [all] Error 2

Archlinux recently swiched from Python2 to Python3 as the default python. It uses symlinks to point /usr/bin/python to the actual Pythonx package. While Python2 is still installed, the /usr/bin/python symlink now points to Python3. The docgen script was using the default python (now Python3). The opening line for the script read: '#! /usr/bin/env python'. So, I will look into this, but the syntax used, which threw the error, was probably deprecated (or there's a bug). The salution thus being to edit the file to use Python2. Thus, the line "sed 's/python/python2/' -i man/docgen" was added to the PKGBUILD. The Python2 package also had to be added to the list of dependencies.