slitaz-vz rev 1

Add contribs scripts for OpenVZ
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Tue Nov 01 09:21:58 2011 +0100 (2011-11-01)
parents fb08988f020c
children 2d20f72ffb19
files vz-contribs/easymac.sh
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/vz-contribs/easymac.sh	Tue Nov 01 09:21:58 2011 +0100
     1.3 @@ -0,0 +1,206 @@
     1.4 +#!/bin/sh
     1.5 +# Script for generating VMware MAC Addresses
     1.6 +# http://www.easyvmx.com
     1.7 +#
     1.8 +# Works on any *NIX system with standard Bourne Shell and /dev/urandom
     1.9 +#
    1.10 +# Freely distributable under the BSD license:
    1.11 +#
    1.12 +# ------------- Start licence --------------
    1.13 +# Copyright (c) 2006, http://www.easyvmx.com
    1.14 +# All rights reserved.
    1.15 +#
    1.16 +# Redistribution and use in source and binary forms, with or without
    1.17 +# modification, are permitted provided that the following conditions are met:
    1.18 +#
    1.19 +# Redistributions of source code must retain the above copyright notice,
    1.20 +# this list of conditions and the following disclaimer.
    1.21 +#
    1.22 +# Redistributions in binary form must reproduce the above copyright notice,
    1.23 +# this list of conditions and the following disclaimer in the documentation
    1.24 +# and/or other materials provided with the distribution.
    1.25 +#
    1.26 +# Neither the name of the <ORGANIZATION> nor the names of its contributors
    1.27 +# may be used to endorse or promote products derived from this software without
    1.28 +# specific prior written permission.
    1.29 +#
    1.30 +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.31 +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    1.32 +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.33 +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.34 +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.35 +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.36 +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.37 +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.38 +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.39 +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.40 +# POSSIBILITY OF SUCH DAMAGE.
    1.41 +# ------------- End licence --------------
    1.42 +#
    1.43 +# Changelog
    1.44 +# ---------
    1.45 +# 2006-11-06:
    1.46 +#	Version 1.0, first release of EasyMAC!
    1.47 +#
    1.48 +# 2007-07-20:
    1.49 +#	Version 1.1:
    1.50 +#		Added option for _any_ MAC address, not only VMware addresses.
    1.51 +#		Changed output for static/random MAC address. It now tells that these are VMware MAC adresses.
    1.52 +#
    1.53 +# 2008-10-08:
    1.54 +#	Version 1.2:
    1.55 +#		Added option for XenSource MAC address creation.
    1.56 +#		You can now output MAC address only, without the leading text.
    1.57 +#
    1.58 +# 2009-04-08:
    1.59 +#	Version 1.3:
    1.60 +#		Changed the way XenSource MAC addresses are created.
    1.61 +
    1.62 +# 
    1.63 +# Version
    1.64 +#
    1.65 +
    1.66 +EMVersion=1.r3
    1.67 +ReleaseYear=2009
    1.68 +ReleaseDate=2009-04-08
    1.69 +
    1.70 +
    1.71 +#
    1.72 +# Functions
    1.73 +#
    1.74 +
    1.75 +# Random VMware MAC Address
    1.76 +vmrandom() {
    1.77 +	vmrandmac=$(dd if=/dev/urandom bs=1 count=3 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | awk '{ print "00:0c:29:"$1":"$2":"$3 }')
    1.78 +	echo $vmrandmac
    1.79 +}
    1.80 +
    1.81 +# Static VMware MAC Address
    1.82 +vmstatic() {
    1.83 +	max3f=$(printf "%02X" $(expr $(dd if=/dev/urandom bs=1 count=1 2>/dev/null | od -tu1 | head -1 | cut -d' ' -f2-) / 4) | tr A-Z a-z)
    1.84 +	vmstatmac=$(echo -n "00:50:56:$max3f:" $(dd if=/dev/urandom bs=1 count=2 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | awk '{ print $1":"$2 }') | sed 's/\ //')
    1.85 +	echo $vmstatmac
    1.86 +}
    1.87 +
    1.88 +# Global MAC Address (any valid MAC address, from the full range)
    1.89 +global() {
    1.90 +        globalmac=$(dd if=/dev/urandom bs=1 count=6 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | awk '{ print $1":"$2":"$3":"$4":"$5":"$6 }')
    1.91 +        echo $globalmac
    1.92 +}
    1.93 +
    1.94 +# XenSource MAC Address
    1.95 +xensource() {
    1.96 +	max3f=$(printf "%02X" $(expr $(dd if=/dev/urandom bs=1 count=1 2>/dev/null | od -tu1 | head -1 | cut -d' ' -f2-) / 4) | tr A-Z a-z)
    1.97 +	xensource=$(echo -n "00:50:56:$max3f:" $(dd if=/dev/urandom bs=1 count=2 2>/dev/null | od -tx1 | head -1 | cut -d' ' -f2- | awk '{ print $1":"$2 }') | sed 's/\ //')
    1.98 +	echo $xensource
    1.99 +}
   1.100 +
   1.101 +
   1.102 +#
   1.103 +# Process options
   1.104 +#
   1.105 +
   1.106 +case "$1" in
   1.107 +
   1.108 +	r|-r|random|-random)
   1.109 +		if [ "$2" != "-m" ]; then
   1.110 +			echo -n "Random VMware MAC Address: "
   1.111 +		fi
   1.112 +		vmrandom
   1.113 +		echo ""
   1.114 +		;;
   1.115 +
   1.116 +	R|-R|RANDOM|-RANDOM|Random|-Random)
   1.117 +		if [ "$2" != "-m" ]; then
   1.118 +			echo -n "Random VMware MAC Address: "
   1.119 +		fi
   1.120 +		vmrandom | tr a-z A-Z
   1.121 +		echo ""
   1.122 +		;;
   1.123 +
   1.124 +	s|-s|static|-static)
   1.125 +		if [ "$2" != "-m" ]; then
   1.126 +			echo -n "Static VMware MAC Address: "
   1.127 +		fi
   1.128 +		vmstatic
   1.129 +		echo ""
   1.130 +		;;
   1.131 +
   1.132 +	S|-S|STATIC|-STATIC|Static|-Static)
   1.133 +		if [ "$2" != "-m" ]; then
   1.134 +			echo -n "Static VMware MAC Address: "
   1.135 +		fi
   1.136 +		vmstatic | tr a-z A-Z
   1.137 +		echo ""
   1.138 +		;;
   1.139 +
   1.140 +	g|-g|global|-global)
   1.141 +		if [ "$2" != "-m" ]; then
   1.142 +			echo -n "Global MAC Address: "
   1.143 +		fi
   1.144 +		global
   1.145 +		echo ""
   1.146 +		;;
   1.147 +
   1.148 +	G|-G|GLOBAL|-GLOBAL|Global|-Global)
   1.149 +		if [ "$2" != "-m" ]; then
   1.150 +			echo -n "Global MAC Address: "
   1.151 +		fi
   1.152 +		global | tr a-z A-Z
   1.153 +		echo ""
   1.154 +		;;
   1.155 +
   1.156 +	x|-x|xen|-xen)
   1.157 +		if [ "$2" != "-m" ]; then
   1.158 +			echo -n "XenSource MAC Address: "
   1.159 +		fi
   1.160 +		xensource
   1.161 +		echo ""
   1.162 +		;;
   1.163 +
   1.164 +	X|-X|XEN|-XEN|Xen|-Xen)
   1.165 +		if [ "$2" != "-m" ]; then
   1.166 +			echo -n "XenSource MAC Address: "
   1.167 +		fi
   1.168 +		xensource | tr a-z A-Z
   1.169 +		echo ""
   1.170 +		;;
   1.171 +
   1.172 +	*)
   1.173 +		echo ""
   1.174 +		echo "EasyMAC! v. $EMVersion"
   1.175 +		echo "Generate hardware adresses for virtual machines"
   1.176 +		echo "Copyright (c) $ReleaseYear, http://www.easyvmx.com"
   1.177 +		echo ""
   1.178 +		echo "Usage: $0 {-r|-R|-s|-S|-x|-X|-g|-G} {-m}"
   1.179 +		echo ""
   1.180 +		echo "Options:"
   1.181 +		echo "   -r:	Random VMware MAC address, lower case"	
   1.182 +		echo "   -R:	Random VMware MAC address, UPPER CASE"	
   1.183 +		echo "   -s:	Static VMware MAC address, lower case"	
   1.184 +		echo "   -S:	Static VMware MAC address, UPPER CASE"	
   1.185 +		echo "   -x:	XenSource MAC address, lower case"	
   1.186 +		echo "   -X:	XenSource MAC address, UPPER CASE"	
   1.187 +		echo "   -g:	Global MAC address, lower case"
   1.188 +		echo "   -G:	Global MAC address, UPPER CASE"
   1.189 +		echo ""
   1.190 +		echo "   -m:	Add the -m option for MAC address only"
   1.191 +		echo ""
   1.192 +		echo "All valid options:"
   1.193 +		echo "   Random VMware Lower Case: 	{r|-r|random|-random}"
   1.194 +		echo "   Random VMware Upper Case: 	{R|-R|RANDOM|-RANDOM|Random|-Random}"
   1.195 +		echo "   Static VMware Lower Case: 	{s|-s|static|-static}"
   1.196 +		echo "   Static VMware Upper Case: 	{S|-S|STATIC|-STATIC|Static|-Static}"
   1.197 +		echo "   XenSource Lower Case: 	{x|-x|xen|-xen}"
   1.198 +		echo "   XenSource Upper Case: 	{X|-X|XEN|-XEN|Xen|-Xen}"
   1.199 +		echo "   Global MAC Lower case:	{g|-g|global|-global}"
   1.200 +		echo "   Global MAC Upper case:	{G|-G|GLOBAL|-GLOBAL|Global|-Global}"
   1.201 +		echo ""
   1.202 +		echo "Freely distributable under the BSD license"
   1.203 +		echo "Visit http://www.easyvmx.com for the best online virtual machine creator!"
   1.204 +		echo ""
   1.205 +		exit 1
   1.206 +
   1.207 +esac
   1.208 +
   1.209 +exit $?