Permalink
Browse files

FL-34: mdev, simplify ebuild, remove old versions

  • Loading branch information...
1 parent e06ca4f commit a0ba42173fb54dafa1bba096bdcf8659cb9cb75e @angryvincent angryvincent committed Jul 31, 2013
View
12 sys-fs/mdev-bb/files/mdev/catch-all
@@ -0,0 +1,12 @@
+#!/bin/sh
+# A catch-all script which will be executed for all not-configured devices in /etc/mdev.conf
+
+umask 022
+
+# Log unknown event so we can debug it later.
+# We hit this part of script if nothing above matched.
+exit
+exec >>/run/mdev.log
+exec 2>&1
+env
+echo '---'
View
33 sys-fs/mdev-bb/files/mdev/proc-bus-usb
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+umask 022
+
+case "${ACTION}" in
+ 'add')
+ [ "${BUSNUM}" ] || return 1
+ [ "${DEVNUM}" ] || return 1
+ [ "${MAJOR}" ] || return 1
+ [ "${MINOR}" ] || return 1
+ mkdir -p "/dev/bus/usb/${BUSNUM}"
+ [ "/dev/${MDEV}" != "/dev/bus/usb/${BUSNUM}/${DEVNUM}" ] && mv "/dev/${MDEV}" "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
+ [ "${DEVPATH}" ] || return 1
+ # Catch most of the Android Phones.
+ if [ -f "/sys/${DEVPATH}/product" ]; then
+ idVendor="$(cat /sys/${DEVPATH}/idVendor)"
+ case "${idVendor}" in
+ '0bb4'|'18d1'|'22b8'|'0fce'|'19d2'|'04e8')
+ chgrp 'plugdev' "/dev/bus/usb/${BUSNUM}/${DEVNUM}" 2>/dev/null && chmod 660 "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
+ ;;
+ esac
+ fi
+ ;;
+ 'remove')
+ [ "${BUSNUM}" ] || return 1
+ [ "${DEVNUM}" ] || return 1
+ [ "${MAJOR}" ] || return 1
+ [ "${MINOR}" ] || return 1
+ rm "/dev/bus/usb/${BUSNUM}/${DEVNUM}"
+ rmdir "/dev/bus/usb/${BUSNUM}" 2>/dev/null
+ rmdir "/dev/bus/usb" 2>/dev/null
+ ;;
+esac
View
171 sys-fs/mdev-bb/files/mdev/settle-nics
@@ -0,0 +1,171 @@
+#!/bin/sh
+# Copyright (c) 2012, Piotr Karbowski <piotr.karbowski@gmail.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this list
+# of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+# * Neither the name of the Piotr Karbowski nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# This script suppose to preserve interfaces names.
+# First it will run nameif to rename interfaces if configured in /etc/mactab
+# Then it will dump known interfaces to new mactab file.
+# Next it will parse old /etc/mactab and copy all interfaces which wasnt added in step two.
+# On the end, it will replace /etc/mactab with the new one.
+
+# Info: Step two will only care about eth*, wlan*, ath*, wifi* and ra* interfaces.
+
+umask 077
+
+if [ -n "${USER}" ] && [ "${USER}" != 'root' ]; then
+ echo "You need root to run it." >&2
+ exit 1
+fi
+
+in_comma_list() {
+ # Check whatever $1 is in the comma separated list $2.
+ local x
+ local check_for="$1"
+ case ",$2," in
+ *,"${check_for}",*)
+ return 0
+ ;;
+ esac
+ return 1
+}
+
+lockfile='/etc/mactab.settle-nics_lockfile'
+while : ; do
+ if ! test -f "${lockfile}" && ( set -o noclobber; echo "$$" > "${lockfile}") 2> /dev/null; then
+ break
+ else
+ sleep 1
+ fi
+done
+
+case "$1" in
+ --write-mactab)
+ write_mactab='true'
+ tmpfile="/etc/mactab.settle-nics_tmpfile.$$"
+ rm -f "${tmpfile}"
+ ;;
+ '')
+ tmpfile='/dev/null'
+ ;;
+ *)
+ echo "Wrong argument!" >&2
+ exit 1
+ ;;
+
+esac
+
+trap 'status="$?"; rm -f "${lockfile}"; test -f "${tmpfile}" && rm -f "${tmpfile}"; exit "${status}"' INT TERM EXIT
+
+# If we do have configured nics but the configured names are already used by something else, rename it to temp name.
+# I wish nameif or ifrename could be smart enough to do it itself...
+inconf_nics=""
+inconf_macs=""
+if [ -f '/etc/mactab' ]; then
+ while read nic macaddr _; do
+ case "${nic}" in
+ '#'*)
+ ;;
+ *)
+ inconf_nics="${inconf_nics},${nic}"
+ inconf_macs="${inconf_macs},${macaddr}"
+ if [ -e "/sys/class/net/${nic}" ]; then
+ curr_macaddr="$(cat /sys/class/net/${nic}/address)"
+ if [ "${curr_macaddr}" != "${macaddr}" ]; then
+ # Okey, so kernel added another NIC with name which we preserved for other NIC.
+ echo "Looks like '${nic}' is preserved. renaming current '${nic}' to '${nic}_tmp' ..." >&2
+ ip link set dev "${nic}" name "${nic}_tmp"
+ fi
+ fi
+ ;;
+ esac
+ done < '/etc/mactab'
+fi
+
+# Run nameif so all interfaces will be renamed to specified names.
+if command -v nameif >/dev/null 2>&1 && test -f /etc/mactab; then
+ nameif
+fi
+
+# Arrr rite. by now nemaif should put nics in right order, if there is still any *_tmp nic, we shall assign proper, free device name to it.
+for nic in /sys/class/net/*_tmp; do
+ nic="${nic##*/}"
+ if [ "${nic}" = '*_tmp' ]; then break; fi
+ nic_basename="${nic%%_tmp}"
+ nic_basename="${nic_basename%%[0-9]*}"
+ i=0
+ while [ "${i}" -le "128" ]; do
+ if ! [ -e "/sys/class/net/${nic_basename}${i}" ] && ! in_comma_list "${nic_basename}${i}" "${inconf_nics}"; then
+ echo "Renaming '${nic}' to '${nic_basename}${i}' ..." >&2
+ ip link set dev "${nic}" name "${nic_basename}${i}"
+ break
+ fi
+ i="$(($i+1))"
+ done
+done
+
+if [ "${write_mactab}" != 'true' ]; then
+ # We don't want write mactab thus there is no reason to check the network interfaces' mac addresses and so on...
+ exit 0
+fi
+
+printf '%s\n' "# Generated by settle-nics from mdev-like-a-boss." >> "${tmpfile}"
+
+# First get all the macs of current accessable nics
+detected_nics=""
+detected_macs=""
+for i in /sys/class/net/*; do
+ unset device macaddr
+ device="${i##*/}"
+ case "${device}" in
+ *_tmp)
+ ;;
+ eth[0-9]*|wlan[0-9]*|ath[0-9]*|wifi[0-9]*|ra[0-9]*)
+ macaddr="$(cat /sys/class/net/${device}/address 2>/dev/null)"
+ if [ -n "${macaddr}" ] && ! in_comma_list "${macaddr}" "${inconf_macs}" && ! in_comma_list "${device}" "${inconf_nics}"; then
+ detected_nics="${detected_nics},${device}"
+ detected_macs="${detected_macs},${macaddr}"
+ printf '%-15s %s\n' "${device}" "${macaddr}" >> "${tmpfile}"
+ fi
+ ;;
+ esac
+done
+
+# Now lets parse current /etc/mactab so we no loose any configured but not available at this moment interface.
+if [ -f '/etc/mactab' ]; then
+ unset device macaddr
+ while read device macaddr; do
+ case "${device}" in
+ '#'*)
+ ;;
+ *)
+ if [ -n "${macaddr}" ] && ! in_comma_list "${macaddr}" "${detected_macs}" && ! in_comma_list "${device}" "${detected_nics}"; then
+ printf '%-15s %s\n' "${device}" "${macaddr}" >> "${tmpfile}"
+ fi
+ ;;
+ esac
+ done < '/etc/mactab'
+fi
+
+mv "${tmpfile}" '/etc/mactab'
View
103 sys-fs/mdev-bb/files/mdev/storage-device
@@ -0,0 +1,103 @@
+#!/bin/sh
+# Copyright (c) 2012, Piotr Karbowski <piotr.karbowski@gmail.com>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this list
+# of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+# * Neither the name of the Piotr Karbowski nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE US
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# This script meant to create /dev/disk/by-* and /dev/mapper/* symlinks.
+# and remove them after storage device is removed.
+# the /dev/disk/by-* handling based on the idea and proof of concept from BitJam.
+
+# debug
+#exec >> /run/debug-mdev 2>&1
+#set -x
+#echo '### ENV:'
+#env
+#echo '### CODE:'
+#
+
+umask 077
+
+storage_dir="/dev/.mdev"
+[ -d "${storage_dir}" ] || mkdir "${storage_dir}"
+
+[ "${MDEV}" ] || exit 2
+
+create_uuid_label_symlink() {
+ local target_dir="/dev/disk/by-${1}"
+ local target_symlink="${target_dir}/${2}"
+ [ -e "${target_symlink}" ] && return
+ mkdir -p "${target_dir}"
+ ln -s "/dev/${MDEV}" "${target_symlink}"
+ echo "${target_symlink}" >"${storage_dir}/storage_symlink_${1}_${MDEV}"
+}
+
+add_symlinks() {
+ if command -v blkid >/dev/null 2>&1; then
+ local field name value UUID LABEL TYPE PTTYPE PARTLABEL PARTUUID
+ local blkid_output="$(blkid "/dev/${MDEV}")"
+ eval "${blkid_output#*: }"
+
+ [ "${UUID}" ] && create_uuid_label_symlink 'uuid' "${UUID}"
+ [ "${LABEL}" ] && create_uuid_label_symlink 'label' "${LABEL}"
+ fi
+
+ if [ -f "/sys/block/${MDEV}/dm/name" ]; then
+ [ -d '/dev/mapper' ] || mkdir '/dev/mapper'
+ if ! [ -c '/dev/mapper/control' ]; then
+ awk '$2 == "device-mapper" { foo = system("mknod /dev/mapper/control c 10 " $1); exit foo }' /proc/misc || exit 1
+ fi
+ local dmname="$(cat "/sys/block/${MDEV}/dm/name")"
+ if [ "${dmname}" ]; then
+ local target_symlink="/dev/mapper/${dmname}"
+ [ -e "${target_symlink}" ] && return
+ ln -s "/dev/${MDEV}" "${target_symlink}"
+ echo "${target_symlink}" >"${storage_dir}/storage_symlink_mapper_${MDEV}"
+ fi
+ fi
+}
+
+drop_symlinks() {
+ local type
+ for type in uuid label mapper; do
+ [ -f "${storage_dir}/storage_symlink_${type}_${MDEV}" ] || continue
+ local target_symlink="$(cat "${storage_dir}/storage_symlink_${type}_${MDEV}" 2>/dev/null)"
+ [ "${target_symlink}" ] || continue
+
+ local target_symlink_device="$(readlink "${target_symlink}")"
+ if [ "${target_symlink_device}" = "/dev/${MDEV}" ]; then
+ rm "${target_symlink}"
+ fi
+ rm "${storage_dir}/storage_symlink_${type}_${MDEV}"
+ done
+}
+
+case "${ACTION}" in
+ 'add'|'')
+ add_symlinks
+ ;;
+ 'remove')
+ drop_symlinks
+ ;;
+esac
+
View
92 sys-fs/mdev-bb/mdev-bb-1.20.2.ebuild
@@ -1,92 +0,0 @@
-EAPI="4"
-inherit eutils flag-o-matic toolchain-funcs multilib
-
-DESCRIPTION="mdev from busybox."
-HOMEPAGE="http://www.busybox.net/"
-
-base='busybox'
-MY_P=${base}-${PV/_/-}
-
-SRC_URI="http://www.busybox.net/downloads/${MY_P}.tar.bz2"
-KEYWORDS="~*"
-
-LICENSE="GPL-2"
-SLOT="0"
-IUSE="static"
-RESTRICT="test"
-
-DEPEND=">=sys-kernel/linux-headers-2.6.39"
-
-RDEPEND="!sys-apps/busybox[mdev]"
-
-S=${WORKDIR}/${MY_P}
-QA_PRESTRIPPED="/sbin/mdev"
-
-src_configure() {
- cat >"${S}/tmp.config" <<-END_OF_CONFIG
- CONFIG_HAVE_DOT_CONFIG=y
- CONFIG_USE_PORTABLE_CODE=y
- CONFIG_PLATFORM_LINUX=y
- CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
- CONFIG_SHOW_USAGE=y
- CONFIG_FEATURE_VERBOSE_USAGE=y
- CONFIG_FEATURE_COMPRESS_USAGE=y
- CONFIG_UNICODE_SUPPORT=y
- CONFIG_FEATURE_CHECK_UNICODE_IN_ENV=y
- CONFIG_UNICODE_COMBINING_WCHARS=y
- CONFIG_UNICODE_WIDE_WCHARS=y
- CONFIG_LONG_OPTS=y
- CONFIG_FEATURE_DEVPTS=y
- CONFIG_LFS=y
- CONFIG_NO_DEBUG_LIB=y
- CONFIG_INSTALL_APPLET_SYMLINKS=y
- CONFIG_MDEV=y
- CONFIG_FEATURE_MDEV_CONF=y
- CONFIG_FEATURE_MDEV_RENAME=y
- CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
- CONFIG_FEATURE_MDEV_EXEC=y
- CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
- CONFIG_FEATURE_SH_IS_NONE=y
- CONFIG_FEATURE_BASH_IS_NONE=y"
-END_OF_CONFIG
-
- if use static; then
- echo 'CONFIG_STATIC=y' >> "${S}/tmp.config"
- fi
-
- # Landley's miniconfig. <3
- make KCONFIG_ALLCONFIG='tmp.config' allnoconfig >/dev/null 2>&1
-}
-
-src_install() {
- mkdir "${D}/sbin" || die
- cp busybox "${D}/sbin/mdev" || die
- chmod 750 "${D}/sbin/mdev" || die
- mkdir -p "${D}/etc"
- cp -a "${FILESDIR}"/mdev.conf "${D}/etc" || die
- dodir /etc/mdev
- exeinto /etc/mdev
- doexe "${FILESDIR}"/catch-all || die
- doexe "${FILESDIR}"/settle-nics || die
- doexe "${FILESDIR}"/storage-device || die
- doexe "${FILESDIR}"/proc-bus-usb || die
- newinitd "${FILESDIR}"/mdev.init mdev || die
-}
-add_init() {
- local runl=$1
- if [ ! -e ${ROOT}/etc/runlevels/${runl} ]
- then
- install -d -m0755 ${ROOT}/etc/runlevels/${runl}
- fi
- for initd in $*
- do
- # if the initscript is not going to be installed and is not currently installed, return
- [[ -e ${D}/etc/init.d/${initd} || -e ${ROOT}/etc/init.d/${initd} ]] || continue
- [[ -e ${ROOT}/etc/runlevels/${runl}/${initd} ]] && continue
- elog "Auto-adding '${initd}' service to your ${runl} runlevel"
- ln -snf /etc/init.d/${initd} "${ROOT}"/etc/runlevels/${runl}/${initd}
- done
-}
-pkg_postinst() {
- add_init sysinit mdev
-}
View
96 sys-fs/mdev-bb/mdev-bb-1.21.0.ebuild
@@ -1,96 +0,0 @@
-EAPI="4"
-inherit eutils flag-o-matic toolchain-funcs multilib
-
-DESCRIPTION="mdev from busybox."
-HOMEPAGE="http://www.busybox.net/"
-
-base='busybox'
-MY_P=${base}-${PV/_/-}
-
-SRC_URI="http://www.busybox.net/downloads/${MY_P}.tar.bz2"
-KEYWORDS="~*"
-
-LICENSE="GPL-2"
-SLOT="0"
-IUSE="static"
-RESTRICT="test"
-
-DEPEND=">=sys-kernel/linux-headers-2.6.39"
-
-RDEPEND="!sys-apps/busybox[mdev]"
-
-S=${WORKDIR}/${MY_P}
-QA_PRESTRIPPED="/sbin/mdev"
-
-src_prepare(){
- epatch "${FILESDIR}/busybox-1.21.0-mdev.patch"
-}
-
-src_configure() {
- cat >"${S}/tmp.config" <<-END_OF_CONFIG
- CONFIG_HAVE_DOT_CONFIG=y
- CONFIG_USE_PORTABLE_CODE=y
- CONFIG_PLATFORM_LINUX=y
- CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
- CONFIG_SHOW_USAGE=y
- CONFIG_FEATURE_VERBOSE_USAGE=y
- CONFIG_FEATURE_COMPRESS_USAGE=y
- CONFIG_UNICODE_SUPPORT=y
- CONFIG_FEATURE_CHECK_UNICODE_IN_ENV=y
- CONFIG_UNICODE_COMBINING_WCHARS=y
- CONFIG_UNICODE_WIDE_WCHARS=y
- CONFIG_LONG_OPTS=y
- CONFIG_FEATURE_DEVPTS=y
- CONFIG_LFS=y
- CONFIG_NO_DEBUG_LIB=y
- CONFIG_INSTALL_APPLET_SYMLINKS=y
- CONFIG_MDEV=y
- CONFIG_FEATURE_MDEV_CONF=y
- CONFIG_FEATURE_MDEV_RENAME=y
- CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
- CONFIG_FEATURE_MDEV_EXEC=y
- CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
- CONFIG_FEATURE_SH_IS_NONE=y
- CONFIG_FEATURE_BASH_IS_NONE=y"
-END_OF_CONFIG
-
- if use static; then
- echo 'CONFIG_STATIC=y' >> "${S}/tmp.config"
- fi
-
- # Landley's miniconfig. <3
- make KCONFIG_ALLCONFIG='tmp.config' allnoconfig >/dev/null 2>&1
-}
-
-src_install() {
- mkdir "${D}/sbin" || die
- cp busybox "${D}/sbin/mdev" || die
- chmod 750 "${D}/sbin/mdev" || die
- mkdir -p "${D}/etc"
- cp -a "${FILESDIR}"/mdev.conf "${D}/etc" || die
- dodir /etc/mdev
- exeinto /etc/mdev
- doexe "${FILESDIR}"/catch-all || die
- doexe "${FILESDIR}"/settle-nics || die
- doexe "${FILESDIR}"/storage-device || die
- doexe "${FILESDIR}"/proc-bus-usb || die
- newinitd "${FILESDIR}"/mdev.init mdev || die
-}
-add_init() {
- local runl=$1
- if [ ! -e ${ROOT}/etc/runlevels/${runl} ]
- then
- install -d -m0755 ${ROOT}/etc/runlevels/${runl}
- fi
- for initd in $*
- do
- # if the initscript is not going to be installed and is not currently installed, return
- [[ -e ${D}/etc/init.d/${initd} || -e ${ROOT}/etc/init.d/${initd} ]] || continue
- [[ -e ${ROOT}/etc/runlevels/${runl}/${initd} ]] && continue
- elog "Auto-adding '${initd}' service to your ${runl} runlevel"
- ln -snf /etc/init.d/${initd} "${ROOT}"/etc/runlevels/${runl}/${initd}
- done
-}
-pkg_postinst() {
- add_init sysinit mdev
-}
View
5 sys-fs/mdev-bb/mdev-bb-1.21.1.ebuild
@@ -66,10 +66,7 @@ src_install() {
cp -a "${FILESDIR}"/mdev.conf "${D}/etc" || die
dodir /etc/mdev
exeinto /etc/mdev
- doexe "${FILESDIR}"/catch-all || die
- doexe "${FILESDIR}"/settle-nics || die
- doexe "${FILESDIR}"/storage-device || die
- doexe "${FILESDIR}"/proc-bus-usb || die
+ doexe "${FILESDIR}"/mdev/* || die
newinitd "${FILESDIR}"/mdev.init mdev || die
}
add_init() {

0 comments on commit a0ba421

Please sign in to comment.