From e8d34d11799fc79c7c53bdcd40f9b4ee7be7a2c5 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 25 Sep 2024 17:42:22 +0800
Subject: [PATCH] Merge branch 'master' of ssh://weike-iot.com:2280/framwork
---
openlibs/dropbear/build.sh | 212 ++++++++++++++++++++++++++++++++++------------------
1 files changed, 137 insertions(+), 75 deletions(-)
diff --git a/openlibs/dropbear/build.sh b/openlibs/dropbear/build.sh
index d6a55c7..04d0844 100755
--- a/openlibs/dropbear/build.sh
+++ b/openlibs/dropbear/build.sh
@@ -1,43 +1,121 @@
#!/bin/bash
-#+--------------------------------------------------------------------------------------------
-#|Description: This shell script used download and compile dropbear for ARM
-#| Author: GuoWenxue <guowenxue@gmail.com>
-#| ChangeLog:
-#| 1, Initialize 1.0.0 on 2011.04.12
-#+--------------------------------------------------------------------------------------------
+# library name and version
+# Official: http://matt.ucc.asn.au/dropbear/releases
+LIB_NAME=dropbear-2019.78
+PACK_SUFIX=tar.bz2
-PREFIX_PATH=`pwd`/../install/
-
+# LingYun source code FTP server
LYFTP_SRC=http://master.weike-iot.com:2211/src/
+# library download URL address
+LIB_URL=$LYFTP_SRC
+
+# Cross compiler for cross compile on Linux server
CROSS_COMPILE=/opt/gcc-aarch32-10.3-2021.07/bin/arm-none-linux-gnueabihf-
-function msg_banner()
-{
- echo ""
- echo "+-----------------------------------------------------------------------"
- echo "| $1 "
- echo "+-----------------------------------------------------------------------"
- echo ""
+# compile jobs
+JOBS=`cat /proc/cpuinfo |grep "processor"|wc -l`
+
+# this project absolute path
+PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
+
+# top project absolute path
+TOP_PATH=$(realpath $PRJ_PATH/..)
+
+# binaries install path
+PREFIX_PATH=$TOP_PATH/install
+BIN_PATH=$PREFIX_PATH/bin
+LIB_PATH=$PREFIX_PATH/lib
+INC_PATH=$PREFIX_PATH/include
+
+# check installed or not file
+INST_FILE=$PREFIX_PATH/bin/dropbear
+
+# shell script will exit once get command error
+set -e
+
+#+-------------------------+
+#| Shell script functions |
+#+-------------------------+
+
+function pr_error() {
+ echo -e "\033[40;31m $1 \033[0m"
+}
+
+function pr_warn() {
+ echo -e "\033[40;33m $1 \033[0m"
+}
+
+function pr_info() {
+ echo -e "\033[40;32m $1 \033[0m"
}
function check_result()
{
if [ $? != 0 ] ; then
- echo ""
- echo "+-----------------------------------------------------------------------"
- echo "| $1 "
- echo "+-----------------------------------------------------------------------"
- echo ""
- exit ;
+ pr_error "$1"
+ exit
fi
}
-
-function export_cross()
+# decompress a packet to destination path
+function do_unpack()
{
+ tarball=$1
+ dstpath=`pwd`
+
+ if [[ $# == 2 ]] ; then
+ dstpath=$2
+ fi
+
+ pr_info "decompress $tarball => $dstpath"
+
+ mkdir -p $dstpath
+ case $tarball in
+ *.tar.gz)
+ tar -xzf $tarball -C $dstpath
+ ;;
+
+ *.tar.bz2)
+ tar -xjf $tarball -C $dstpath
+ ;;
+
+ *.tar.xz)
+ tar -xJf $tarball -C $dstpath
+ ;;
+
+ *.tar.zst)
+ tar -I zstd -xf $tarball -C $dstpath
+ ;;
+
+ *.tar)
+ tar -xf $tarball -C $dstpath
+ ;;
+
+ *.zip)
+ unzip -qo $tarball -d $dstpath
+ ;;
+
+ *)
+ pr_error "decompress Unsupport packet: $tarball"
+ return 1;
+ ;;
+ esac
+}
+
+function do_export()
+{
+ BUILD_ARCH=$(uname -m)
+ if [[ $BUILD_ARCH =~ "arm" ]] ; then
+ pr_warn "local($BUILD_ARCH) compile $LIB_NAME"
+ return ;
+ fi
+
+ pr_warn "cross(${CROSS_COMPILE}) compile $LIB_NAME"
+
# export cross toolchain
export CC=${CROSS_COMPILE}gcc
+ export CXX=${CROSS_COMPILE}g++
export AS=${CROSS_COMPILE}as
export AR=${CROSS_COMPILE}ar
export LD=${CROSS_COMPILE}ld
@@ -46,7 +124,7 @@
export OBJDUMP=${CROSS_COMPILE}objdump
export STRIP=${CROSS_COMPILE}strip
- # export cross configure
+ # export cross configure
export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux "
# Clear LDFLAGS and CFLAGS
@@ -54,71 +132,55 @@
export CFLAGS=
}
-function compile_x86()
+function do_fetch()
{
- # compile for X86 and generate Key
- msg_banner "Start compile $SRC_NAME for X86"
- make distclean
- ./configure && make
- ./dropbearkey -t rsa -f ${PREFIX_PATH}/dropbear_rsa_host_key
- chmod 644 ${PREFIX_PATH}/dropbear_rsa_host_key
- make distclean
+ if [ -e ${INST_FILE} ] ; then
+ pr_warn "$LIB_NAME compile and installed alredy"
+ exit ;
+ fi
+
+ if [ -d $LIB_NAME ] ; then
+ pr_warn "$LIB_NAME fetch already"
+ return ;
+ fi
+
+ if [ ! -f ${LIB_NAME}.${PACK_SUFIX} ] ; then
+ wget ${LIB_URL}/${LIB_NAME}.${PACK_SUFIX}
+ check_result "ERROR: download ${LIB_NAME} failure"
+ fi
+
+ do_unpack ${LIB_NAME}.${PACK_SUFIX}
}
-function compile_dropbear()
+function do_build()
{
- SRC_NAME=dropbear-2019.78
- PACK_SUFIX=tar.bz2
+ cd $LIB_NAME
- if [ -f ${PREFIX_PATH}/bin/dropbear ] ; then
- msg_banner "$SRC_NAME already compile and installed"
- return 0;
- fi
-
- msg_banner "Start donwload $SRC_NAME "
- if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
- #wget http://matt.ucc.asn.au/dropbear/releases/${SRC_NAME}.${PACK_SUFIX}
- wget $LYFTP_SRC/$SRC_NAME.$PACK_SUFIX
- check_result "ERROR: download ${SRC_NAME} failure"
- fi
-
- tar -xjf ${SRC_NAME}.${PACK_SUFIX}
- cd ${SRC_NAME}
-
- msg_banner "Start cross compile $SRC_NAME "
+ do_export
./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --disable-zlib
- check_result "ERROR: configure ${SRC_NAME} failure"
+ check_result "ERROR: configure ${LIB_NAME} failure"
- make
- check_result "ERROR: compile ${SRC_NAME} failure"
+ make -j ${JOBS}
+ check_result "ERROR: compile ${LIB_NAME} failure"
- ${STRIP} dbclient dropbear
- cp dropbear ..
- cp dbclient ../ssh
- cp dbclient ${PREFIX_PATH}/bin/ssh
- cp dropbear ${PREFIX_PATH}/bin/
-
- cd -
+ install -d ${BIN_PATH}
+ install -m 755 dbclient ${BIN_PATH}/ssh
+ install -m 755 dropbear ${BIN_PATH}/
}
-function install_script()
+function do_clean()
{
- init_script=S20_dropbear
-cat << EOF > ${init_script}
-#!/bin/sh
-
-mkdir -p /etc/dropbear/
-dropbear -R
-EOF
-
- chmod 755 ${init_script}
-
+ rm -rf *${LIB_NAME}*
}
-export_cross
+if [[ $# == 1 && $1 == -c ]] ;then
+ pr_warn "start clean ${LIB_NAME}"
+ do_clean
+ exit;
+fi
-compile_dropbear
+do_fetch
-install_script
+do_build
--
Gitblit v1.9.1