Commits

Anonymous committed 3e68e56

Update comments on utility scripts.

  • Participants
  • Parent commits bda6a9c

Comments (0)

Files changed (2)

File _build/vasm-devel.sh

 #!/bin/sh
+# This script by Jason Pierce <echo -e "moc\x2eliamg\x40nosaj.ecreip" | rev>.
+# Licensed as MIT.
 SELF=$(basename $0 | cut -d. -f1)
 helper_ver="0.1"
 
 	main;
 fi;
 
+# TODO: 1) setup logging 2) implement passthrough args 3) implement --alternate_source
 until [ -z "$1" ]; do
 	case "$1" in
 		-a | --alternate_source ) hg_url="$2"; shift;;

File src/vasm/data/setup_logging.sh

 #!/bin/sh
-logFile="/var/log/vasm.log";
+# This script by Jason Pierce <echo -e "moc\x2eliamg\x40nosaj.ecreip" | rev>.
+# Licensed as MIT.
+SELF=$(basename $0 | cut -d. -f1)
+helper_ver="0.1"
 
-in_use() {
-	local property;
-	property=$1;
-	usingProperty=$( grep -I $property /etc/syslog.conf | sed "s/#.*$//" | sed '/^$/d' | wc -l );
-	if [ "$usingProperty" -gt "0" ]; then
-		# This property is in use.
-		echo true;
+usage() {
+cat <<HELP
+$SELF - Update helper for ${pkgname%-devel} development tree.
+Handles update checking and launches ${pkgname%-devel}. Any options after a double
+dash -- are passed unmodified to the ${pkgname%-devel} subprocess.
+ver. $helper_ver
+
+Usage: $SELF [-u] [-h]
+Usage: $SELF [-a] [-l] [VASM UI] -- [VASM OPTS]
+
+Options:
+	-a, --alternate_source <mercurial repo>
+		Use alternate source repo for updates.
+		Default: $hg_url
+		NOTE: Option not current implemented.
+	-h,  --help
+		Output this help message.
+	-l, --library
+		Start helper in shell library mode. Do not run any functions.
+		Allow functions and variables to be sourced into an
+		interactive POSIX environment.
+	-u, --update
+		Run update checks then exit.	
+		
+VASM UI selects the user interface. If not specified, auto-selection is
+based on presence of running Xorg(env DISPLAY). Usually resulting in GUI.
+
+Valid VASM UI choices:
+	tui
+		Text user interface, utilizing urwid display toolkit.
+	gui
+		Graphical user interface, utilizing gtk display toolkit.
+HELP
+}
+
+
+#####################  Configuration  #####################
+
+pkgname="vasm-devel"
+pkgdir="/opt/$pkgname" # Location of files on disk
+hg_url="https://bitbucket.org/m0e_lnx/vasm" # Where to clone/pullfrom
+change_file=".hg/last_pull" # File for checking last pull
+update_timeframe="4"; # 4 days between update checks
+	
+#####################  Functions  #####################
+
+# Ensures directory exists and repo has been cloned.
+startup_verification() {
+	if [ ! -d "$pkgdir" ]; then
+		echo "Directory $pkgdir does not exist.";
+		echo -e "This should have been created by package install.\nExiting.";	
+		exit;
+	fi;
+	
+	cd $pkgdir;
+	
+	if [ ! -d "$pkgdir/.hg" ]; then
+		echo "Directory $pkgdir/.hg does not exist.";
+		echo "Devel repo not initialized. Cloning now.";
+		
+		hg clone $hg_url $pkgdir/; local hg_ret=$?;
+		touch_change_file $hg_ret;
 	fi;
 }
 
-syslog_payload() {
-	local facility;
-	local payload;
-	facility=$1;
-	cat <<EOF
+# List files changed since last update.
+# Run between pull and update commands.
+show_changed() {
+	hg status --rev . --rev tip;
+}
 
-# Vasm centralized logging to facility $facility.
-$facility.*					-$logFile
-EOF
+# Update the timestamp on our change_file.
+# First check if any problems pulling (hg_ret).
+touch_change_file() {
+	local hg_ret=$1;
+
+	if [ "$hg_ret" -gt "0" ]; then
+		echo "Problem pulling updates. hg returned status $hg_ret";
+		exit 1;
+	else
+		# 'Touch' the change_file.
+		echo "Do not remove." > $pkgdir/$change_file; 
+	fi;
 }
+
+# See if our check_file dates indicate a need to update.
+# Turn dates 2011-10-18* into 20111018 for doing math.
+# Prompt before checking for updates.
+need_updates() {
+	local last_pull;
+	local today;
+	local difference;
 	
-
-usingVasm=$( in_use "$logFile" );
-if [ $usingVasm ]; then
-	# Vasm logging already setup
-	echo "Logging already configured for $logFile."
-	echo "Doing nothing.";
-	exit 0;
-else
-	echo "Logging not configured for $logFile.";
-	echo "Configuring in /etc/syslog.conf.";
-	usingLocal0=$( in_use "local0" );
-	if [ $usingLocal0 ]; then
-		# Something else is using 'local0'
-		echo "Logging facility 'local0' already in use."
-		echo "Checking for 'local1' now.";
-		usingLocal1=$( in_use "local1" );
-		if [ $usingLocal1 ]; then
-			# Something else is using 'local1';
-			echo "Logging facility 'local1' already in use.";
-			echo "Aborting configuration of /etc/syslog.conf.";
-			echo "Please configure manually for vasm logging.";
+	if [ -f $pkgdir/$change_file ]; then
+		last_pull=$( stat -c%y $pkgdir/$change_file | cut -d " " -f1 | sed "s/-//g" );
+	else
+		get_updates;
+		return;
+	fi;
+	
+	today=$( date +%F | sed "s/-//g" );
+	difference=$(( $today - $last_pull ));
+	if [ "$difference" -gt "$update_timeframe" ]; then
+		echo "Time to check for updates. Run \`hg pull\` now? [Y/n]";
+		read confirm;
+		if [ "$confirm" != "n" ]; then
+			get_updates;
+			return;
 		else
-			# We can use 'local1'.
-			facility="local1";
+			echo "Update check aborted. You can do this at any time by running \`hg pull && hg update\`.";
+			return;
 		fi;
 	else
-		# We can use 'local0'.
-		facility="local0";
+		echo "Less than $update_timeframe days since last check. Not doing automatic update.";
+		echo "You can force update at any time by running \`$SELF -u\`.";
+	fi;
+}
+
+# Pull and display updates. Update change_file timestamp.
+# Prompt before merging updates into filesystem.
+get_updates() {
+	hg pull; local hg_ret=$?;
+	touch_change_file $hg_ret;
+	show_changed;
+	echo "Merge these changes? [Y/n]";
+	read confirm;
+	if [ "$confirm" != "n" ]; then
+		hg update;
+	else
+		echo "Merge aborted. You can do this at any time by running \`hg update\`.";
+	fi;
+}
+
+choose_ui() {
+	local ui_choice;
+	local ui_command;
+	
+	if [ -z "$1" ]; then
+		if [ -z "$DISPLAY" ]; then
+			ui_choice="tui";
+		else
+			ui_choice="gui";
+		fi;
+	else
+		ui_choice="$1";
 	fi;
 	
-	# Write our conf lines to syslog config file.
-	syslog_payload $facility >> /etc/syslog.conf;
-	echo "Configured with facility=$facility logfile=$logFile.";
+	case "$1" in
+		tui	) ;;
+		gui	) ;;
+		*	) echo "Unknown ui selected: $ui_choice. If this is really what you want, try passing it directly to ${pkgname%-devel}."
+	esac;
+	
+	echo "Running ${pkgname%-devel} with selected UI: $ui_choice." > /dev/stderr;
+	echo $ui_command;
+}
+
+main() {
+	local ui_cmd;
+	
+	# Make sure we have a directory and a repo in place.
+	startup_verification;
+	
+	# Check timestamps to see if we need to try to update.
+	need_updates;	
+	
+	ui_cmd=$( choose_ui $1 );
+	
+	echo "python2 $ui_cmd";
+	python2 $ui_cmd;
+	exit 0;
+}
+
+#####################  Dispatcher code	#####################
+
+if [ -z "$1" ]; then
+	main;
 fi;
+
+# TODO: 1) setup logging 2) implement passthrough args 3) implement --alternate_source
+until [ -z "$1" ]; do
+	case "$1" in
+		-a | --alternate_source ) hg_url="$2"; shift;;
+		-l | --library ) DO='';;
+		-u | --update ) startup_verification; DO="get_updates";;
+		-h | --help | -* ) usage; exit;;
+		* ) DO="main $1";;
+	esac;
+	shift;
+done;
+
+eval "$DO";