安装编译环境:
apt-get install build-essential libncurses5-dev zlib1g-dev
下载交叉编译环境及sshpass源码:
wget http://downloads.openwrt.org/backfire/10.03.1/brcm63xx/OpenWrt-SDK-brcm63xx-for-Linux-i686-gcc-4.3.3%2bcs_uClibc-0.9.30.1.tar.bz2
tar jxvf OpenWrt-SDK-brcm63xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
mkdir -p OpenWrt-SDK-brcm63xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1/package/sshpass
cd OpenWrt-SDK-brcm63xx-for-Linux-i686-gcc-4.3.3+cs_uClibc-0.9.30.1/package/sshpass
wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz
tar zxvf sshpass-1.05.tar.gz
mv sshpass-1.05 src
sshpass目录新建Makefile文件:
include $(TOPDIR)/rules.mk
# Name and release number of this package
PKG_NAME:=sshpass
PKG_RELEASE:=1.05
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/sshpass
SECTION:=utils
CATEGORY:=Utilities
TITLE:=sshpass
endef
define Package/sshpass/description
Sshpass is a tool for non-interactivly performing password authentication with SSH's
endef
# Specify what needs to be done to prepare for building the package.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
# Specify where and how to install the program.
define Package/sshpass/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/sshpass $(1)/bin/
endef
# This line executes the necessary commands to compile our program.
$(eval $(call BuildPackage,sshpass))
编译sshpass:
cd ../
make package/sshpass/compile
编译成功的程序文件:
ls bin/brcm63xx/packages/
Packages Packages.gz sshpass_1.05_brcm63xx.ipk
编译过程中如遇到以下错误:
staging_dir/toolchain-mips_r2_gcc-4.3.3+cs_uClibc-0.9.30.1/usr/lib/libc.so: undefined reference to `_dl_app_init_array’
需修改:
TARGET_LDFLAGS:=-L$(STAGING_DIR)/usr/lib -L$(STAGING_DIR)/lib
为:
TARGET_LDFLAGS+= -L$(TOOLCHAIN_DIR)/usr/lib -L$(TOOLCHAIN_DIR)/lib -Wl,-rpath=$(TOOLCHAIN_DIR)/lib
sshpass使用:
sshpass -p pass ssh -p 22 -o StrictHostKeyChecking=no root@haiyun.me 'uptime'
标签:openwrt