Add functionality to small Linux and automatically add dependent libraries to the appropriate location

Source: Internet
Author: User

To add functionality to small Linux, let's write a script.


$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

Important points of knowledge: FILE=/ETC/LOCAL/SRC

from left to right

Echo ${file#/} A # indicates that the first/left content is stripped out of the execution result to ETC/LOCAL/SRC

Echo ${file##/} represents a left-to-right look, finds the last/and removes all left-hand content from the execution result to/SRC (for filename)

From right to left

Echo ${file%/*} Search from right to left/find first will/and right content all delete execution result to/etc/local (directory for fetching files)

Echo ${file%%/*} Go from right to left to the last/and remove all of its contents to the right

*******************************************************************

#!/bin/bash

#

# #复制生成路径

Dest=/mnt/sysroot

LIBCP () {

libpath=${1%/*}

[!-D $DEST $libpath] && mkdir-p $DEST $libpath

[!-e $DEST ${1}] && cp $DEST $libpath && echo "copy $ finished."

}


# #复制命令

BINCP () {

cmdpath=${1%/*}

[!-D $DEST $cmdpath] && mkdir-p $DEST $cmdpath

[!-e $DEST ${1}] && cp $DEST $cmdpath


For LIB in ' LDD $ | Grep-o "/.*lib\ (64\) \{0,1\}/[^[:space:]]\{1,\}"; Do

LIBCP $LIB

Done

}

Read-p "Your command:" CMD

until [$CMD = = ' Q ']; Do

! Which $CMD && echo "wrong command" && read-p "Input again" CMD && continue

Command= ' which $CMD | Grep-v "^alias" | Grep-o "[^[:space:]]\{1,\}" '

BINCP $COMMAND

echo "Copy $COMMAND finished"

Read-p "Continue:" CMD

Done



###########################################

At last

Mkdir/mnt/sysroot/lib/modules

Modinfo Mii The execution result has a path and then copies the path

cp/lib/modules/2.6.18....mii.ko/mnt/sysroot/lib/modules/

Modeinfo Pcnet32 the execution results have a path and then copy

Cp/lib/modules/2.6.18....net.pcnet32.ko

Sync

We look forward to automatically loading these two modules when booting

Vim/mnt/sysroot/etc/rc.d/rc.sysinit

Insmod/lib/modules/mii.ko

Insmod/lib/modules/pcnet32.ko

Ifconfig eth0 192.168.9.224/16

Ifconfig Lo 192.0.0.0/8

Sync




Add functionality to small Linux and automatically add dependent libraries to the appropriate location

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.