echo "${1##*/}"
}
+function touch() {
+ local file=${1}
+
+ : > ${file}
+}
+
function enabled() {
local param=${1}
}
function mac_generate() {
- local mac=()
+ # Get a bunch of random hex digits
+ # and remove all dashes from the input.
+ local random=$(</proc/sys/kernel/random/uuid)
+ random=${random//-/}
+ assert isset random
+
+ local output
+
+ local i o
for i in $(seq 0 5); do
- mac[i]="$(uuid)"
- mac[i]="0x${mac[i]:0:2}"
- done
+ o="0x${random:0:2}"
+ random="${random:2:${#random}}"
- # Remove multicast bit
- # and set address is software assigned
- # XXX must doublecheck if this works
- mac[0]=$((mac[0] & 0xfe))
- mac[0]=$((mac[0] | 0x02))
+ case "${i}" in
+ 0)
+ # Remove multicast bit
+ # and set address is software assigned
+ o=$(( ${o} & 0xfe ))
+ o=$(( ${o} | 0x02 ))
- local output
- for i in ${mac[*]}; do
- if [ -n "${output}" ]; then
- output="${output}:"
- fi
-
- output="${output}$(printf "%02x" ${i})"
+ printf -v output "%02x" "${o}"
+ ;;
+ *)
+ printf -v output "%s:%02x" "${output}" "${o}"
+ ;;
+ esac
done
# Check if output is valid
assert mac_is_valid ${output}
- echo ${output}
+ echo "${output}"
}
function mac_format() {