diff --git a/tools/build-binaries.sh b/tools/build-binaries.sh index a8aba88..b82c50f 100755 --- a/tools/build-binaries.sh +++ b/tools/build-binaries.sh @@ -5,6 +5,7 @@ set -e -x NDK_PATH="${NDK_PATH:-/opt/ndk}" +BUILD_ROOT="${BUILD_ROOT:-/tmp/dropbear-build}" SRC_ROOT="${SRC_ROOT:-$(realpath -e -s -- "$(dirname -- "${0}")/..")}" PATCH_DIR="${PATCH_DIR:-${SRC_ROOT}/tools/patches}" TARGET_DIR="${TARGET_DIR:-${SRC_ROOT}/services/bin}" @@ -25,7 +26,7 @@ install_ndk() { # Download and checksum a src download() { local src="/tmp/${1}.tar.gz" - local srcdir="/opt/${1}-src" + local srcdir="${BUILD_ROOT}/${1}-src" rm -r -f -- "${srcdir}" mkdir -p -- "${srcdir}" wget -O "${src}" -- "${2}" @@ -35,31 +36,31 @@ download() { } build_dropbear() { - cd /opt/dropbear-src + cd "${BUILD_ROOT}/dropbear-src" patch -N -p 1 -i "${PATCH_DIR}/dropbear-2022.83-dynamic_crypt-v1.patch" cp -v -- "${PATCH_DIR}/dropbear-localoptions.h" localoptions.h - ./configure --host arm-webos-linux-gnueabi --disable-lastlog --enable-dynamic-crypt + ./configure ${CONFIGURE_FLAGS} --disable-lastlog --enable-dynamic-crypt local programs='dropbear scp' make ${MAKEOPTS} -- PROGRAMS="${programs}" - arm-webos-linux-gnueabi-strip -- ${programs} + ${STRIP} -- ${programs} cp -v -v -t "${TARGET_DIR}" -- ${programs} } build_rsync() { - cd /opt/rsync-src - ./configure --host arm-webos-linux-gnueabi \ + cd "${BUILD_ROOT}/rsync-src" + ./configure ${CONFIGURE_FLAGS} \ --disable-simd --disable-debug --with-included-popt=yes --with-included-zlib=yes \ --disable-lz4 --disable-zstd --disable-xxhash --disable-md2man --disable-acl-support make ${MAKEOPTS} - arm-webos-linux-gnueabi-strip -- rsync + ${STRIP} -- rsync cp -v -t "${TARGET_DIR}" -- rsync } build_sftp() { - cd /opt/openssh-src - ./configure --host=arm-webos-linux-gnueabi --without-openssl + cd "${BUILD_ROOT}/openssh-src" + ./configure ${CONFIGURE_FLAGS} --without-openssl --without-zlib-version-check make ${MAKEOPTS} -- sftp-server - arm-webos-linux-gnueabi-strip -- sftp-server + ${STRIP} -- sftp-server cp -v -t "${TARGET_DIR}" -- sftp-server } diff --git a/tools/patches/dropbear-localoptions.h b/tools/patches/dropbear-localoptions.h index 4765e98..f279b4a 100644 --- a/tools/patches/dropbear-localoptions.h +++ b/tools/patches/dropbear-localoptions.h @@ -5,4 +5,29 @@ #define DEFAULT_PATH "/home/root/.local/bin:/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin:/usr/bin:/bin" #define DEFAULT_ROOT_PATH "/home/root/.local/bin:/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin:/usr/sbin:/usr/bin:/sbin:/bin" #define DROPBEAR_SFTPSERVER 1 -#define SFTPSERVER_PATH "/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin/sftp-server" + +#define SFTPSERVER_PATH_FALLBACK "/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin/sftp-server" + +#include +#include + +static const char* get_sftp_server_path() { + static char path[4096] = ""; + if (path[0] == '\0') { + char* dropbear_path = realpath("/proc/self/exe", path); + char *last_slash; + if (dropbear_path == NULL) { + strncpy(path, SFTPSERVER_PATH_FALLBACK, sizeof(path)); + return path; + } + last_slash = strrchr(path, '/'); + if (last_slash == NULL) { + strncpy(path, SFTPSERVER_PATH_FALLBACK, sizeof(path)); + return path; + } + strcpy(last_slash + 1, "sftp-server"); + } + return path; +} + +#define SFTPSERVER_PATH get_sftp_server_path()