slitaz-vz annotate vz-contribs/easymac.sh @ rev 6

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:27:32 2019 +0100 (2019-02-26)
parents
children
rev   line source
erjo@1 1 #!/bin/sh
erjo@1 2 # Script for generating VMware MAC Addresses
erjo@1 3 # http://www.easyvmx.com
erjo@1 4 #
erjo@1 5 # Works on any *NIX system with standard Bourne Shell and /dev/urandom
erjo@1 6 #
erjo@1 7 # Freely distributable under the BSD license:
erjo@1 8 #
erjo@1 9 # ------------- Start licence --------------
erjo@1 10 # Copyright (c) 2006, http://www.easyvmx.com
erjo@1 11 # All rights reserved.
erjo@1 12 #
erjo@1 13 # Redistribution and use in source and binary forms, with or without
erjo@1 14 # modification, are permitted provided that the following conditions are met:
erjo@1 15 #
erjo@1 16 # Redistributions of source code must retain the above copyright notice,
erjo@1 17 # this list of conditions and the following disclaimer.
erjo@1 18 #
erjo@1 19 # Redistributions in binary form must reproduce the above copyright notice,
erjo@1 20 # this list of conditions and the following disclaimer in the documentation
erjo@1 21 # and/or other materials provided with the distribution.
erjo@1 22 #
erjo@1 23 # Neither the name of the <ORGANIZATION> nor the names of its contributors
erjo@1 24 # may be used to endorse or promote products derived from this software without
erjo@1 25 # specific prior written permission.
erjo@1 26 #
erjo@1 27 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
erjo@1 28 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
erjo@1 29 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
erjo@1 30 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
erjo@1 31 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
erjo@1 32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
erjo@1 33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
erjo@1 34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
erjo@1 35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
erjo@1 36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
erjo@1 37 # POSSIBILITY OF SUCH DAMAGE.
erjo@1 38 # ------------- End licence --------------
erjo@1 39 #
erjo@1 40 # Changelog
erjo@1 41 # ---------
erjo@1 42 # 2006-11-06:
erjo@1 43 # Version 1.0, first release of EasyMAC!
erjo@1 44 #
erjo@1 45 # 2007-07-20:
erjo@1 46 # Version 1.1:
erjo@1 47 # Added option for _any_ MAC address, not only VMware addresses.
erjo@1 48 # Changed output for static/random MAC address. It now tells that these are VMware MAC adresses.
erjo@1 49 #
erjo@1 50 # 2008-10-08:
erjo@1 51 # Version 1.2:
erjo@1 52 # Added option for XenSource MAC address creation.
erjo@1 53 # You can now output MAC address only, without the leading text.
erjo@1 54 #
erjo@1 55 # 2009-04-08:
erjo@1 56 # Version 1.3:
erjo@1 57 # Changed the way XenSource MAC addresses are created.
erjo@1 58
erjo@1 59 #
erjo@1 60 # Version
erjo@1 61 #
erjo@1 62
erjo@1 63 EMVersion=1.r3
erjo@1 64 ReleaseYear=2009
erjo@1 65 ReleaseDate=2009-04-08
erjo@1 66
erjo@1 67
erjo@1 68 #
erjo@1 69 # Functions
erjo@1 70 #
erjo@1 71
erjo@1 72 # Random VMware MAC Address
erjo@1 73 vmrandom() {
erjo@1 74 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 }')
erjo@1 75 echo $vmrandmac
erjo@1 76 }
erjo@1 77
erjo@1 78 # Static VMware MAC Address
erjo@1 79 vmstatic() {
erjo@1 80 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)
erjo@1 81 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/\ //')
erjo@1 82 echo $vmstatmac
erjo@1 83 }
erjo@1 84
erjo@1 85 # Global MAC Address (any valid MAC address, from the full range)
erjo@1 86 global() {
erjo@1 87 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 }')
erjo@1 88 echo $globalmac
erjo@1 89 }
erjo@1 90
erjo@1 91 # XenSource MAC Address
erjo@1 92 xensource() {
erjo@1 93 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)
erjo@1 94 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/\ //')
erjo@1 95 echo $xensource
erjo@1 96 }
erjo@1 97
erjo@1 98
erjo@1 99 #
erjo@1 100 # Process options
erjo@1 101 #
erjo@1 102
erjo@1 103 case "$1" in
erjo@1 104
erjo@1 105 r|-r|random|-random)
erjo@1 106 if [ "$2" != "-m" ]; then
erjo@1 107 echo -n "Random VMware MAC Address: "
erjo@1 108 fi
erjo@1 109 vmrandom
erjo@1 110 echo ""
erjo@1 111 ;;
erjo@1 112
erjo@1 113 R|-R|RANDOM|-RANDOM|Random|-Random)
erjo@1 114 if [ "$2" != "-m" ]; then
erjo@1 115 echo -n "Random VMware MAC Address: "
erjo@1 116 fi
erjo@1 117 vmrandom | tr a-z A-Z
erjo@1 118 echo ""
erjo@1 119 ;;
erjo@1 120
erjo@1 121 s|-s|static|-static)
erjo@1 122 if [ "$2" != "-m" ]; then
erjo@1 123 echo -n "Static VMware MAC Address: "
erjo@1 124 fi
erjo@1 125 vmstatic
erjo@1 126 echo ""
erjo@1 127 ;;
erjo@1 128
erjo@1 129 S|-S|STATIC|-STATIC|Static|-Static)
erjo@1 130 if [ "$2" != "-m" ]; then
erjo@1 131 echo -n "Static VMware MAC Address: "
erjo@1 132 fi
erjo@1 133 vmstatic | tr a-z A-Z
erjo@1 134 echo ""
erjo@1 135 ;;
erjo@1 136
erjo@1 137 g|-g|global|-global)
erjo@1 138 if [ "$2" != "-m" ]; then
erjo@1 139 echo -n "Global MAC Address: "
erjo@1 140 fi
erjo@1 141 global
erjo@1 142 echo ""
erjo@1 143 ;;
erjo@1 144
erjo@1 145 G|-G|GLOBAL|-GLOBAL|Global|-Global)
erjo@1 146 if [ "$2" != "-m" ]; then
erjo@1 147 echo -n "Global MAC Address: "
erjo@1 148 fi
erjo@1 149 global | tr a-z A-Z
erjo@1 150 echo ""
erjo@1 151 ;;
erjo@1 152
erjo@1 153 x|-x|xen|-xen)
erjo@1 154 if [ "$2" != "-m" ]; then
erjo@1 155 echo -n "XenSource MAC Address: "
erjo@1 156 fi
erjo@1 157 xensource
erjo@1 158 echo ""
erjo@1 159 ;;
erjo@1 160
erjo@1 161 X|-X|XEN|-XEN|Xen|-Xen)
erjo@1 162 if [ "$2" != "-m" ]; then
erjo@1 163 echo -n "XenSource MAC Address: "
erjo@1 164 fi
erjo@1 165 xensource | tr a-z A-Z
erjo@1 166 echo ""
erjo@1 167 ;;
erjo@1 168
erjo@1 169 *)
erjo@1 170 echo ""
erjo@1 171 echo "EasyMAC! v. $EMVersion"
erjo@1 172 echo "Generate hardware adresses for virtual machines"
erjo@1 173 echo "Copyright (c) $ReleaseYear, http://www.easyvmx.com"
erjo@1 174 echo ""
erjo@1 175 echo "Usage: $0 {-r|-R|-s|-S|-x|-X|-g|-G} {-m}"
erjo@1 176 echo ""
erjo@1 177 echo "Options:"
erjo@1 178 echo " -r: Random VMware MAC address, lower case"
erjo@1 179 echo " -R: Random VMware MAC address, UPPER CASE"
erjo@1 180 echo " -s: Static VMware MAC address, lower case"
erjo@1 181 echo " -S: Static VMware MAC address, UPPER CASE"
erjo@1 182 echo " -x: XenSource MAC address, lower case"
erjo@1 183 echo " -X: XenSource MAC address, UPPER CASE"
erjo@1 184 echo " -g: Global MAC address, lower case"
erjo@1 185 echo " -G: Global MAC address, UPPER CASE"
erjo@1 186 echo ""
erjo@1 187 echo " -m: Add the -m option for MAC address only"
erjo@1 188 echo ""
erjo@1 189 echo "All valid options:"
erjo@1 190 echo " Random VMware Lower Case: {r|-r|random|-random}"
erjo@1 191 echo " Random VMware Upper Case: {R|-R|RANDOM|-RANDOM|Random|-Random}"
erjo@1 192 echo " Static VMware Lower Case: {s|-s|static|-static}"
erjo@1 193 echo " Static VMware Upper Case: {S|-S|STATIC|-STATIC|Static|-Static}"
erjo@1 194 echo " XenSource Lower Case: {x|-x|xen|-xen}"
erjo@1 195 echo " XenSource Upper Case: {X|-X|XEN|-XEN|Xen|-Xen}"
erjo@1 196 echo " Global MAC Lower case: {g|-g|global|-global}"
erjo@1 197 echo " Global MAC Upper case: {G|-G|GLOBAL|-GLOBAL|Global|-Global}"
erjo@1 198 echo ""
erjo@1 199 echo "Freely distributable under the BSD license"
erjo@1 200 echo "Visit http://www.easyvmx.com for the best online virtual machine creator!"
erjo@1 201 echo ""
erjo@1 202 exit 1
erjo@1 203
erjo@1 204 esac
erjo@1 205
erjo@1 206 exit $?