Wednesday, November 3, 2010

recurperms

I wrote a script to remove the executable flags from all files within a directory but directories themsevles. It will also descend into sub-directories.

#!/bin/bash

# This script will chmod -x every file within a
# directory recursively, without removing the
# executable nature of the directories contained
# within.
################################################

do_recursion() {
    files=`ls`
    file=
    for i in $files; do
        file=$file$i
        if [[ ! -e $file ]]; then
            file=$file' '
            continue
        fi
        if [[ -d "$(pwd)/$file" ]]; then
            echo "descending into directory $(pwd)/$file"
            cd "$(pwd)/$file"
            do_recursion
        fi
        if [[ -d "$(pwd)/$file" ]]; then
            echo "ascending to directory $(pwd)/$file"
        else
            echo "chmodding $(pwd)/$file"
            chmod -x $file
        fi
        file=
    done
    cd ..
    return
}

do_recursion

exit 0

Tuesday, November 2, 2010

pacdown

Since I'm going to be running testing full-on, I'm going to need a script that can downgrade recently upgraded packages. I'll want to be able to pass the script a single package name that it can then downgrade, or tell it to downgrade all packages recently upgraded from testing. This may also lead to my package management script that will look at a blacklist file of packages that had to be downgraded, so that they won't be re-upgraded unless removed from the blacklist.

Testing Packages

Suprisingly, I haven't run into any conflicts until now. I guess some packages in testing require other packages in testing to be installed. Therefore, when using the testing repos, it is necessary to update the machine soley from the testing repo, rather than pick and choose packages to be tested. I will thus be scrapping the pactesting script and installing all packages from testing. I e-mailed the mailing list and it was advised that I do the aforementioned and simply use a script to revert to the stable package incase a testing package does not work propperly.

Monday, November 1, 2010

[bug]pactesting

When passing an option to pacman, i.e. pactesting -w package, pactesting will treat the option as a package while validating. While the script still works as it should, options and all, it's not correct. An update is in the works.

Friday, October 29, 2010

crond errors

While going through the cron log with my scanlogs script, I noticed that the only errors present are those that say 'unable to exectute /usr/sbin/sendmail/'. Sendmail is a script of some sort that sends a message (to the root user, I believe) with cronjob info. However, /usr/bin/sendmail doesn't exist. You can also sepcify this messaging script in the config file, /etc/conf.d/crond, with the -M switch. So, I made a blank script, cronmailer, and had cron call it instead of sendmail.

Thursday, October 28, 2010

[update]seressid

I think I've posted this script before. Simple script to search for a regexp within a near by broadcasting ESSID. Reports found networks or that nothing matched 'regexp'.

#!/bin/bash

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

count=0
while [[ $count < 10 ]]; do
  iwlist wlan0 scan | grep $1
  [[ $? = 0 ]] && exit 0
    let count=$count+1
  sleep 2
done

echo "No ESSID's matching term '$1' found."

exit 1

Tuesday, October 26, 2010

[update]wircon

Fixes:
If the find_network function failed, the script would still try to connect to a network, which would cause an error because there was no network set to connect to.
An instance where main was called from a function which was called by main. Now it just returns to main rather than calling it again.
An edit to the restart function in the init script was also necessary. The delay between stopping and starting the script was changed from 1 second to 2.

Still to fix:
If the script is stopped before it enters the 'main' function, the signal wont be caught and the do_unset_network function wont be run.

#!/bin/sh

dhcpcdPID="/var/run/dhcpcd.pid"
networks=`cat /home/jason/devel/scripts/wircon/pref_networks.lst`
statfile="/home/jason/devel/scripts/wircon/status"
silent=1

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

echo "starting" > $statfile

##################################################################
# scan for essids located in pref_networks.lst
find_network() {
  for i in $networks; do
    iwlist wlan0 scan | grep $i &> /dev/null
    if [[ "$?" = "0" ]]; then
      local essid=$i
      break
    fi
  done

  case $essid in
    "SouthPacific")
            network="sp"
            ;;
    "SouthPacific_Extender")
            network="spx"
            ;;
    "Belkin_G_Wireless_C973D1")
            network="seans"
            ;;
        "NETGEAR-Go")
            network="seans2"s
            ;;
        "MadisonOaks")
            network="daniels"
            ;;
        *)
            network=
  esac
}

##################################################################
# if dhcpcd is running, stop it
do_dhcpcd_check() {
  if [[ -f $dhcpcdPID ]]; then
    if [[ $silent = "1" ]]; then
      dhcpcd -x
    else
      dhcpcd -x -q
    fi
  fi

}

##################################################################
# load wireless firmware
do_load_firmware() {
  [[ $silent = "1" ]] && echo "loading wireless firmware"
  ifconfig wlan0 up
}

##################################################################
# set essid and, if applicable, network key
do_set_network() {
  [[ $silent = "1" ]] && echo "setting network parameters"
  iwconfig wlan0 essid $ESSID
  if [[ $KEY != "" ]]; then
      iwconfig wlan0 key $KEY
  fi
}

##################################################################
# unset the network for graceful exit
do_unset_network() {
  do_dhcpcd_check
  ifconfig wlan0 down
}

##################################################################
# try for dhcp lease
do_dhcpcd() {
  if [[ $silent = "1" ]]; then
    dhcpcd
  else
    dhcpcd -q
  fi
}

##################################################################
# something that helps find a carrier
do_channel_auto() {
  [[ $silent = "1" ]] && echo "connecting to carrier"
  iwconfig wlan0 channel auto
}

##################################################################
# make sure it worked
check_connection() {
  ping -c 1 www.google.com &> /dev/null

  if [[ $? = "0" ]]; then
    return 0
  else
    return 1
  fi
}

##################################################################
# set the desired network
set_network_params() {
  case $network in
    "sp")
            ESSID="SouthPacific"
            KEY="6bcebdfbea3caf9f3cd36b31b8"
            ;;
    "spx")
            ESSID="SouthPacific_Extender"
            KEY="6bcebdfbea3caf9f3cd36b31b8"
            ;;
    "seans")
            ESSID="Belkin_G_Wireless_C973D1"
            KEY=
            ;;
        "seans2")
            ESSID="NETGEAR-Go"
            KEY=
            ;;
        "daniels")
            ESSID="MadisonOaks"
            KEY=
            ;;
    *)
            return 1
  esac

    return 0
}

##################################################################
# make sure we're still connected to the network
connection_monitor() {
  while [[ 1 = 1 ]]; do
    sleep 10
    check_connection
    if [[ $? = 1 ]]; then
      echo "disconnected" > $statfile
      return
    fi
    echo "connected" > $statfile
  done
}

##################################################################
# call all functions in proper order to establish connection
main() {
  trap 'echo "down" > $statfile; do_unset_network; exit;' INT
  trap 'echo "down" > $statfile; do_unset_network; exit;' TERM

    while [[ 1 = 1 ]]; do
        set_network_params
        [[ $? = 0 ]] && break
        echo "searching" > $statfile
        find_network
    done

  while [[ 1 = 1 ]]; do
    do_dhcpcd_check
    do_set_network
    sleep 2
    do_dhcpcd
    do_channel_auto
    check_connection
    if [[ $? = 0 ]]; then
      [[ $silent = "1" ]] && echo "connection established"
      connection_monitor
        else
            echo "disconnected" > $statfile
    fi
  done
}


##################################################################
# check scripts usage
if [[ $# > 0 ]]; then
  if [[ $1 = "-s" ]]; then
    silent=0
    shift
  fi
    do_load_firmware
    sleep 2
  if [[ ! -z $1 ]]; then
    network=$1
  else
    find_network
  fi
else
    do_load_firmware
    sleep 2
  find_network
fi

main

exit 2