1. 程式人生 > >openwrt編譯進階

openwrt編譯進階

摘要 這篇文章是Openwrt編譯的學習筆記包括(1)Openwrt基礎入門(2)Openwrt基礎進階(3)整合軟體

之前總喜歡在在寫文章之前寫一大段自己的光榮事蹟,後來發現看別人這樣寫的文章是一件很蛋疼的事,畢竟這是一篇技術類文章,不是小學生日記。
好吧,這次直接進入正題,抱歉,又寫了一段和本文內容無關的文字……
去年學校開始用H3C認證來限制我們上網,於是好奇心再次害死貓,本宮終於修成正果,誤入Openwrt這個大坑,折騰Openwrt有一年多了,到了回饋社會的時候了,這篇文章寫寫Openwrt編譯的一些高階配置(相對入門級編譯教程而言),以HG255D為例。

Openwrt基礎編譯

這類文章一手一大把,精簡的,詳細的(多半是廢話)都有,這裡就簡單的把一些指令寫下

編譯環境為Ubuntu
#升級元件包
sudo apt-get update
#安裝編譯需要的元件
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev git-core gawk asciidoc libz-dev sphinxsearch libtool sphinx-common libssl-dev libsqlite3* intltool libiconv* gstreamer-0.10
* glib2.0 libxml2-dev qemu (*64位系統需安裝ia32-libs) #使用非root使用者登入,建立openwrt目錄 mkdir openwrt #進入openwrt目錄 cd openwrt #下載openwrt原始碼 svn checkout svn://svn.openwrt.org/openwrt/trunk #賦予trunk目錄許可權 sudo chmod -R 777 trunk #進入trunk目錄 cd trunk #更新最新原始碼 ./scripts/feeds update -a #安裝最新原始碼 ./scripts/feeds install -a #更新版本號
svn up #進入編譯選單 make menuconfig Y:選擇Y,該軟體將被編譯,並且加入到你的目標韌體裡; M:選擇M,該軟體包將會被編譯,但不會被放入韌體裡。在需要它的時候,可以用OPKG軟體包管理器進行安裝; N:選擇N,該軟體包將不會被編譯,也不會被安裝進韌體。 方向鍵是移動游標 回車鍵是確認 空格鍵是選擇,可以代替Y/M/N鍵的使用 /:搜尋 #編譯 make V=99 #清除編譯過程產生的臨時檔案 make clean #恢復編譯環境 make defconfig

Openwrt編譯進階

其實按照上面的指令一路執行下來,你已經能夠在/bin/$target下找到刷機韌體了,是不是很簡單……

修改WIFI設定

package/kernel/mac80211/files/lib/wifi/mac80211.sh

config wifi-device  radio$devidx
    option type     mac80211
    option channel  11
    option hwmode    11ng
    option path    '10180000.wmac'
    option htmode    HT20
    list ht_capab    GF
    list ht_capab    SHORT-GI-20
    list ht_capab    SHORT-GI-40
    list ht_capab    TX-STBC
    list ht_capab    RX-STBC12
    # REMOVE THIS LINE TO ENABLE WIFI:
    option disabled 0
    option noscan 1
    option txpower 20
    option htmode HT40-

config wifi-iface
    option device   radio$devidx
    option network  lan
    option mode     ap
    #自定義SSID為MakeBlaze_MAC後六位
    option ssid     MakeBlaze_$(cat /sys/class/ieee80211/${dev}/macaddress|awk -F ":" '{print $4""$5""$6 }'| tr a-z A-Z) 
    option encryption none

修改LUCI

修改LUCI介面配置

feeds/luci/modules/base/root/etc/config/luci

config core main
    option resourcebase '/luci-static/resources'
    #設定預設語言
    option lang 'zh_cn'
    #設定預設主題
    option mediaurlbase '/luci-static/bootstrap'

#設定可選擇的語言        
config internal languages
    option zh_cn 'chinese'
    option en 'English'
#設定可選擇的主題
config internal themes
    option Bootstrap '/luci-static/bootstrap'

新增釋放記憶體

feeds/luci/modules/admin-full/luasrc/controller/admin/index.lua

function index()
+    entry({"admin", "Free_Memory"}, call("Free_Memory"), _("釋放記憶體"), 75)
end

function Free_Memory()
    luci.util.exec("echo 3 > /proc/sys/vm/drop_caches")
    luci.http.redirect(luci.dispatcher.build_url("admin", "status", "overview"))
end

在頂欄顯示重啟

feeds/luci/modules/admin-full/luasrc/controller/admin/system.lua

function index()
    entry({"admin", "reboot"}, call("action_reboot"), _("Reboot"), 90)
end

feeds/luci/modules/admin-full/luasrc/view/admin_system/reboot.htm

在頂欄顯示備份/升級

feeds/luci/modules/admin-full/luasrc/controller/admin/system.lua

function index()
    entry({"admin", "flashops"}, call("action_flashops"), _("Backup / Flash Firmware"), 70)
end

修改配置檔案

package/base-files/files/etc/
在這個目錄裡,你可以把你的備份的路由器匯入進來

修改root密碼

package/base-files/files/etc/shadow

#預設情況下root是沒有密碼的,需設定密碼才能開啟ssh
root:$1$wEehtjxj$YBu4quNfVUjzfv8p/PBo5.:0:0:99999:7:::

修改路由連線數

package/base-files/files/etc/sysctl.conf

net.netfilter.nf_conntrack_max=65535

修改主機名,設定時區

package/base-files/files/etc/config/system

config system
    #設定主機名
    option hostname 'MakeBlaze'
    option conloglevel '8'
    option cronloglevel '8'
    #設定時區
    option zonename 'Asia/Shanghai'
    option timezone 'CST-8'

#設定時間伺服器
config timeserver 'ntp'
    option enable_server '1'
    list server '210.72.145.44'
    list server 's1a.time.edu.cn'
    list server 's1b.time.edu.cn'
    list server '202.120.2.101'

config led 'usb_led'
    option name 'USB'
    option sysfs 'hg255d:usb'
    option trigger 'usbdev'
    option dev '1-1'
    option interval '50'

config led 'wlan_led'
    option name 'WLAN'
    option sysfs 'hg255d:wlan'
    option trigger 'netdev'
    option dev 'ra0'
    option mode 'link tx'

config led 'internet_led'
    option name 'INTERNET'
    option sysfs 'hg255d:internet'
    option trigger 'netdev'
    option dev 'eth0.2'
    option mode 'tx rx'

SAMBA免密碼訪問

package/base-files/files/etc/config/samba

config samba
    #顯示中文
    option charset 'gb2312'

config sambashare
    option read_only 'no'
    option guest_ok 'yes'
    option create_mask '0777'
    option dir_mask '0777'
    option display charset

package/base-files/files/etc/samba/smb.conf.template

[global]
    netbios name = |NAME| 
    display charset = |CHARSET|
    interfaces = |INTERFACES|
    server string = |DESCRIPTION|
    unix charset = |CHARSET|
    workgroup = |WORKGROUP|
    browseable = yes
    deadtime = 30
    domain master = yes
    encrypt passwords = true
    enable core files = no
    guest account = root
    guest ok = yes
    #invalid users = root
    local master = yes
    load printers = no
    map to guest = Bad User
    max protocol = SMB2
    min receivefile size = 16384
    null passwords = yes
    obey pam restrictions = yes
    os level = 20
    passdb backend = smbpasswd
    preferred master = yes
    printable = no
    security = share
    smb encrypt = disabled
    #smb passwd file = /etc/samba/smbpasswd
    socket options = TCP_NODELAY IPTOS_LOWDELAY
    syslog = 2
    use sendfile = yes
    writeable = yes

整合軟體

新增aria2,luci新增,web管理介面

aria2 http://sourceforge.net/projects/aria2/files/stable/

#aria2的依賴安裝
sudo apt-get update 
sudo apt-get install autoconf automake libcppunit-dev autopoint openssl libtool sphinx-common sphinxsearch libgcrypt11-dev 
#下載aria2原始碼
cd dl
sudo apt-get install wget
wget http://sourceforge.net/projects/aria2/files/stable/aria2-1.18.7/aria2-1.18.7.tar.bz2
#獲取md5碼
md5sum aria2-1.18.7.tar.bz2
#新增luci-aria2

這裡用的是南浦月的luci-app-aira2和webui-aria2
OpenWrt-Extra https://github.com/nanpuyue/openwrt-extra

在feeds.conf.default中新增`src-git extra git://github.com/nanpuyue/openwrt-extra.git`
./scripts/feeds update -a
./scripts/feeds install -a

在make menuconfig中選中aria2,luci-app-aira2和webui-aria2就可以了

新增將自己開發的程式

在package下建立一個資料夾,以自己的專案命名,裡邊包括一個files資料夾和一個Makefile檔案

目錄結構
<ccnu>
├Makefile
├<files>
│  ├<etc>
│  │  ├<config>
│  │  │  └ccnu
│  │  ├<init.d>
│  │  │  └ccnu
│  ├<usr>
│  │  ├<lib>
│  │  │  ├<lua>
│  │  │  │  ├<luci>
│  │  │  │  │  ├<controller>
│  │  │  │  │  │  └ccnu.lua
│  │  │  │  │  ├<model>
│  │  │  │  │  │  ├<cbi>
│  │  │  │  │  │  │  └ccnu.lua
│  │  ├<sbin>
│  │  │  └ccnu

package/ccnu/Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=ccnu
PKG_VERSION:=2.0.1        
PKG_RELEASE:=1
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/ccnu
  SECTION:=utils
  CATEGORY:=Utilities
  SUBMENU:=H3C inode
  TITLE:= iNode Compatible Client for CCNU
  DEPENDS:=+libc +libgcc 
  MAINTAINER:= RiceLyn <fjkfwz@gmail.com>
endef

define Package/ccnu/description
    iNode Compatible Client for CCNU
endef

define Build/Prepare
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/ccnu/install
    $(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,ccnu))

之後./scripts/feeds install -a,ccnu就會出現在Utilities -> H3C inode裡啦
這裡先做一個簡單的程式,以後會寫文章詳細介紹。

HG255D個性化配置

開啟HG255D編譯

/target/linux/ramips/image/Makefile去除HG255D前的#

Image/Build/Profile/HG255D=$(call BuildFirmware/Default16M/$(1),$(1),hg255d,HG255D)
$(call Image/Build/Profile/HG255D,$(1))

make menuconfig配置

#選擇編譯物件
Target System (Ralink RT288x/RT3xxx)    —>
Subtarget (RT3x5x/RT5350 based boards)  —>
Target Profile (HuaWei HG255D)          —>

#新增USB掛載
Base system —> <*>block-mount   

#新增硬碟格式支援
Kernel modules —> Filesystems —> <*> kmod-fs-ext4 (行動硬碟EXT4格式選擇)
Kernel modules —> Filesystems —> <*> kmod-fs-vfat(FAT16 / FAT32 格式 選擇)
Kernel modules —> Filesystems —> <*> kmod-fs-ntfs (NTFS 格式 選擇)

#新增USB相關支援
Kernel modules —> USB Support —> <*> kmod-usb-core.
Kernel modules —> USB Support —> <*> kmod-usb-ohci.
Kernel modules —> USB Support —> <*> kmod-usb-storage.
Kernel modules —> USB Support —> <*> kmod-usb-storage-extras.
Kernel modules —> USB Support —> <*> kmod-usb2.
Kernel modules —> USB Support —> <*> kmod-usb3.

#新增自動掛載工具
Utilities —> Filesystem —> <*> badblocks

#新增UTF8編碼,CP437編碼,ISO8859-1編碼
Kernel modules —> Native Language Support —> <*> kmod-nls-cp437
Kernel modules —> Native Language Support —> <*> kmod-nls-iso8859-1
Kernel modules —> Native Language Support —> <*> kmod-nls-utf8

#新增SCSI支援
Kernel modules —> Block Devices —> <*>kmod-scsi-core

#新增LED支援
LED modules  —>
< *> kmod-ledtrig-usbdev…………………………. LED USB device Trigger

#新增luci
LuCI ->Collections -> <*> luci

#新增luci的中文語言包
LuCI ->Translations -> <*> luci-i18n-chinese

#新增luci應用
LuCI ->Applications  —> <*> luci-app-aria2……………………………… LuCI Support for aria2
LuCI ->Applications  —> <*> luci-app-ddns……………………… Dynamic DNS configuration module
LuCI ->Applications  —> <*> luci-app-samba……………….. Network SharesSamba SMB/CIFS module
LuCI ->Applications  —> <*> luci-app-transmission…………………. LuCI Support for Transmission

開啟POWER LED狀態指示燈

target\linux\ramips\base-files\etc\diag.sh

get_status_led() {
    case $(ramips_board_name) in
+    hg255d)
+        status_led="hg255d:power"
+        ;;

使用RA-MOD軟體源

RA-MOD https://github.com/ravageralpha/my_openwrt_mod

feeds.conf.default
src-git ramod git://github.com/ravageralpha/my_openwrt_mod.git
#src-git luci http://git.openwrt.org/project/luci.git    

./scripts/feeds clean
./scripts/update -a
./scripts/install -a

新增自動掛載指令碼

/package/base-files/files/etc/gotplug/block/30-block_mount

#!/bin/sh

#---------------------------------------------------------------------
# Filename:    30-block_mount
# Revision:    0.5.1
# Data:        Jul. 7, 2014
# Email:       [email protected]
# Contacts:    QQ/TM 389191 or mail address above
# Licensing:   General Public License v2
# Description: Created for automatic mount block devices on OpenWRT
# Usage:       Put this script into directory /etc/hotplug.d/block
#---------------------------------------------------------------------

## Global settings of auto-mount script ##

# Turn on|off auto-mount function for disk volumes
VOL_ENABLED=1  # <0|1  0-Disable, 1-Enable>

# Turn on|off auto-mount function for sawp partition  
SWAP_ENABLED=1  # <0|1  0-Disable, 1-Enable>

# Set which method you want to name the mounted volumes
USE_VLABEL=1  # <0|1  0-Use device name, 1-Use volume label>  Eg. /mnt/sda1 | /mnt/DataDisk
#
# Note that if you choose name mount point by volume label but the volume's label is empty,
# the volume will be named to 'volume_$PARTUUID', such as the /mnt/volume_31173116-01
# Also, if exist more than one device which have the same volume label, it will be renamed 
# as the original name + sequence number, such as the /mnt/DataDisk_n (n=1,2,3..9)

# Show filesystem type as the prefix of mount point, requires set USE_VLABEL=1
FSTYPE_IN_VLABEL=1  # <0|1  0-Disable, 1-Enable>  Eg. /mnt/[ntfs]-DataDisk

# Set access the mounted device with read-write or read-only permission
FS_READONLY=0  # <0|1  0-Read Write, 1-Read Only>

# Exclusion list of auto-mount function
# Allows mixing the device name, volume label and UUID, each item must be separated by space(s)
# Eg. EXCLUDE_LIST="sda1 DataDisk f32b2ea6-4d42-43a5-bcec-7d818a163d07" 
EXCLUDE_LIST=""  # Default: empty string

# Specify a directory for mounts
MOUNTS_PATH="/mnt"  # Default: /mnt , don't need include the trailing slash (/)

# Define the add-ons scripts directory for automatic execute
ADDSH_PATH="/etc/hotplug.d/user"  # Script naming rule: [0-9][0-9]-xxxxx, Eg. 20-backup-sdcard

## End of global settings ##

# Purge the directory MOUNTS_PATH
purge_mnts()
{
local i RETVAL
[ -d $MOUNTS_PATH ] || return 1
for i in $MOUNTS_PATH/* ; do
    if [ -d $i ] ; then
        if [ -z "`ls -A $i 2>&-`" ] ; then
            `grep -qs "$i" /proc/mounts` || { rm -rf $i 2>/dev/null; RETVAL=$?; }
            if [ $RETVAL -eq 0 ] ; then
                logger -t Auto-Mount "[Notice] Unused mount point $i was removed"
                [ "$CLI" = "yes" ] && echo "[Notice] Unused mount point '$i' was removed"
            else
                logger -t Auto-Mount "[Error] Remove unused mount point $i failed"
                [ "$CLI" = "yes" ] && echo "[Error] Remove unused mount point $i failed"
            fi
        fi
    fi
done
}

# Unmount all block device
umountall()
{
local i MOUNTS
MOUNTS=`grep -os '^/dev/sd[a-z][1-9]' /proc/mounts`
for i in $MOUNTS ; do
    umount -f $i
    [ $? -eq 0 ] &&    echo "[Notice] Device $i unmounted" | tee /proc/self/fd/2 | logger -t Auto-Mount
done
purge_mnts
}

# Detect blkid exists
BLKID=`which blkid`
if [ $? -ne 0 ] ; then
    logger -t Auto-Mount "[Error] Unable to mount block devices automatically because 'blkid' does not exist"
    exit 1
fi

MOUNTS_PATH=${MOUNTS_PATH%/}
[ -z "$ACTION" ] && ACTION=${1##*-}
[ -n "$DEVICENAME" ] && DEV=$DEVICENAME || DEV=$2
logger -t Auto-Mount "[Debug] action='$ACTION' devicename='$DEV'"
case "$ACTION" in
    add)
        [ -z "$DEV" ] && { logger -t Auto-Mount "[Error] Missing required arguments: \$devicename"; exit 1; }
        if [ -n "$EXCLUDE_LIST" ] ; then
            UUID=`$BLKID -s UUID /dev/$DEV | awk -F '=' '{print $NF}' | tr -d '"| '`
            VLABEL=`$BLKID -d -s LABEL /dev/$DEV | awk -F '=' '{print $NF}' | tr -d '"| '`
            for i in $EXCLUDE_LIST ; do
                ignore=0
                if `echo "$i" | grep -qs '^sd[a-z][1-9]$'` ; then  # is device name
                    [ $i = $DEV ] && ignore=1
                elif `echo "$i" | grep -Eiqs '^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$'` ; then  # is UUID
                    [ $i = $UUID ] && ignore=1
                else  # as volume label
                    [ $i = $VLABEL ] && ignore=1
                fi
                [ $ignore -eq 1 ] && { logger -t Auto-Mount "[Notice] Device $DEV is ignored because it in exclusion list"; exit 0; }
            done
        fi
        if `echo "$DEV" | grep -qs '^sd[a-z][1-9]$'` ; then
            [ -z "$VLABEL" ] && VLABEL=`$BLKID -d -s LABEL /dev/$DEV | awk -F '=' '{print $NF}' | tr -d '"| '`
            [ -z "$VLABEL" ] && VLABEL="unknown"
            FSTYPE=`$BLKID -s TYPE /dev/$DEV | awk -F '=' '{print $NF}' | tr -d '"| '`
            logger -t Auto-Mount "[Debug] devicename='$DEV' volume_label='$VLABEL' fstype='$FSTYPE'"
            MCMD=""  # set default value
            [ $FS_READONLY -eq 1 ] && acs="ro" || acs="rw"
            case "$FSTYPE" in
                ext[234])
                    if `grep -vs '^nodev' /proc/filesystems | grep -qs "$FSTYPE"` ; then
                        MCMD="mount -t $FSTYPE -o ${acs},noatime"
                    fi
                    ;;
                xfs|reiserfs)
                    if `grep -vs '^nodev' /proc/filesystems | grep -qs "$FSTYPE"` ; then
                        MCMD="mount -t $FSTYPE -o ${acs},noatime"
                    fi
                    ;;
                iso9660|udf)
                    if `grep -vs '^nodev' /proc/filesystems | grep -qs "$FSTYPE"` ; then
                        MCMD="mount -t $FSTYPE -o ro"
                    fi                    ;;
                vfat|msdos)
                    if `grep -vs '^nodev' /proc/filesystems | grep -qs "$FSTYPE"` ; then
                        MCMD="mount -t $FSTYPE -o ${acs},codepage=936,umask=000"  #iocharset=utf8
                    fi
                    ;;
                exfat)
                    if `grep -Eqs '^[[:space:]]+fuseblk$' /proc/filesystems` && `which mount.exfat >/dev/null` ; then
                        MCMD="mount.exfat -o ${acs},iocharset=cp936,umask=000"
                    fi
                    ;;
                ntfs)
                    if `grep -Eqs '^[[:space:]]+fuseblk$' /proc/filesystems` && `which mount.ntfs-3g >/dev/null` ; then
                        MCMD="mount -t ntfs-3g -o ${acs},noatime,big_writes,async,umask=000"
                    fi
                    ;;
                swap)
                    [ $SWAP_ENABLED -ne 1 ] && exit 0
                    if [ `grep -vs '^Filename' /proc/swaps | wc -l` -eq 0 ] ; then
                        MCMD="swapon /dev/$DEV"
                    fi
                    ;;
                *)
                    MCMD=""
                    ;;
            esac
            [ $VOL_ENABLED -ne 1 ] && exit 0
            if [ $FSTYPE = "swap" ] ; then
                MOPT=""
            elif [ $FSTYPE = "iso9660" -o $FSTYPE = "udf" ] ; then
                CDROM="cdrom"
                if `grep -qs "$MOUNTS_PATH/$CDROM " /proc/mounts` ; then
                    SUFFIX=1
                    while `grep -qs "$MOUNTS_PATH/$CDROM " /proc/mounts` ; do
                        [ $SUFFIX -lt 10 ] && CDROM="${CDROM%_*}_$SUFFIX" || { CDROM="${CDROM%_*}_99"; break; }
                        let SUFFIX++
                    done
                fi
                MPOINT=$CDROM
            else
                if [ $USE_VLABEL -eq 1 ] ; then
                    if [ $VLABEL = "unknown" ] ; then
                        PARTUUID=`$BLKID -s PARTUUID /dev/$DEV | awk -F '=' '{print $NF}' | tr -d '"| '`
                        [ -z "$PARTUUID" ] && PARTUUID=`cat /proc/sys/kernel/random/uuid | cut -f1 -d'-'`
                        VLABEL="volume_${PARTUUID}"
                    elif `grep -qis "$MOUNTS_PATH/$VLABEL " /proc/mounts` ; then
                        SUFFIX=1
                        while `grep -qis "$MOUNTS_PATH/$VLABEL " /proc/mounts` ; do
                            if [ $SUFFIX -lt 10 ] ; then
                                VLABEL="$(echo "$VLABEL" | sed 's/_[0-9]\+$//')_$SUFFIX"
                                let SUFFIX++
                            else
                                VLABEL="$(echo "$VLABEL" | sed 's/_[0-9]\+$//')_99"
                                break
                            fi
                        done
                    fi
                    [ $FSTYPE_IN_VLABEL -eq 1 ] && MPOINT="[${FSTYPE}]-${VLABEL}" || MPOINT=$VLABEL
                else
                    MPOINT=$DEV
                fi
                MOPT="/dev/$DEV $MOUNTS_PATH/$MPOINT"
            fi
            if [ -n "$MCMD" ] ; then
                if ! `grep -qs '/dev/$DEV' /proc/mounts` ; then
                    [ $FSTYPE = "swap" ] || { [ -d $MOUNTS_PATH/$MPOINT ] || mkdir -p $MOUNTS_PATH/$MPOINT; }
                    logger -t Auto-Mount "[Debug] MountCMD='$MCMD $MOPT'"
                    # echo "[Debug] MountCMD='$MCMD $MOPT'" >> /tmp/auto-mount-debug
                    $MCMD $MOPT
                    RETVAL=$?
                    if [ $FSTYPE = "swap" ] ; then
                        if [ $RETVAL -eq 0 ] ; then
                            logger -t Auto-Mount "[Notice] Swap device /dev/$DEV turned on" 
                        fi
                    else
                        if [ $RETVAL -eq 0 ] ; then
                            logger -t Auto-Mount "[Notice] Block device /dev/$DEV mounted on $MOUNTS_PATH/$MPOINT" 
                        else
                            logger -t Auto-Mount "[Warning] Re-try mount the block device /dev/$DEV after 2 seconds..."
                            sleep 2
                            $MCMD $MOPT
                            if [ $? -eq 0 ] ; then
                                logger -t Auto-Mount "[Notice] Block device /dev/$DEV mounted on $MOUNTS_PATH/$MPOINT" 
                            else
                                rm -rf $MOUNTS_PATH/$MPOINT 2>/dev/null
                                logger -t Auto-Mount "[Error] Mount block device /dev/$DEV encounters an error"
                                exit 1
                            fi
                        fi
                    fi
                fi
            else
                if [ $FSTYPE = "swap" ] ; then
                    logger -t Auto-Mount "[Notice] Swap device /dev/$DEV was ignored"
                else
                    logger -t Auto-Mount "[Error] Unsupported filesystem '$FSTYPE' on /dev/$DEV"
                fi
            fi
            unset MCMD
        fi
        purge_mnts
        ;;
    remove)
        [ -z "$DEV" ] && { logger -t Auto-Mount "[Error] Missing required arguments: \$devicename"; exit 1; }
        if `echo "$DEV" | grep -qs '^sd[a-z][1-9]$'` ; then
            if `grep -qs '/dev/$DEV' /proc/mounts` ; then
                MPATH=`awk -F ' ' '/\/dev\/'"$DEV"'/ {print $2}' /proc/mounts 2>/dev/null`
                umount /dev/$DEV
                [ $? -eq 0 ] &&    logger -t Auto-Mount "[Notice] Block device $DEV unmounted"
                [ -d "$MPATH" ] && rm -rf $MPATH 2>/dev/null
            fi
            if `grep -qs '/dev/$DEV' /proc/swaps` ; then
                swapoff $DEV
                [ $? -eq 0 ] &&    logger -t Auto-Mount "[Notice] Swap device $DEV turned off"                 
            fi            
        fi
        purge_mnts
        ;;
    umountall)
        CLI="yes"
        umountall
        ;;
    purge)
        CLI="yes"
        purge_mnts
        ;;
    *)
        echo "[Error] ** Invalid action arguments: $ACTION" | tee /proc/self/fd/2 | logger -t Auto-Mount
        ;;
esac

## Execute the add-ons script
# ADDSH_PATH="$(cd "$(dirname "$0")"; cd ..; pwd)/user"
if [ -n "`ls -A $ADDSH_PATH 2>&-`" ]; then
    i=0
    for addsh in ${ADDSH_PATH}/[0-9][0-9]-* ; do
        [ $i -eq 0 ] && logger -t Auto-Mount "[Notice] -- Execute additional scripts ..."
        logger -t Hotplug-Debug "-- Exec script - $addsh"
        sh $addsh $ACTION $DEV 
        let i++
    done
fi
# Script EOF