📄 install-can.svn-base
字号:
#!/bin/sh# install-can.shROOT_UID=0 # Only users with $UID 0 have root privileges.E_XCD=66 # Can't change directory?E_NOTROOT=67 # Non-root exit error.defDir=1#key=link_files=1directory="/usr/src/linux"#directory="/home/tiderko/Entwicklung/testdir"# the copy function --------------------------------------function can_copy (){ # Copy *.c and *.h files in driver/can directory echo " -> Copy CAN driver files to $directory/drivers/can . . . " mkdir -p $directory"/drivers/can" cp ./core/*.c ./core/*.h $directory"/drivers/can" # Copy or link files if [ $link_files = "0" ] then echo " -> Link can.h and Kconfig files" # link Kconfig ln -s $(pwd)/core/Kconfig $directory"/drivers/can/Kconfig" ln -s $(pwd)/tools/can.h $directory"/include/linux/can.h" # link can.h in "usr/include/can" mkdir -p "/usr/include/can" ln -s $(pwd)/tools/can.h "/usr/include/can/can.h" else # copy Kconfig cp ./core/Kconfig $directory"/drivers/can" # copy can.h cp ./tools/can.h $directory"/include/linux" # copy can.h in "usr/include/can" echo " -> Copy can.h to usr/include/can . . . " mkdir -p "/usr/include/can" cp ./tools/can.h "/usr/include/can" fi # Create Makefile echo " -> Create Makefile in $directory/drivers/can . . . " cat ./core/make.kernel > $directory"/drivers/can/Makefile" # Add to Kconfig the line: source "<install-dir>/drivers/can/Kconfig" echo " -> Modify Kconfig in $directory/drivers . . . " # Test if the line: source "can/Kconfig already exists if [ "$(sed -n '/source \"drivers\/can\/Kconfig\"/=' $directory"/drivers/Kconfig")" = "" ] then sed '/source \"net\/Kconfig\"/ a\\nsource \"drivers\/can\/Kconfig\"' $directory"/drivers/Kconfig" > temp cat temp > $directory"/drivers/Kconfig" rm temp fi # Add to Makefile the line: source "<install-dir>/drivers/can/Kconfig" echo " -> Modify Makefile in $directory/drivers . . . " # Test if the line: "obj-y += can" already exists if [ "$(sed -n '/obj-y\t\t\t\t+= can/=' $directory"/drivers/Makefile")" = "" ] then# echo "habe gefunden" sed '/obj-y\t\t\t\t+= base/ a\obj-y\t\t\t\t+= can/' $directory"/drivers/Makefile" > temp cat temp > $directory"/drivers/Makefile" rm temp fi # Copy *.h files in include/net/can directory echo " -> Copy CAN driver files to $directory/include/net/can . . . " mkdir -p $directory"/include/net/can" cp ../../include/*.h $directory"/include/net/can" echo " -> Store the install directory . . . " echo $directory > /usr/include/can/install-dir echo ""}# Tis function tests the entered directory and the version of Linuxfunction test_dir (){ # Test if the entered directory includes the version.h if test -f "$directory/include/linux/version.h" then # Compere the Linux-Version UTS_VERSION=$(grep "UTS_RELEASE" "$directory/include/linux/version.h" | sed 's/[^"]*"//' | sed 's/[^.]*"//') if [ $UTS_VERSION = "2.6." ] then # The Linux-Versions are equal # begin to copy the files echo "Kernel source version is ${UTS_VERSION}*" can_copy else # The Linux-Versions are not equal # exit with an error echo "Kernel source version is ${UTS_VERSION}*" echo "You need kernel source version 2.6.*" echo "usage: install-can -help for help" exit 1 fi else # The entered directory does not include the necessarily files echo "Bad entry or the directory! '$directory' does not include the necessarily files!" echo "usage: install-can -help for help" exit 1 fi}# This function removes all installed directoriesfunction can_remove (){ # remove driver/can directory echo " -> Remove CAN driver files from $directory/drivers . . . " rm -r $directory"/drivers/can" # remove can.h rm $directory"/include/linux/can.h" # remove can.h from "usr/include/can" echo " -> Remove usr/include/can directory . . . " rm -r "/usr/include/can" # Remove from Kconfig file the line: source "drivers/can/Kconfig" echo " -> Modify Kconfig in $directory/drivers . . . " sed '/source \"drivers\/can\/Kconfig\"/,+1 d' $directory"/drivers/Kconfig" > temp cat temp > $directory"/drivers/Kconfig" rm temp # Remove from Makefile file the line: obj-y += can echo " -> Modify Makefile in $directory/drivers . . . " sed '/obj-y\t\t\t\t+= can/ d' $directory"/drivers/Makefile" > temp cat temp > $directory"/drivers/Makefile" rm temp # remove include/net/can directory echo " -> Remove CAN driver files from $directory/include/net . . . " rm -r $directory"/include/net/can" echo "" echo "All files were removed!" echo ""}# This fuction checks the correct entry from userfunction proceed (){ while : do echo -n "Proceed? [y/n] " read key case $key in 'y' | 'Y') return 0;; 'n' | 'N') return 1;; esac done}function help_function (){cat <<EOFusage: install-can <option>OPTION:<directory> enter the install directory-d use to uninstall can-help use to display help-l use to link can.h and Kconfing NOT to copy! you can also use: install-can <directory> -l EOF}# Run as root, of course. if [ "$UID" -ne "$ROOT_UID" ] then echo "Must be root to run this script!" exit $E_NOTROOT fi # Test if command line argument present (non empty)case $# in0) # no arguments in the command line echo "" echo "This script installs the CANpie kernel driver package in the kernel source tree." echo "Default directory is $directory" # User enter his choise proceed if [ $? = 0 ] then test_dir else echo -n "Please enter the new directory: " read directory test_dir exit 0 fi;; 1) # use arguments from command line if [ "$1" = "-d" ] then # Test if the install directory exists if test -f "/usr/include/can/install-dir" then directory=$(cat /usr/include/can/install-dir) echo "" echo "This will remove the CANpie kernel driver package from the kernel source tree." echo "The installation directories are: " echo " $directory/drivers/can" echo " $directory/include/net/can" echo " /usr/include/can" # User enter his choise proceed if [ $? = 0 ] then can_remove exit 0 else echo "The Operation was canceld by user!" exit 0 fi else echo "The files couldn't be removed!" exit 1; fi fi if [ "$1" = "-l" ] then echo "" echo "This script installs the CANpie kernel driver package in the kernel source tree." echo "With LINKERS to can.h and Kconfig to default directory $directory" link_files=0 test_dir exit 0 fi if [ "$1" = "-help" ] then help_function else echo "" echo "This script installs the CANpie kernel driver package in the '$1'" directory=$1 test_dir exit 0 fi;; 2) if [ "$2" = "-l" ] then echo "" echo "This script installs the CANpie kernel driver package in the '$1' with LINKERS to can.h and Kconfig" directory=$1 link_files=0 test_dir fi;;*) echo "usage: install-can <OPTION>" echo "enter 麓install-can -help麓 for help";;esac
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -