Sign up to create your own snipts, or login.

Public snipts » jrguitar21's snipts The latest snipts from jrguitar21.

showing 1-20 of 34 snipts
  • install Drush from CVS HEAD on any unix server
    ##
    ## Installs Drush (the Drupal Shell command line utility) from CVS HEAD 
    ## on any UNIX machine, such that all users that have /usr/local/bin in
    ## their $PATH can use Drush (granted they have access to a Drupal install).
    ##
    ##
    
    cd /usr/local/src
    cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d drush-HEAD contributions/modules/drush/
    curl -O http://download.pear.php.net/package/Console_Table-1.1.3.tgz
    tar zxvf Console_Table-1.1.3.tgz
    cp Console_Table-1.1.3/Table.php drush-HEAD/includes/table.inc
    ln -s /usr/local/src/drush-HEAD/drush /usr/local/bin/drush
    
    ##
    ## now any user that has /usr/local/bin in their $PATH can use Drush.
    ##
    ##
    ## ... later on, to keep drush up to date, run the following:
    
    #cd /usr/local/src/drush-HEAD
    #cvs update -dPA
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Mar 05, 2010 at 11:38 a.m. EST
  • create ssh RSA id
    # Create an SSH id and public key pair (RSA) on your laptop/local machine
    mkdir ~/.ssh
    chmod 700 ~/.ssh
    ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
    ## Enter passphrase (empty for no passphrase): …
    ## Enter same passphrase again: …
    
    # protect your SSH keys
    chmod go-w ~/
    chmod 700 ~/.ssh
    chmod go-rwx ~/.ssh/*
    
    # Send your public id to the server. 
    # @see http://snipt.net/jrguitar21/passwordless-rsa-ssh-1-liner/
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 29, 2010 at 10:26 a.m. EST
  • install svn on shared host
    #Install subversion on a shared host
    
    
    curl -O http://subversion.tigris.org/downloads/subversion-1.6.9.tar.gz
    curl -O http://subversion.tigris.org/downloads/subversion-deps-1.6.9.tar.gz
    curl -O http://www.openssl.org/source/openssl-0.9.8l.tar.gz
    
    tar zxvf openssl-0.9.8l.tar.gz
    tar zxvf subversion-1.6.9.tar.gz
    tar zxvf subversion-deps-1.6.9.tar.gz
    
    cd openssl-0.9.8l/
    ./config shared --prefix=$HOME/installs && make clean && make && make install
    cd ../
    
    export CFLAGS="-O2 -g -I$HOME/installs/include"
    export LDFLAGS="-L$HOME/installs/lib"
    export CPP="gcc -E -I$HOME/installs/include"
    
    cd subversion-1.6.9/neon/
    ./configure --with-ssl=openssl --prefix=$HOME/installs
    cd ../
    ./configure --with-ssl --prefix=$HOME/installs --with-neon=$HOME/installs/bin/neon-config
    make clean && make && make install
    
    echo 'store-plaintext-passwords=no' >> ~/.subversion/servers
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 28, 2010 at 8:01 p.m. EST
  • remove .svn folders
    find . -name ".svn" -type d -exec rm -rf {} \;
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 06, 2010 at 11:47 a.m. EST
  • detect linux distro
    #!/bin/sh
    # Detects which OS and if it is Linux then it will detect 
    # which Linux Distribution.
    
    OS=`uname -s`
    REV=`uname -r`
    MACH=`uname -m`
    
    GetVersionFromFile()
    {
    	VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
    }
    
    if [ "${OS}" = "SunOS" ] ; then
    	OS=Solaris
    	ARCH=`uname -p`	
    	OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
    elif [ "${OS}" = "AIX" ] ; then
    	OSSTR="${OS} `oslevel` (`oslevel -r`)"
    elif [ "${OS}" = "Linux" ] ; then
    	KERNEL=`uname -r`
    	if [ -f /etc/redhat-release ] ; then
    		DIST='RedHat'
    		PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
    		REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
    	elif [ -f /etc/SUSE-release ] ; then
    		DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
    		REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
    	elif [ -f /etc/mandrake-release ] ; then
    		DIST='Mandrake'
    		PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
    		REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
    	elif [ -f /etc/debian_version ] ; then
    		DIST="Debian `cat /etc/debian_version`"
    		REV=""
    
    	fi
    	if [ -f /etc/UnitedLinux-release ] ; then
    		DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
    	fi
    	
    	OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
    
    fi
    
    
    echo ${OSSTR}
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 06, 2010 at 11:20 a.m. EST
  • outdated drupal module with svn
    ## In a nutshell, how to update a module from Drupal contrib, 
    ## on a production site that is under revision control (subversion).
    
    # If you turn on a module (that just happens to already be
    # present in the list on admin/build/modules), then you MUST
    # 1)  go to the update status page
    # 2)  find out if the module you just turned on is up to date
    # 3)  if it is,  fine (your done! stop here),  
    # 4)  if there are updates... then go to the drupal.org site first
    #     to see if there are any "gotchas" for the upgrade.  As you'll
    #     be turning the module on for the first time on a new site,
    #     then you shouldnt have to worry too much.
    # 5)  To run the updates: login via ssh
    
    ssh username@server.com
    
    # 6) go to the right folder and execute drush update
    
    cd domains/example.com/public_html/sites/all/modules
    drush --uri=example.com update modulename
    
    # 7) confirm that the update was successful on the site
    # 8) then check in the code
    
    svn commit -u username -m "updated modulename to the latest version"
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 23, 2009 at 4:49 p.m. EST
  • apache configure htaccess defaults
    #
    # AccessFileName: The name of the file to look for in each directory
    # for additional configuration directives.  See also the AllowOverride
    # directive.
    #
    AccessFileName .htaccess
    
    #
    # The following lines prevent .htaccess and .htpasswd files from being 
    # viewed by Web clients. 
    #
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
    </Files>
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 15, 2009 at 7:59 a.m. EST
  • protect svn/cvs in apache conf
    # Protect revision controlled web projects. This version is 
    # for Apache's global configuration (conf) file. Protection
    # can also be done if you dont have access to Apache conf, 
    # in any directorie's .htaccess file, in which case,  Apache 
    # conf must aleady be configured to use htaccess.
    <DirectoryMatch "^/.*/(\.svn|CVS)/">
      Order deny,allow
      Deny from all 
    </DirectoryMatch>
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 15, 2009 at 7:57 a.m. EST
  • svn bash shortcuts
    alias .s='svn stat'
    alias .c='svn ci -m'
    alias .u='svn up'
    alias .a='svn stat | grep "^\?" | awk "{print \$2}" | xargs svn add'
    alias .d='svn stat | grep "^\!" | awk "{print \$2}" | xargs svn delete'
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 14, 2009 at 2:48 p.m. EST
  • divide and conquer svn repo
    # The following structure exists:
    #
    #  originalrepository/
    #    project_name/
    #      trunk/
    #      branches/
    #      tags/
    #
    # I want to move it to its *own* repository and give the following structure:
    #
    #  newrepositoryname/
    #    trunk/
    #    branches/
    #    tags/
    #
    
    export LOCAL='file:/'
    export SVN_DIR='/home/bluespark/svn'
    export SVN_OLD_REPO='originalrepository'
    export SVN_PROJ='project_name'
    export SVN_REPO='newrepositoryname'
    
    cd $SVN_DIR
    
    ## Create dumps
    mkdir $SVN_DIR/dumps
    svnadmin dump $SVN_OLD_REPO > dumps/$SVN_OLD_REPO.dump
    
    ## Filter the specific project_name out of the dump
    svndumpfilter include $SVN_PROJ \
         --drop-empty-revs \
         --preserve-revprops \
         --renumber-revs \
         < dumps/$SVN_OLD_REPO.dump \
         > dumps/$SVN_PROJ.dump
    
    ## Create the new repository...
    ## NOTE: You may need to do this step in the cpanel!!
    ## Here is how to do it on the comand line:
    # svnadmin create $SVN_DIR/$SVN_REPO
    
    
    ## Load the new repository with the contents of the
    ## filtered dump file.
    svnadmin load $SVN_REPO < dumps/$SVN_PROJ.dump
    
    
    ## Move the contens of the project_name to the repo root.
    svn mv $LOCAL/$SVN_DIR/$SVN_REPO/$SVN_PROJ/branches \
           $LOCAL/$SVN_DIR/$SVN_REPO/$SVN_PROJ/tags \
           $LOCAL/$SVN_DIR/$SVN_REPO/$SVN_PROJ/trunk \
           $LOCAL/$SVN_DIR/$SVN_REPO/ \
           -m "moved $SVN_PROJ contents to root"
    
    ## Delete the old (empty) project directory.
    ## Note:  you need to make sure the directory 
    ##        is really empty before deleting!
    svn del $SVN_DIR/$SVN_REPO/$SVN_PROJ -m "removed old project directory"
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 14, 2009 at 2:34 p.m. EST
  • update drupal from subversion tags
    # Update a Drupal minor revision using a patch file.
    # Creating a patch file between cvs tags on the server proved to be 
    # impossible. I've found a way to do this with a subversion mirror
    # of Drupal core.
    
    cd ~/path/to/local/drupal
    
    # What is current version of Drupal?
    cat CHANGELOG.txt | grep Drupal | head -1
    ## Drupal 6.13, 2009-07-01
    
    # I'm using a Subversion mirror of Drupal core to create the patch.
    # (Thanks to the guys at subversible.com!)
    svn diff http://subversible.com/svn/drupal/tags/DRUPAL-6-13 \ 
             http://subversible.com/svn/drupal/tags/DRUPAL-6-14 > d6-14.patch 
    
    # The local version of drupal was created from a tarball, and the date 
    # format inside the $Id$ (from CVS) is: YYYY/mm/dd HH:MM:SS,  but in the 
    # subversion patch it was YYYY-mm-dd HH:MM:SS.  So I had to this quick 
    # find/replace in order to get the patch to apply cleanly.
    perl -pi -e 's/(\d{4})-(\d{2})-(\d{2})\s(\d{2})/\1\/\2\/\3 \4/g' d6-14.patch
    
    
    # Check to see if you have any outstanding uncommitted local changes. If
    # there are some changes then execute the commit (commented out below).
    svn status
    #svn commit -m "latest changes prior to drupal core update"
    
    # Apply the patch.  The patch from svn diff command should be in 
    # unified diff format (-u) and the paths should be taken as they are so 
    # files in subfolders are matched (-p0).
    patch -p0 -u <d6-14.patch
    
    
    #dont forget to commit the updates...
    svn commit -m "updated core drupal"
    
    #optionally, tag the updated code in the repository
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 11, 2009 at 7:45 p.m. EST
  • mac os x apache development setup
    ##
    ##  This will setup a fresh install of Mac OS X up for AUTOMATICALLY serving
    ##  custom top level domains (such as .dev or .test) for your development 
    ##  environment on a MacBook Pro laptop.  You no longer have to muck with adding
    ##  VirtualHosts  or editing /etc/hosts files, and you definitely dont need 
    ##  to download MAMP.
    ##
    ##  I recommend executing commands below by hand. 
    ##
    ##  After completion of all the commands, add  ""127.0.0.1""  (without quotes)
    ##  to the top of the list of DNS servers in:
    ##    
    ##     System Preferences > Network > Advanced... > DNS tab > DNS Servers
    ##
    ##  The directory structure of your ~/Sites folder should be the following: 
    ##   ~/Sites
    ##     |- dev
    ##     |  |- project1
    ##     |  |  |- public
    ##     |  |  |  |- index.html
    ##     |  |  |  |- otherpage.html
    ##     |  |- subdomainswork.project2
    ##     |  |  |- public
    ##     |  |  |  |- index.html
    ##
    ##  The BIND / Apache configurations explained below combined with the above 
    ##  example folder structure would enable the following:
    ##
    ##   http://localhost/                
    ##          <--- /Users/username/Sites/ 
    ##   http://project1.dev/             
    ##          <--- /Users/username/Sites/dev/project1/public/
    ##   http://subdomainswork.project2.dev/
    ##          <--- /Users/username/Sites/dev/SubDomainsWork.Project2/public/
    ##
    ##  The code here is a summarized version of the instructions and comments in a 
    ##  blog entry by Jason Johnoson of postpostmodern.com, originally posted here:
    ##
    ##     http://postpostmodern.com/instructional/a-smarter-mamp/ 
    ##
    
    
    E_BADARGS=85
    if [ -z "$1" ]
    then
      echo "Usage: `basename $0` tld"
      exit $E_BADARGS
    fi
    
    # edit the following as desired, if running this by hand
    USERNAME=`whoami`
    TLD=$1
    
    # The file needs to be ran as your regular Mac OS X user, not root.
    if [[ `whoami` = "root" ]] 
    then
     echo "Please execute this script as an admin user, do not use the sudo command."
     echo "Usage: `basename $0` tld"
     exit 0
    fi
    
    
    
    ############################
    ##   BIND Configurations  ##
    ############################
    
    # Create a custom launch key for BIND
    if [ ! -e /etc/rndc.conf ]
    then 
      echo "Creating RNDC"
      sudo rndc-confgen > /etc/rndc.conf
      sudo head -n 6 /etc/rndc.conf > /etc/rndc.key
    fi
    
    
    if [ ! -e /var/named/$TLD.zone ]
    then
      # Add the top level domain to BIND.
      echo "Adding TLD '$TLD' to BIND"
      sudo chmod 777 /etc/named.conf
      cat >> /etc/named.conf <<END
    zone "$TLD" IN {
      type master;
      file "$TLD.zone";
    };
    END
      # Create the Zone file for BIND
      echo "Creating zone file for $TLD (/var/named/$TLD.zone)"
      sudo chmod 644 /etc/named.conf
      sudo touch /var/named/$TLD.zone
      sudo chmod 777 /var/named/$TLD.zone
      cat > /var/named/$TLD.zone <<END
    ;
    ; BIND data file for $TLD sites
    ;
    \$TTL    604800
    @       IN      SOA     $TLD. root.$TLD. (
                         2008101920         ; Serial
                             604800         ; Refresh
                              86400         ; Retry
                            2419200         ; Expire
                             604800 )       ; Negative Cache TTL
    ;
    @       IN      NS      $TLD.
    @       IN      A       127.0.0.1
    *.$TLD.  14400   IN      A       127.0.0.1
    END
    fi
      sudo chmod 644 /var/named/$TLD.zone
    
    # Allow named daemon to be launched on boot. 
    if [[ `sudo defaults read /System/Library/LaunchDaemons/org.isc.named Disabled` = 1 ]]
    then 
      echo "Configuring BIND LaunchDaemon"
      # Unfortunately this will convert the plist from XML to binary format! 
      sudo defaults write /System/Library/LaunchDaemons/org.isc.named Disabled -boolean true
      # here's an alternate  that maintains the file in human-readable text format.
      # sed -n 5,6s/<true/<false/  /System/Library/LaunchDaemons/org.isc.named.plist
    fi
    # Load/Reload BIND
    sudo launchctl load /System/Library/LaunchDaemons/org.isc.named.plist
    
    
    ###############################
    ##  Bonjour Configurations   ##
    ###############################
    
    
    if [ ! -e /etc/resolver/$TLD ]
    then
      echo "Creating top level domain entry in Bonjour for '$TLD'"
      if [ ! -d /etc/resolver ] ; then sudo mkdir /etc/resolver ; fi
      # Enable Bonjour to serve your top level domain when you aren't connected to the internet
      sudo chmod 777 /etc/resolver
      cat > /etc/resolver/$TLD <<END
    domain $TLD
    nameserver 127.0.0.1
    END
    fi
      sudo chmod 755 /etc/resolver
      
    ###############################
    ##  TLD VirtualHost Folder   ##
    ###############################
    
    if [ ! -e "/Users/$USERNAME/Sites/$TLD" ]
    then
       echo "Creating ~/Sites/$TLD folder for user $USERNAME"
       mkdir -p "/Users/$USERNAME/Sites/$TLD"
    else
       echo "~/Sites/$TLD exists."
    fi
    
    ###############################
    ##  Apache Configurations    ##
    ###############################
    
    # create a new apache configuration for your user.
    echo "Updating Apache config /etc/apache2/users/$USERNAME.conf for NameVirtualHost mode."
    sudo mv /etc/apache2/users/$USERNAME.conf /etc/apache2/users/$USERNAME.conf.`date "+%Y%m%d%H%M%S"`
    sudo chmod 777 /etc/apache2/users
    cat > /etc/apache2/users/$USERNAME.conf <<END
    DocumentRoot /Users/$USERNAME/Sites
    <Directory "/Users/$USERNAME/Sites/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    NameVirtualHost 127.0.0.1
    <VirtualHost 127.0.0.1>
        VirtualDocumentRoot /Users/$USERNAME/Sites/%-1/%-2+/public
    </VirtualHost>
    END
    sudo chmod 755 /etc/apache2/users
    
    # restart apache, You may wan to check in the Console.app for any apache errors.
    echo "Restarting Apache."
    sudo apachectl restart
    
    
    # Dont forget to add 127.0.0.1 to the list of DNS servers in System Preferences  (see above).
    # You'll also need to add probably some other DNS entries as well. I recommend OpenDNS.
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Nov 09, 2009 at 2:56 a.m. EST
  • rsync over ssh
    rsync -e ssh -av username@server.example.com:remote_directory local_directory
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Nov 08, 2009 at 5:27 p.m. EST
  • top twenty processes by memory
    ps -eo pmem,pcpu,rss,vsize,args | sort -k 1 -r | head -21
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Oct 13, 2009 at 2:49 p.m. EDT
  • ultimate bash find and replace with sed
    for i in $(find . -type f); do sed 's/oldstring/newstring/g' $i > $i-tmp; mv $i $i-backup; mv $i-tmp $i; done
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jul 01, 2009 at 12:42 a.m. EDT
  • svn relocate
    # Subversion Management
    # relocate a working copy to a new repository URL
    
    cd /path/to/working-copy
    svn switch --relocate http://original.com/repo  http://new.com/repo .
    
    # relocate a working copy to a new repository location, and
    # change the cached username associated with the working copy
    
    cd /path/to/working-copy 
    svn switch --username newuser --password newpass --relocate  http://original.com/repo  http://new.com/repo .
    
    # NOTE: dont forget the period "." at the end, signifying current working directory.
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on May 16, 2009 at 7:51 p.m. EDT
  • Warehouse permission settings on Dreamhost
    # in the Warehouse settings page:
    #  Shell command to run when permissions are updated:
    
    rake warehouse:build_config REPO=:subdomain CONFIG=config/:subdomain.access
    
    # Note 1:  the above works for both the :path URL method
    #   (eg http://wh.example.com/reponame/)  
    # as well as the :subdomain URL method 
    #   (eg http://reponame.wh.example.com/)
    #
    # During WH setup, you should create a symlink to the .access file created 
    # by the Dreamhost panel for each repo you want to control with Warehouse.
    
    cd /your_web_app_directory/config
    ln -s /home/username/svn/reponame.access
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on May 15, 2009 at 11:30 a.m. EDT
  • restart a Rails Web Application on DreamHost.
    # restart a Rails Web Application on DreamHost. this requires that you've 
    # enabled mod_rails (Passenger) support for the app in the DreamHost panel
    
    $ touch /your_web_app_directory/tmp/restart.txt
    
    # Passenger looks for a file tmp/restart.txt and if it exists, it reloads 
    # your app, and refreshes all your files then deletes the tmp/restart.txt file
    
    # The other way to force a restart is through the dreamhost panel:
    # Domains > Manage Domains > Edit your-app.domain.com 
    #  >> submit the form through the "fully host this application" button.
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on May 15, 2009 at 11:20 a.m. EDT
  • 403 Forbidden error apache mac os x
    #  To avoid the 403 Forbidden error when browsing sites in your ~/Sites folder
    #  add the apache user "_www" to the staff group... 
    #  Note: sometimes staff may be admin if you're upgrading from earlier OS X
    #
    #  Solution for OS X Leopard's dscl tool (Directory Service Command Line)
    sudo dscl . -append /Groups/staff GroupMembership "_www"
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Mar 03, 2009 at 4:38 p.m. EST
  • wma2mp3
    #!/bin/bash
    
    #
    # script requires mplayer and lame!
    #
    
    for i in *.wma do mplayer -ao pcm -aofile "${i%.wma}.wav" "$i" && lame --preset hifi "${i%.wma}.wav" "${i%.wma}.mp3"
    rm "${i%.wma}.wav"
    done
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Feb 19, 2009 at 12:01 p.m. EST
Sign up to create your own snipts, or login.