Skip to content

Instantly share code, notes, and snippets.

@brianoflan
brianoflan / subHome.sh
Last active December 16, 2016 17:39
For overriding $HOME, alt home, altHome (and link or copy in any necessary content from the real home)
#!/bin/bash
gemRubyMinorVer='2.2.0' ;
subHome() {
echo subHome ;
local home="/home/$(id -un)" ;
[[ -e "$home" ]] || home=$(grep $(id -un) /etc/passwd | awk -F: '{print $6}' | sed -e 's/[\/]$//') ;
[[ $home ]] || [[ ! -e /Users ]] || home="/Users/$(id -un)" ;
[[ $home ]] && [[ -e $home ]] || home='' ;
@brianoflan
brianoflan / iterateOverCFOrgsSpaces.sh
Last active June 19, 2023 18:14
How to iterate over all orgs and spaces on a Cloud Foundry endpoint (cf, cf routes, cf orgs, cf spaces, CloudFoundry)
#!/bin/bash
timeout=gtimeout
action() {
echo "cf_routes $1 $2" 1>&2 ;
local x=`cf_routes $1 $2 | egrep -v '^( *$|space *|name *|Getting routes|FAILED|No space targeted|No routes found)' | egrep '.' | perl -ne 'print " $_"'` ;
[[ -z $x ]] || echo -e " Found it:\n$x." ;
echo "" 1>&2 ;
}
main() {
@brianoflan
brianoflan / either_rvm_or_rbenv.sh
Last active December 16, 2016 18:04
To make sure either rvm or rbenv is set up well. (Pick a ruby version.)
#!/bin/bash
either_rvm_or_rbenv() {
[[ $useRubyVersion ]] || useRubyVersion='2.2.3' ;
local use_rvm_or_rbenv='' ;
[[ $use_rvm_or_rbenv ]] || { rvm -v &> /dev/null && use_rvm_or_rbenv='rvm' || true ; }
[[ $use_rvm_or_rbenv ]] || { rbenv -v &> /dev/null && use_rvm_or_rbenv='rbenv' || true ; }
if [[ rbenv == $use_rvm_or_rbenv ]] ; then
[[ -e $HOME/.rbenv/versions/$useRubyVersion ]] || rbenv install "$useRubyVersion" ;
@brianoflan
brianoflan / use_either_rvm_or_rbenv.sh
Last active December 16, 2016 18:03
Example of how to use the either_rvm_or_rbenv() function in BASH (rvm, rbenv, subhome)
#!/bin/bash
#Example of how to use the either_rvm_or_rbenv() function in BASH
useRubyVersion='2.2.3' ;
init() {
source ./subHome.sh ;
cd .. ;
subHome ;
either_rvm_or_rbenv ;
@brianoflan
brianoflan / BASH_script_alt2.sh
Last active December 16, 2016 18:03
basic BASH template (execute, vexecute, die)
#!/bin/bash
main() {
execute cd $HOME/w/ ;
vexecute false ;
execute echo sniffletart ;
}
# vexecute()
# Run the given command verbosely and with trailing newline;
@brianoflan
brianoflan / getProxy.sh
Last active December 16, 2016 18:02
iterate over all possible proxy vars (get_proxy, http_proxy, HTTP_PROXY, HttpProxy, but not https)
#!/bin/bash
get_proxy() {
[[ -n $http_proxy ]] && echo $http_proxy || {
[[ -n $HTTP_PROXY ]] && echo $HTTP_PROXY || {
[[ -n $HttpProxy ]] && echo $HttpProxy || {
return 1 ;
} ;
} ;
} ;
}
@brianoflan
brianoflan / puppet_mkdir_p.pp
Last active December 16, 2016 18:01
Puppet mkdir -p (file resource, recursive mkdir, inline_template, split, unless you need a comma in a folder name)
$file_dirs_s = inline_template('<%= @files.map{ |f| File.dirname(f) }.join(",") %>')
$file_dirs = split($file_dirs_s, ',')
file { $file_dirs:
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755'
}
@brianoflan
brianoflan / add_storage.sh
Last active December 16, 2016 18:01
add LVM storage (df -h, pvs, vgextend, lvextend, device, mount, volume group, logical volume)
#!/bin/bash
# For AWS EC2 CentOS boxes that use LVM and have storage volumes presented as /dev/xvd_ (where _ is a letter).
main() { # Args: device (like "c" for xvdc), size[GB], mount point (like /var or /some/folder), volume group, logical volume name.
local devPrefix=xvd ;
local dev=$1 ;
local gb=$2 ;
local fs_dir=$3 ;
local vg=$4 ;
local lv_name=$5 ;
@brianoflan
brianoflan / fix_certname.pp
Last active December 16, 2016 17:53
Fix certname in puppet.conf (augeas, networking, fqdn)
augeas { "puppet.conf certname":
lens => 'Puppet.lns',
incl => "/etc/puppetlabs/puppet/puppet.conf",
context => "/files/etc/puppetlabs/puppet/puppet.conf",
changes => [
"set main/certname ${::networking[fqdn]}",
],
}
@brianoflan
brianoflan / find_altlinks.sh
Last active December 16, 2016 17:49
find links that work with the /etc/alternatives system (usr)