Tagged: Shell Scripts Toggle Comment Threads | Keyboard Shortcuts

  • jess 7:56 pm on June 11, 2010 Permalink | Reply
    Tags: , , Shell Scripts   

    Mac OSX 10.6 Shell Script to Configure, Launch, and Shutdown Screen Sharing 

    Apple’s MacOS has a tidy built in remote access client and service generically known as “Screen Sharing”. Yay! This works great for headless machines, testing servers, and annoying your spouse. The paranoid and performance conscious user may not want these services continuously running. Rogue services hanging out, listening, and waiting for some punk to probe them in an Internet dark alley. This cobbled together shell script might be for you!

    This shell script has four simple commands (I use sudo because I really should):

    • # sudo ./share-screen.sh start
    • # sudo ./share-screen.sh stop
    • # sudo ./share-screen.sh allow {username}
    • # sudo ./share-screen.sh deny {username}

    I use this in terminal. Make sure you put a copy of this script on the target machine and make it executable. First I make sure that Remote Login is active on the target computer. It’s under Sharing in System Preferences. Then I login remotely using ssh. I fire up the script, activate Screen Sharing, do my business, shutdown Screen Sharing, log off, and go home.

    Of course, no warranty, no guaranty. Good Luck!

    #!/bin/bash
    
    if [ $# == 0 ]; then
    	echo  "Commands: start, stop, allow <username>, deny <username>"
    	exit
    fi
    
    case "$1" in
    	start)
    		echo 'Starting Remote Access'
    		# Activate Apple Remote Access with current settings
    		sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate
    		;;
    	stop)
    		echo 'Stopping Remote Access'
    		# Deactivate Apple Remote Access
    		sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -stop
    		;;
    	allow)
    		if [ -z "$2" ]; then
    			echo  "ERROR: Provide a valid user"
    			exit
    		fi
    		sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -specifiedUsers
    		sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -access -on -privs -all -users ${2}
    		;;
    	deny)
    		if [ -z "$2" ]; then
    			echo  "ERROR: Provide a valid user"
    			exit
    		fi  
    		sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -specifiedUsers
    		sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -access -off -privs -none -users ${2}  
    		;;  
    esac
    

    I almost forgot. Credit where credit is due! Inspiration from these articles and resources:

    http://www.macosxhints.com/article.php?story=20080318190503111
    http://rentzsch.tumblr.com/post/515009165/starting-vnc-remotely-via-kickstart

     
  • jess 2:52 pm on March 25, 2010 Permalink | Reply
    Tags: Shell Scripts, Subversion,   

    My Ugly WordPress, HyperDB, & BuddyPress Deployment Shell Script 

    This is the source of some of the website deployment scripts I have. This is one is fairly complex and it is my pocket tool of choice for development of big nasty WordPress sites. Probably only interesting to folks who deal with unix shells and do mildly heavy WordPress work.

    It’s designed to update from SVN trunk for WordPress, HyperDB, & BuddyPress. My favorite is quick rsync for folders and subfolders so you can upload theme changes quickly because the web is my sketchpad.

    Common List of Commands:

    # Get the configured site 
    ./wp-work.sh get
    # Put the configured site 
    ./wp-work.sh put
    # Upgrade the configured site to latest WordPress, HyperDB, &amp; BuddyPress
    ./wp-work.sh upgrade
    # Put specific folders in the sites root
    ./wp-work.sh work put the-site-folder
    # get specific folders in the sites root
    ./wp-work.sh work get the-site-folder
    

    The Big Ugly Script:

    You will really want to customize the top values for sure.

    #!/bin/sh
    
    # Batch Update jess
    #
    # Uses flat array list of site locations, updates using latest source from SVN and performs all update steps.
    #
    
    # Website Name
    WEB_ROOT_NAME="example.com"
    
    # Web Direcory locations Using $HOME is good.
    WEB_ROOT_LOCAL="${HOME}/luser/${WEB_ROOT_NAME}/"
    WEB_ROOT_REMOTE="/home/luser/${WEB_ROOT_NAME}/"
    
    # Archive -a mode is -rlptgoD -pgo is permission, user, group and be an issue had to add -vz
    RSYNC_SWITCH='-vzrltD'
    # SSH command because you might need: 'ssh -i /shh/secret-key/master-magic-key -p 56232'
    RSYNC_SSH='ssh'
    # Remember the ssh account is where your files land.
    RSYNC_SSH_ACCOUNT='me@example.com'
    
    # Tools location for exclude files ans stuff. Using $HOME is good.
    TOOLS_ROOT_LOCAL="${HOME}/luser/stuff/"
    TOOLS_ROOT_EXCLUDES="${HOME}/luser/stuff/"
    
    # Temp files
    TEMP_ROOT_LOCAL="${HOME}/luser/tmp/"
    
    # Putting the path into a variable gets tricky
    WORKING_TEMP_LOCATION=$( readlink -nf ${TEMP_ROOT_LOCAL} )
    
    # Move to tools directory so we can find things easier.
    cd ${TOOLS_ROOT_LOCAL}
    
    # Print good ole help if no command
    if [ $# == 0 ]; then
    	echo  "${WEB_ROOT_NAME} Commands: get, put, upgrade, work [put or get] [directory]"
    	exit	
    fi
    
    # Get all remote
    if [ $1 == "get" ]; then
      echo '----- Start Site Download -----'
      echo  "Get all stuff with a few exceptions."
      rsync ${RSYNC_SWITCH} --delete -e "${RSYNC_SSH}" ${RSYNC_SSH_ACCOUNT}:${WEB_ROOT_REMOTE} ${WEB_ROOT_LOCAL}
      exit
    fi
    
    # Put all with some exceptions
    if [ $1 == "put" ]; then
      echo '----- Start Site Upload -----'
      echo  "Put all stuff with a few exceptions."
      rsync ${RSYNC_SWITCH} --delete --exclude-from=${TOOLS_ROOT_EXCLUDES}wordpress-exclude.txt -e "${RSYNC_SSH}" ${WEB_ROOT_LOCAL} ${RSYNC_SSH_ACCOUNT}:${WEB_ROOT_REMOTE}
      exit
    fi
    
    # Upgrade with merge from several sources
    if [ $1 == "upgrade" ]; then
    
    	echo  "Don't have this for work.funroe.net"
    
    	exit
    	
    	mkdir ${WORKING_TEMP_LOCATION}
    	mkdir ${WORKING_TEMP_LOCATION}/wordpress
    	mkdir ${WORKING_TEMP_LOCATION}/buddypress
    	mkdir ${WORKING_TEMP_LOCATION}/hyperdb
    	
    	svn co http://svn.automattic.com/wordpress/trunk/ ${WORKING_TEMP_LOCATION}/wordpress/
    	svn co http://svn.buddypress.org/trunk/ ${WORKING_TEMP_LOCATION}/buddypress/
    	svn co http://svn.wp-plugins.org/hyperdb/trunk/ ${WORKING_TEMP_LOCATION}/hyperdb/
    	 
    	mv -f ${WORKING_TEMP_LOCATION}/buddypress ${WORKING_TEMP_LOCATION}/wordpress/wp-content/plugins/buddypress
    	mv -f ${WORKING_TEMP_LOCATION}/hyperdb/db.php ${WORKING_TEMP_LOCATION}/wordpress/wp-content/db.php
    	
    	echo '----- Update local site -----'
    	rsync ${RSYNC_SWITCH} --delete --exclude-from=${TOOLS_ROOT_EXCLUDES}wpmu-bbpres-bp-exclude.txt  ${WORKING_TEMP_LOCATION}/wordpress/ ${WEB_ROOT_LOCAL}
    	
    	echo  "----- Remove temp working directory! -----"
    	rm -Rf ${WORKING_TEMP_LOCATION}
    	
    	echo  "----- Update remote site! -----"	
    	rsync ${RSYNC_SWITCH} --delete --exclude-from=${TOOLS_ROOT_EXCLUDES}wordpress-exclude.txt -e "${RSYNC_SSH}" ${WEB_ROOT_LOCAL} ${RSYNC_SSH_ACCOUNT}:${WEB_ROOT_REMOTE}
    	echo '----- DONE! -----'
    	
    	exit
    fi
    
    # Work allows get and put of specific directories starting at web root ie. this.command work put wp-content/themes
    if [ $1 == "work" ]; then
    
     	# Putting the path into a variable gets tricky
     	WORKING_LOCAL_LOCATION=$( readlink -nf ${WEB_ROOT_LOCAL}${3} )
    	
    	if [ ! -d "${WORKING_LOCAL_LOCATION}" ]; then
    		if [ ! -f "${WORKING_LOCAL_LOCATION}" ]; then
    			 echo "Not a valid work site! Please try again."
    			 exit
    		fi
    	fi
    	
    	# Set remote location
    	WORKING_REMOTE_LOCATION=${WEB_ROOT_REMOTE}${3}
    			
    	# Add slashes to end if they were omitted
    	if [ `echo "$WORKING_LOCAL_LOCATION" | grep "[^/]$"` ]; then 
    		WORKING_LOCAL_LOCATION="${WORKING_LOCAL_LOCATION}/"; 
    		WORKING_REMOTE_LOCATION="${WORKING_REMOTE_LOCATION}/"; 
    	fi
    	
    	# Remove double slashes
    	WORKING_LOCAL_LOCATION=${WORKING_REMOTE_LOCATION//\/\//\/}	
    	WORKING_REMOTE_LOCATION=${WORKING_REMOTE_LOCATION//\/\//\/}
    
    	echo "rsync ${RSYNC_SWITCH} --delete --exclude-from=${TOOLS_ROOT_EXCLUDES}wordpress-exclude.txt -e "${RSYNC_SSH}" ${WORKING_LOCAL_LOCATION}  ${RSYNC_SSH_ACCOUNT}:${WORKING_REMOTE_LOCATION}"
    
    	if [ $2 == "get" ]; then
    	  echo "----- Get All ${WEB_ROOT_NAME} -----"
    	  echo  "Downloading all work.funroe.net/$work_site files..."
    	  rsync ${RSYNC_SWITCH} --delete -e "${RSYNC_SSH}" ${RSYNC_SSH_ACCOUNT}:${WORKING_REMOTE_LOCATION} ${WORKING_LOCAL_LOCATION}
    	  exit
    	fi
    	
    	if [ $2 == "put" ]; then
    	  echo "----- Put ${WEB_ROOT_NAME} -----"
    	  echo  "Uploading selected work.funroe.net/$work_site files..."
          rsync ${RSYNC_SWITCH} --delete --exclude-from=${TOOLS_ROOT_EXCLUDES}wordpress-exclude.txt -e "${RSYNC_SSH}" ${WORKING_LOCAL_LOCATION}  ${RSYNC_SSH_ACCOUNT}:${WORKING_REMOTE_LOCATION}
    	  exit
    	fi	
    
    fi
    

    Exclude file: wordpress-exclude.txt needs to be in that TOOLS_ROOT_EXCLUDES directory. I use it skip stuff that I don’t want to be synced on upload because the remote file changes are most important.

    .htaccess
    wp-config.php
    bb-config.php
    cache/
    blogs.dir
    uploads
    wp-content/advanced-cache.php
    wp-cache-config.php
    sitemap.xml.gz
    robots.txt
    sitemap.xml
    googlee-thingyfile.html
    

    Exclude file: wpmu-bbpress-bp.txt needs to be in that TOOLS_ROOT_EXCLUDES directory. This is to keep files from being overwritten when a package is created from the SVN repositories and moved to the local site staging area. This really may need customized to protect your personal themes, plugins, and files.

    # WP Core excludes
    - .htaccess
    - wp-config.php
    - bb-config.php
    - /cgi-bin
    - /cache
    - blogs.dir
    - uploads
    
    # Themes
    + themes/index.php
    + themes/classic
    + themes/default
    + themes/twentyten
    - themes/*
    
    # Plugins
    + plugins/readme.txt
    + plugins/index.php
    + plugins/buddypress
    - plugins/*
    
    # MU Plugins
    + mu-plugins/readme.txt
    + mu-plugins/index.php
    - mu-plugins/*
    
    # Hyper DB
    - db-settings.php
    
     
  • jess 2:15 pm on March 25, 2010 Permalink | Reply
    Tags: , Shell Scripts, Tommy Johnson   

    Tommy’s diggall.sh revised 

    Think you know the linux digg command? Ever try to do some simple network discovery with it? This script by Tommy Johnson does some nice condensed discovery. Just pass a domain for the argument.

    ./diggall.sh example.com

    That is all!

    #!/bin/bash
    echo "MX points to:"
    dig MX $1 +short | sort -n
    echo ""
    echo "A points to:"
    dig A $1 +short
    echo ""
    echo "www points to:"
    dig A www.$1 +short
    echo ""
    echo "mail points to:"
    dig A mail.$1 +short
    echo ""
    echo "SOA Nameserver declared:"
    echo `dig SOA $1 +short | awk '{print $1}'`
    echo ""
    #echo "oldmail points to:"
    #dig A oldmail.$1 +short
    domain1=( $(echo $1 | awk -F '.' '{print $1}'))
    domain2=( $(echo $1 | awk -F '.' '{print $2}'))
    domain3=( $(echo $1 | awk -F '.' '{print $3}'))
    domain2=( $(echo $domain2.$domain3 | sed 's/[:.:]$//') )
    first=( $(dig NS +short $domain2 | sed 's/[:.:]$//') )
    second=( $(dig +short NS $domain2 @$first | sed 's/[:.:]$//') )
    #echo "Authoritative nameserver for TLD is: "$second
    #echo '+===============================================+'
    echo "Name Servers as reported by registrar:"
    echo `dig NS $domain1.$domain2 @$second | grep "AUTHORITY SECTION" -A3 | grep -v AUTHORITY | awk '{print $5}'`
    echo "IPs declared by registrar:"
    echo `dig NS $domain1.$domain2 @$second | grep "ADDITIONAL SECTION" -A3 | grep -v ADDITIONAL | awk '{print $5}'`
    #echo '+===============================================+'
    echo ""
    echo "Name Servers in zone file are:"
    dig NS $1 +short
    dig NS $1 | grep "ADDITIONAL SECTION" -A3 | grep -v ADDITIONAL | awk '{print $5}'
    echo "txt record is:"
    dig txt $1 +short
    
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel