linux

Pi-hole setup on Raspberry Pi Zero

by Patrick Connelly posted on February 11, 2019

If you’ve not noticed, ads on the internet are everywhere. On my personal machine, I run uMatrix in chrome and it works great for blocking things but that’s not really an option for all devices (like mobile phones) or for all users (like my wife and kids). This is where Pi-hole comes in.

Pi-hole is an application that runs a customized DNS (Domain Name System) server that whenever a system using it tries to look up the name of and if it’s on the Pi-hole’s blacklist it pretends that the host doesn’t exist. Thus your device can’t see the ad server and then can’t load the ad.


VPN Setup and Auto Connect from Command-line

by Patrick Connelly posted on April 24, 2017

New servers mean new things to play with and new setups that have to be done. I set up a new VM that I wanted to always be connected to a VPN and for that VPN to come up whenever the system is started. The biggest “problem” here is that this VM is running in runlevel 3 so no GUI is available. So let’s jump into setting up an OpenVPN client using network manger’s command line interface

While these instructions are written for Fedora 25, they should work on any system using NetworkManager. You will have to figure out what packages you need and how to install them if you are not using an RPM (and probably Red Hat based) system.

Displaying Salesforce Test Status in screen using JSforce

by Patrick Connelly posted on September 29, 2014

This post will probably only be useful to one other person out there, but it was a fun exercise and thought I’d at least share my output.

One of the biggest challenges I have when running tests is that I will often forget they are running and leave them completed for a while before I go back and remember I ran them. This mainly happens when I’m running an entire class worth of tests and have 5-10 minutes to kill. When first learned about JSforce and it’s cli capability I was in love! So I set out to make it so that the current testing status is displayed inside of my screen session. At the end of it all this is what I came up with:

Screen status


Adding git status to the bash prompt

by Patrick Connelly posted on October 24, 2013

After talking to a friend of mine Jeff Larkin about bash prompts, I decided to modify what he did into a single line bash prompt. By adding the following to your .bashrc you’ll get the branch your on in git (if current directory is tracked), a color denoting the status of the branch as well as the return code of the last command (if non-zero)

#
# Define some colors first: Capitals denote bold
#
red='\e[0;31m'
RED='\e[1;31m'
green='\e[0;32m'
GREEN='\e[1;32m'
yellow='\e[0;33m'
YELLOW='\e[1;33m'
blue='\e[0;34m'
BLUE='\e[1;34m'
magenta='\e[0;35m'
MAGENTA='\e[1;35m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
NC='\e[0m' # No Color

# Taken from http://www.opinionatedprogrammer.com/2011/01/colorful-bash-prompt-reflecting-git-status/
function _git_prompt() {
  local git_status="`git status -unormal 2>&1`"
  if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then
    if [[ "$git_status" =~ nothing\ to\ commit ]]; then
      local ansi=$GREEN
    elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then
      local ansi=$RED
    else
      local ansi=$YELLOW
    fi
    if [[ "$git_status" =~ On\ branch\ ([^[:space:]]+) ]]; then
      branch=${BASH_REMATCH[1]}
      #test "$branch" != master || branch=' '
    else
      # Detached HEAD.  (branch=HEAD is a faster alternative.)
      branch="(`git describe --all --contains --abbrev=4 HEAD 2> /dev/null ||
      echo HEAD`)"
    fi
    echo -n '[\['"$ansi"'\]'"$branch"'\[\e[0m\]]'
  fi
}

function report_status() {
  RET_CODE=$?
  if [[ $RET_CODE -ne 0 ]] ; then
    echo -ne "[\[$RED\]$RET_CODE\[$NC\]]"
  fi
}

export _PS1="\[$NC\][\u@\h \W]"
export PS2="\[$NC\]> "
export PROMPT_COMMAND='_status=$(report_status);export PS1="$(_git_prompt)${_status}${_PS1}\$ ";unset _status;'

Bash Prompt


Even better remote notifications with Irssi

by Patrick Connelly posted on July 26, 2013

Last month I wrote a Irssi plugin that pushed messages from Irssi to Beanstalkd. I was pretty happy with it, but I wanted more. So, I’ve improved it. The new version pushes in a slightly more normalized json payload to one of two beanstalk tubes. The tubes are configured for here and away. Then the python script that consumes them either displays it via a notification pop up, if sent to the here tube, or to pushover if sent to the away tube.

Setup

  1. Install beanstalkd on a system that both the irssi client (producer) and the system the notifications will be displayed on (consumer) can access via the network
  2. Install and configure the beanstalkNotify.pl script in irssi
    1. Set beanstalk_server to the address of your beanstalkd server
    2. Set beanstalk_port to the port of your beanstalkd server
    3. Set beanstalk_here_tube to the tube name you want (optional)
    4. **Set beanstalk_away_tube to the tube name you want (optional)
  3. If you want to use pushover for your away notifications, do the following. Otherwise, set your beanstalk_away_tube in step 2D to the same as your beanstalk_here_tube
    1. Purchase pushover on your preferred platform [android / ios]
    2. Create a new application
    3. Copy your application key and user token from your account settings
  4. Download and configure beanstalk-notify.py on your consumer system
    1. Run the script python beantalk-notify.py start to generate the directories and basic configuration
    2. Modify the ~/.beanstalk-notify/beanstalk-notify.conf
      1. beanstalk
        1. server: The address / hostname to your beanstalk server
        2. port: The port for your beanstalk server
        3. clear_on_start: If the tubes should be emptied on start. This keeps from flooding you with notifications if the daemon has not been run in a while
        4. away_tube: The name of the tube for pushover messages
        5. away_ignore: A comma separated list of server names (from irssi) to ignore when sending notifications
        6. here_tube: The name of the tube for noticiation messages
        7. here_ignore: A comma separated list of server names (from irssi) to ignore when sending notifications
      2. pushover
        1. app_token: Your application token
        2. user_key: Your user key
        3. notification
          1. use_native: Use the python notification library
          2. type: The type to use. Determines icon
        4. daemon
          1. log_level: The message level for the daemon loggin
    3. Run the script with the updated config python beanstalk-notify.py start
    4. Profit!

Better remote notifications with irssi

by Patrick Connelly posted on June 28, 2013

This has been deprecated in for the new script and configuration.

History

As I wrote about a long time ago I use to use a custom script with irssi to push to mumbles. Well, mumbles has gone defunct and I couldn’t really find a good growl client for linux. Plus with me traveling into the office weekly, it’s just not going to work well since growl is more push notification. So this lead me to research a true messaging system to try it.

Beanstalkd

Beanstalkd is a simple fast workqueue. Using this, we can push messages (in JSON formatting) to the queue and have the client pull from the queue whenever they want. The nice thing about designing it this way is it can be reused to push other desktop notifications from other systems.

You can find the full repo with updated documentation on github

Setup

  • Install beanstalkd on a system that both your irssi client (producer) and the system you want notifications on (consumer)

Producer

  • Install the JSON perl module as well as the Queue::Beanstalk module
  • Download the beanstalkNotify.pl file into your ~/.irssi/scripts/ directory

Consumer

  • Install pyyaml and beanstalkc. These can be installed via python-pip
  • Download the beanstalk-notify.py file onto your consumer system

Configuration

Producer

  • Install the script by running _/script load beanstalkNotify _in irssi
  • Set your server /set beanstalk_server beanstalk.example.com
  • Set your port /set beanstalk_port 12345

Consumer

  • Modify the beanstalk-notify.py file to point to your beanstalkd server
  • Run the consumer script

Future Features

In the future I plan on adding the ability to add an audible notification for these as well. Maybe I’ll add the ability to pick a specific queue instead of the default, but I doubt it.


Download and launch an Elluminate session from the command line

by Patrick Connelly posted on January 07, 2013

We use Elluminate Live! for some of our meetings, and it has always bothered me that I have to launch the browser to use Elluminate especially for reoccurring meetings. So one afternoon I set out to fix this problem. I wrote the following script and have been using it for about a month now without any issues. You can set the parameters at the head of the script if you have a reoccurring meeting you want to use, or set the parameters at run time (or in an alias for multiple reoccurring meetings) if you need too.

The only prerequisite for this script is to have javaws installed an in your PATH.

#!/bin/bash

nick="NICKGOESHERE"
participant_password="PASSWORD"
leader_password="PASSWORD"
sid="SID"
output="/tmp/meeting.jnlp"
launch_on_download="true"

#############################################################################
####                   DO NOT EDIT PAST THIS POINT                       ####
#############################################################################

usage() {
  echo "usage: $0 [-n nick] [-p password] [-s sid] [-f file] [-l] [-j]"
	echo -e "\t-n The username"
	echo -e "\t-p The elluminate 'password'"
	echo -e "\t-s The elluminate 'sid'"
	echo -e "\t-l Use the leader password or the provided password is the leader password"
	echo -e "\t-f The output file [default ./meeting.jnlp]"
	echo -e "\t-j Launch the meeting file"
}

password=""
leader="false"

while getopts "hn:p:s:f:l" opt
do
	case $opt in
		n)
			echo "setting nick $OPTARG"
			nick=$OPTARG
			;;
		p)
			echo "setting password $OPTARG"
			password=$OPTARG
			;;
		l)
			echo "using leader password"
			leader="true"
			;;
		s)
			echo "setting sid $OPTARG"
			sid=$OPTARG
			;;
		f)
			echo "setting output $OPTARG"
			output=$OPTARG
			;;
		j)
			launch_on_download="true"
			;;
		h)
			usage
			exit
			;;
		?)
			usage
			exit
			;;
	esac
done

if [ ".$password" == "." ]
then
	if [ ".$leader" == ".true" ]
	then
		password=$leader_password
	else
		password=$participant_password
	fi
fi

if [ ".$output" == "." ]
then
	output_file="meeting.jnlp"
else
	output_file=$output
fi

post_data=""
url=""
curl_type=""
referer=""

if [ ".$leader" == ".true" ]
then
	#Leader needs to be a GET not a POST.  Plus some different headers
	url="https://sas.elluminate.com/site/external/launch/meeting.jnlp?sid=$sid&miuid=$password"
	curl_type="GET"
	referer="https://sas.elluminate.com/site/external/jwsdetect/meeting.jnlp?sid=$sid&miuid=$password"

	curl -s --insecure \
		-H 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
		-H 'Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3' \
		-H 'Accept-Encoding:gzip,deflate,sdch' \
		-H 'Accept-Language:en-US,en;q=0.8' \
		-H 'Connection:keep-alive' \
		-H 'DNT:1' \
		-H 'Host:sas.elluminate.com' \
		-H "Referer:$referer" \
		-H 'User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4' \
		-X $curl_type \
		$url > $output_file
else
	post_data="username=$nick&sid=$sid&password=$password&submit.x=0&submit.y=0"
	url="https://sas.elluminate.com/site/external/launch/meeting.jnlp"
	curl_type="POST"
	referer="https://sas.elluminate.com/site/external/launch/meeting.jnlp?sid=$sid&password=$password"

	curl -s --insecure \
		-H 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' \
		-H 'Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3' \
		-H 'Accept-Encoding:gzip,deflate,sdch' \
		-H 'Accept-Language:en-US,en;q=0.8' \
		-H 'Cache-Control:max-age=0' \
		-H 'Connection:keep-alive' \
		-H 'Content-Type:application/x-www-form-urlencoded' \
		-H 'DNT:1' \
		-H 'Host:sas.elluminate.com' \
		-H 'Origin:https://sas.elluminate.com' \
		-H "Referer:$referer" \
		-H 'User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4' \
		-d "$post_data" \
		-X $curl_type \
		$url > $output_file
fi


if [ ".$launch_on_download" == ".true" ]
then
	javaws $output_file
fi

Auto watch a directory and rebuild the repository when an rpm is added/updated

by Patrick Connelly posted on December 19, 2012

Today I started setting up the repository for people to use to install the Solenopsis rpm. The problem is I want to be able to build the rpm (via Jenkins) and push it to a remote server and automatically have the repo rebuild when it sees an rpm updated or added to the directory.

To do this, I wrote a small python script that can be run and backgrounded. It sends a pushover notification and runs createrepo against the target directory.

import re
import httplib, urllib
from subprocess import call

ROOT_DIR = '/path/to/dir'

wm = pyinotify.WatchManager();
mask = pyinotify.IN_CLOSE_WRITE

def pushover(message):
        conn = httplib.HTTPSConnection("api.pushover.net:443")
        conn.request("POST", "/1/messages.json",
        urllib.urlencode({
                "token": "TOKEN",
                "user": "USER",
                "message": message,
        }), { "Content-type": "application/x-www-form-urlencoded" })
        conn.getresponse()

def gen_repo():
        pushover('rebuilding repo')
        call(["createrepo", ROOT_DIR])


class EventHandler(pyinotify.ProcessEvent):
        def process_IN_CLOSE_WRITE(self, event):
                if event.pathname.endswith('.rpm'):
                        gen_repo()

handler = EventHandler();
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch(ROOT_DIR, mask, rec=True)

notifier.loop()

Swapping two files with a quick bash function

by Patrick Connelly posted on July 03, 2012

One thing I find myself doing a lot is swapping two files in bash. I thought about making this into a bash script then I realized 1) that’s over kill and 2) not as portable as I want. So, if you add this to your .bashrc then re-source it, you’ll be able to run the command swap to switch two files

function swap() {
  TMP_NAME="TMP_$RANDOM"
  mv "$1" "/tmp/$TMP_NAME" && mv "$2" "$1" && mv "/tmp/$TMP_NAME" "$2"
}

Using meld with git diff

by Patrick Connelly posted on May 03, 2011

This is test

Automatic backups with UDEV

by Patrick Connelly posted on September 25, 2009

I recently challenged myself to come up with a way to make udev automatically backup when you plug in a USB harddrive. I did all my testing with a USB stick drive, but since they both show up as block devices to the kernel, it shouldn’t matter.

UDEV Rules

To start with, we need to set up static naming for the storage device that you want to make into backup disk. Start by plugging in the disk. (Now I’m not using Gnome or KDE so I’m not sure what their automounter will do. So, you might have to find a way to exclude it from the automounter. We need to find out the “model” of the drive. My udev rules are pretty basic, and will work since most people don’t have more than one the same model of USB drive laying around that they would use. You can always modify the udev rules to work for you.

udevadm info -a -p /sys/block/sdc | grep model

Here we are looking at the block device sdc (which is what the kernel named it since we don’t have any udev rules yet). This could change depending on how many block devices you currently have. Now we take this information, and feed it into a udev rule. I created a file /etc/udev/rules.d/50-backup.rules The name isn’t really important, however, the number 50- is. That is the order in which it runs. We want that number to be less than 90 so that hal doesn’t run first. Inside that file, we have the following:

KERNEL=="sd?1″, SUBSYSTEM=="block", ATTRS{model}=="MODEL GOES HERE", SYMLINK+="backup", RUN+="/usr/local/bin/backup.sh"

Replace “MODEL GOES HERE” with the output from the udevadm command

The backup script

Now we udev running our script /usr/local/bin/backup.sh we need to make that script

#!/bin/bash

NOTIFYUSER="pcon"
MAINDIR="/home/pcon/"
BACKUPDIR="/mnt/backup"

su $NOTIFYUSER alt-notify-send backup "Waiting for things to settle" 0
sleep 5

su $NOTIFYUSER alt-notify-send backup "Starting backup" 0
echo "$(date) - Mounting /dev/backup to $BACKUPDIR" > /tmp/backup.log
mount /dev/backup $BACKUPDIR >> /tmp/backup.log 2>&1
echo "$(date) - Staring rsync of $MAINDIR to $BACKUPDIR" >> /tmp/backup.log
rsync -arvuz --inplace --delete $MAINDIR $BACKUPDIR >> /tmp/backup.log 2>&1
echo "$(date) - Mounting /dev/backup to $BACKUPDIR" >> /tmp/backup.log
umount $BACKUPDIR >> /tmp/backup.log 2>&1
su $NOTIFYUSER alt-notify-send backup "Backup completed" 0

We have a couple of things to setup here. First we need to create /mnt/backup as root, and fill out the other variables in the top of the script. Also, if we want notification in gnome, we need to make a notify-send work around. Put the following in /usr/local/bin/alt-notify-send

#!/bin/sh
user=`whoami`
pids=`pgrep -u $user gnome-panel`
title=$1
text=$2
timeout=$3

if [ -z "$title" ]; then
    echo You need to give me a title >&2
    exit 1
fi
if [ -z "$text" ]; then
     text=$title
fi
if [ -z "$timeout" ]; then
     timeout=60000
fi

for pid in $pids; do
    # find DBUS session bus for this session
    DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
    /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
    # use it
    DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
    notify-send -u low -t $timeout "$title" "$text"
done

Now chmod +x the two scripts, and everything should be good to go.


External programs that update screen

by Patrick Connelly posted on September 18, 2009

Screen is a great tool, and it allows you do to alot of neat things. One of my favorites is binding commands to key strokes. So all you have to do is hit F5 and it will start something in the background. Such as a build command. The problem is, you either get no output, or you get spam all over your screen. Well I’ve finally found a way around that. The answer lies in ANSI Privacy Messages.

In your .screenrc, make sure you have a place that will show messages. If you start up screen and you see “New screen…” then you’ve got this. Next add your script to your .screenrc

bind -k k5 exec /home/pcon/bin/build_script.sh

Now everything in your screen is ready to go. Now, on to build_script.sh

#!/bin/bash

echo -n -e "\033^Starting Build\033\\"

# Do something here

echo -n -e "\033^Ending Build\033\\"

That’s it. Now your screen will display “Starting Build” and “Ending Build” on your display. If the stuff in between happens too fast, you may only see your last message. The key thing is that your message has to start with \033^ and end with \033\\ otherwise you’ll lose your cursor. And you have to have the -e on the echo so that it will interpret the octal codes correctly.


irssi + mumbles == push notification goodness

by Patrick Connelly posted on August 31, 2009

One of the biggest problems with irssi is that if you run it on remote machine, it can be quite hard to get notifications. For the past couple of years, I’ve been running a plugin called fnotify that writes notifications to a file, then using another script I read that file and print it out with libnotify. There are a couple of problems with this:

  1. libnotify is ugly
  2. takes up diskspace if you don’t clear the queue
  3. requires you to either have the script, or remember the ridiculously long command

Well, these are things of the past. Thanks to mumbles!

First install mumbles from yum (or source) then install the irssi script. Make sure you change the growl_server and growl_password then you are good to go. The script has a dependency on Net::GrowlNotify in perl.

The script uses irssi config variables so you can use /SET growl_server or /SET growl_password to set your growl server/password without having to load/unload the script.


DVD player with xsessions

by Patrick Connelly posted on June 12, 2009

I’ve come across the need to simply the dvd playing process. I’m having to set up a laptop to play a dvd and use a remote presenter control. Now in the past I’ve just been in charge of this setup, and haven’t had to worry about explaining how to start it up for others. This time, I need to make it as user friendly as possible. So, I’ve decided to do this with a couple of bash scripts and a couple of xsessions.

Goals

  • Generic user with a generic password to hand to the person in charge
  • Ability to play dvd stored locally. (Called presentation_dvd)
  • Ability to play any dvd inserted.
  • Require no user input except to choose presentation_dvd or dvd

Preperation

To get ready, we need to do a couple of things

  • Create a presenter user
  • Install xine and xine-lib-extras-freeworld
  • Copy our presentation_dvd to an iso
    dd if=/dev/dvd of=/home/presenter/presentation_dvd.iso
    

Xesssions

Xsessions are what defines your window manager. It’s what tells X11 what to run when you say Session->Gnome or Session->fluxbox. These files are stored in /usr/share/xsessions.

[Desktop Entry]
Encoding=UTF-8
Name=Presentation_DVD
Comment=Start the presentation DVD
Exec=/usr/local/bin/presentation_dvd
Terminal=False

[Window Manager]
SessionManaged=true

This is our file in /usr/share/xesssions/presentation_dvd.desktop We then create one in /usr/share/xesssions/dvd.desktop and replace presentation_dvd with dvd.

The Scripts

Our /usr/local/bin/presentation_dvd looks like this:

#!bin/bash
amixer set Master playback 100%
xine -f -g --no-splash dvd:/home/presenter/presentation_dvd.iso

This will turn the volume up to 100% and then start xine on the iso. To exit, just right click and say exit. This will take you back to the login screen.

Now to handle any dvd with the /usr/local/bin/dvd

#!/bin/bash
amixer set Master playback 100%
xine -f -g --no-splash dvd://

And the final touch, make them both executable

chmod a+x /usr/local/bin/dvd /usr/local/bin/presentation_dvd

Usage

From the login menu, choose your presenter user, and then choose the appropriate session at the bottom. Then type in the password. Like magic, everything should work.

Potential problems

If you don’t see your session in the list, you might have a typo in your xsession file

If one of the xine scripts don’t work, try logging into gnome and running the script from the command-line to see why.


Mutt and Lynx

by Patrick Connelly posted on April 21, 2009

So, in my time with mutt, I have grown to have a disdain for people that send HTML only email. And surprisingly, this happens alot! So, instead of trying to change the world, I’ve decided to just use mutt and lynx to my advantage and call it a day. Thanks to one of my co-workers for showing me how to do this.

At the end of your ~/.mailcap file, add the following

text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^   //’; copiousoutput; needsterminal; nametemplate=%s.html

Then, in the ~/.muttrc add

auto_view text/x-vcard text/html text/enriched

And restart mutt. This will use lynx to render the email. You can substitute lynx for any text-based html browser you’d like.


Boxee and AppleTV

by Patrick Connelly posted on March 10, 2009

  1. Prior to starting up the AppleTV or even unboxing it, get your patchstick ready by following these instructions
  2. Unbox and setup the AppleTV to your LAN.
  3. Then, navigate to the setup->general->updates and make sure you STOP the update if you can. The update won’t technically break anything, but there are some problems with the newest firmware. If you can stop it it’s better
  4. Insert your patchstick, and reboot the AppleTV Linux loader
  5. Once it’s done open up your favorite terminal, and get ready to ssh to make sure that AppleTV can run any updates. The password is **frontrow
      ssh frontrow@appletv
      sudo bash -c ‘echo "127.0.0.1 mesu.apple.com" >> /etc/hosts'
    
  6. From the menu select ‘XBMC/Boxee’ → Updates and select the non-alpha boxee
  7. Wait and wait some more
  8. Download the darwinx86 iso from here you can get a free login for this by following the links
  9. Mount it up on the loop back and scp the /usr/bin/vim and /sbin/mount_nfs to the AppleTV
  10. You will need to make sure you nfs export has the option insecure or the AppleTV won’t be able to mount it
  11. Reboot one last time. You can do this with sudo /sbin/reboot now
  12. Choose boxee from the menu and launch it. There are a couple of known bugs with the latest firmware and boxee version.
  • Boxee starts with a black screen. The only real ‘fix’ for that is to restart it a bunch until it starts up right.
  • Boxee freezes on the menu. Remove the /Users/frontrow/Library/Application Support/BOXEE/UserData/ folder.

Boxee running


Reverse Alias in mutt

by Patrick Connelly posted on February 23, 2009

A need has arisen here recently for me to need to “change” the headers on an email, so I can tell two people at work apart. Both have their name in the email header the same. Let’s call them “John Doe.” So in order to tell them apart, I’ve added a reverse alias rule to mutt to handle this. First enable the use of them by using

set reverse_alias

Then set up the alias. This can be added to your alias file, or straight into your .muttrc

alias fake_john john_doe2@example.com (Fake John Doe)

Now all mail that comes in from john_doe2@example.com will show up as from “Fake John Doe” but the headers will remain the same, and no one is the wiser.


Web Apps to Desktop Apps

by Patrick Connelly posted on February 18, 2009

Something I’ve found very interesting, is the recent trend to move apps away from the desktop, and out into the “cloud.” Now, for the most part I agree with this. I rejoiced the day I moved from a pop3 account to an imap account. And then rejoiced again, when I moved my mail hosting to Google Apps. This is just the way most things are moving. Most people don’t need apps outside of email and word processing. And if that information can be stored in the cloud then that means I don’t have to be without my documents.

That brings me to the real point. If you haven’t gotten a chance to check out some of the apps that make desktop apps out of web apps, try them.

  • I like fluid for OSX, it seems a little more full featured
  • Then Prism is looking really promising for all platforms (yes, even linux)

Perpetual Screen Part Deux

by Patrick Connelly posted on February 02, 2009

So, I’ve figured out how to add in a “fail-safe” to the perpetual screen, so that if you want to ssh without starting screen you can. And it’s pretty easy. First add the following to your sshd_config and restart ssh

AcceptEnv NO_SCREEN

Then add the following to the bottom of you .bashrc: (Note: I named my screen ‘main’ you can name yours whatever you want)

NO_SCREEN=`echo "."$NO_SCREEN`
# Hack to get around if the variable is not set

if [ $TERM = "screen" ]
# If we are already in a screen do nothing
then
     echo -n ""
elif [ $TERM = "dumb" ]
# If we are using scp do nothing
then
     echo -n ""
elif [ $NO_SCREEN = ".true" ]
# Our fail safe to ssh w/o screen
then
     echo -n ""
else
# Startup screen
     screen -Rd main && exit
fi

Then, you can either ssh like normal to start the screen, or do the following to login without screen starting

export NO_SCREEN="true"

ssh -o "SendEnv NO_SCREEN" user@host

Works like a champ


Combining pdf with linux via the command-line

by Patrick Connelly posted on January 06, 2009

I’ve always found a need for this, and with some digging, I’ve found a couple of ways to do this. The simplist is with ImageMagik, but I’ve found the default values leave the quality a little lacking. However, I’ve found an article that uses GhostScript to do it, and it does a wonderful job.

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf

They suggest putting it in an alias, but I’ve gone a step further and just put it in a bash script in ~/bin/combinepdf

#!/bin/bash

if [ $# -le 1 ]
then
     echo "usage: combinepdf output.pdf input1.pdf ... inputN.pdf"
exit -1
fi

OUTPUT=$1

if [ -e $OUTPUT ]
then
     echo "Output file \"$OUTPUT\" exists"
exit -1
fi

fnum=2

INPUT="$2"
ARGV=( $@ )

while [ $fnum -lt $# ]
do
     INPUT=`echo $INPUT" "${ARGV[$fnum]}`
     let "fnum += 1"
done

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$OUTPUT $INPUT

Then chmod a+x ~/bin/combinepdf and then run it.


Perpetual Screen

by Patrick Connelly posted on December 29, 2008

This article has been updated

So, I’ve been tossing around the idea for the past while to make is so that screen starts up every time I ssh into my box at the house. Well, I finally broke down and did it, and it wasn’t that bad at all. I’ve named my screen session main you can call it whatever you want. Just add the following to the end or your .bashrc If you don’t put it at the end, you the rest of your .bashrc won’t get evaluated.

if [ $TERM == "screen" ]
# If we are already in a screen do nothing
then
  echo -n ""
elif [ $TERM == "dumb" ]
# If we are using scp do nothing
then
  echo -n ""
else
# Startup screen
  screen -Rd main && exit
fi

It works so far with everything I’ve had to do, but we’ll see if I run across any other problems.


Running Boxee on Ubuntu

by Patrick Connelly posted on December 07, 2008

First, I know I’m going to hell for using Ubuntu. But, I’m too lazy to compile xbmc and boxee on Fedora. So, now that it’s out of the way. Here’s the step-by-step:

  1. Install Ubuntu 10.4
  2. Add the extra boxee repo based on the instructions on boxee.tv
  3. Install mingetty and rcconf
      apt-get install mingetty rcconf
    
  4. Disable gdm with rcconf
  5. Add a boxee user with and add them to the “admin” and “audio” group
      useradd -G admin,audio -d /home/boxee boxee
    
  6. Add a .bashrc to /home/boxee
      case "`tty`" in
     /dev/tty1) startx
      esac
    
  7. Add .xinitrc to /home/boxee
      #!/bin/bash
      while [ 1 ]
      do
     exec /opt/boxee/Boxee --standalone
      done
    
  8. Make it executable
      chmod a+x .xinitrc
    
  9. Edit line in /etc/event.d/tty1
      #exec /sbin/getty 38400 tty1
      exec /sbin/mingetty --autologin boxee tty1
    
  10. Reboot and pray

Custom boot isos and imgs

by Patrick Connelly posted on June 06, 2008

I’ve spent the past couple of days banging my head against the desk trying to get this to work out correctly. And now it finally does. Just as a note, I’ve tested that the general steps work. I have not verified that I haven’t skipped a step. So if anything’s missing let me know.

This has only been tested with RHEL and nothing else, but there is no reason why it won't work. And if you don't have a satellite you can use this with any old kickstart. Assuming you have the tree setup correctly. Please test your kickstart tree first.

Satellite prep

Create your kickstart as you normally would. Then, make sure the kickstart is accessible via the following style URL:

http://satellite.example.com/kickstart/ks/view_label/<kickstart_label>

Replace <kickstart_label> with the name of label set on the satellite. Remember this URL, you’ll need it later

view_label VS label

In the kickstart URL, you can use either view_label or label. view_label will not register the box if there is not an activation key set inside the kickstart. label generates a one time use activation key and registers the box to the satellite

Why use one over the other?

view_label is good if you are using an activation key, or if you have to install a box a bunch of times, and don’t want to have a bunch of extra profiles lingering around.label is good if you don’t want to have to set up an activation key, and a machine is only going to be kickstarted once. If you are going to be using the disk image in a PXE like fashion, view_label is your best option.

Rolling the disk image (For usb-key)

Get the first disk of what ever you are trying to install from the kickstart. For this document, I will be using RHEL 5 U2 x86_64

NOTE: The arch and update must match or it will fail.

  • Copy the images/diskboot.img file to /root/rhel5u2-64bit.img
  • Mount the /root/rhel5u2-64bit.img file on the loopback /mnt/
  • Edit the /mnt/syslinux.cfg file, and add/edit the following:

    default custom
    prompt 0
    timeout 0
    display boot.msg
    label custom
    kernel vmlinuz
    
    append initrd=initrd.img ks=http://satellite.example.com/kickstart/ks/view_label/<kickstart_label> ksdevice=link noipv6
    
  • Edit the /mnt/boot.msg to say what you want. I recommend removing the lines below splash.lss and replace with something like:

    ``` Your install of Red Hat Enterprise Linux Update 2 (x86_64) will start shortly. ``

  • Unmount the diskboot.img file
  • Then burn to a cd, or copy to a jumpdrive with the following command:

    ```bash dd if=/root/rhel5u2-64bit.img of=/dev/sdc ``

    NOTE: Replace /dev/sdc with the device name of your jumpdrive

Rolling the disk image (For cdrom)

Get the first disk of what ever you are trying to install from the kickstart. For this document, I will be using RHEL 5 U2 x86_64

The arch and update must match or it will fail.
  • Copy the images/boot.iso file to /root/rhel5u2-64bit-boot.iso
  • Mount the /root/rhel5u2-64bit-boot.iso file on the loopback /mnt/
  • Make a directory in /tmp/ /tmp/rhel5u2-64bit/
  • Copy /mnt/* to that directory
  • Unmount the rhel5u2-64bit-boot.iso file
  • Remove the rhel5u2-64bit-boot.iso file to reduce confusion
  • Make the /tmp/rhel5u2-64bit/isolinux/isolinux.cfg writable by root
  • Edit the /tmp/rhel5u2-64bit/isolinux/isolinux.cfg file, and add/edit the following:

    default custom
    prompt 0
    timeout 0
    display boot.msg
    label custom
    kernel vmlinuz
    
    append initrd=initrd.img ks=http://satellite.example.com/kickstart/ks/view_label/<kickstart_label> ksdevice=link noipv6
    
  • Edit the /tmp/rhel5u2-64bit/isolinux/boot.msg to say what you want. I recommend removing the lines below splash.lss and replace with something like:

    Your install of Red Hat Enterprise Linux Update 2 (x86_64) will start shortly.
    
  • Then make a bootable iso by running:

    cd /tmp/
    mkisofs -r -T -J \
      -V "RHEL 5u2 x86_64 kickstart iso" \
      -b isolinux/isolinux.bin -c isolinux/boot.cat \
      -no-emul-boot -boot-load-size 4 -boot-info-table \
      -v -o "/root/rhel5u2-64bit.iso" /tmp/rhel5u2-64bit/
    
  • The burn the cd as a cd image

Boot

The insert the media into the machine and boot off of it.