What's new

Entware [SOLUTION] Cross-Compile Torsocks Entware Package via Debian Live DVD

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

garycnew

Senior Member
NOTE: After finally being convinced by the Entware & OpenWRT Developers that neither Build Environment was meant to be Compiled Natively on a Router (Neutered C Libraries), I decided to pursue this Cross-Compile Torsocks Entware Package via Debian Live DVD solution; which, is presumably a bit slower, but ultimately successful. It wasn't too terrible after finding the right cross-compiling platform and combining a few different build references.

Requirements/Assumptions:

Cross-Compiling Host Machine:
1. Plenty of Physical Memory (RAM)
2. Debian Live (Testing) DVD
3. Flash Drive >= 32GB (Preferably USB 3.0/3.1)

Torsocks Installation Machine:
1. An Asuswrt-Merlin Compatible Router (i.e., Asus RT-AC66U)
2. Asuswrt-Merlin Compatible Firmware (i.e., 384.19)
3. Formated JFFS Partition and Enabled JFFS Custom Scripts and Configs
4. Entware installed on USB 3.0 Interface Device via Asuswrt-Merlin Terminal Menu (AMTM) with Swap File created

NOTE: Not sure if it matters... At the time of this writing, Debian Bullseye (Testing) Live DVD contained the same package versions as the current Entware repository, opposed to the Debian Buster (Stable) Live DVD, so we opted to use the Debian Bullseye (Testing) Live DVD.

### Download & Burn Debian Live (Testing) DVD ###
Code:
$ curl -L -O -C - http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/weekly-live-builds/amd64/iso-hybrid/debian-live-testing-amd64-gnome+nonfree.iso

### Boot Debian Live (Testing) DVD on the Cross-Compiling Host Machine ###
Our Cross-Compiling Host Machine required the [F12] key to be pressed during boot to enter into the Boot Menu and select the Debian Live (Testing) DVD. Make sure you setup and have Internet access on the Cross-Compiling Host Machine.

### Open Terminal ###

### Mount Flash Drive (Repeat after each DVD Boot) ###
Code:
$ sudo -p /media/user/SanDiskSDCZ
$ sudo mount /dev/sdb1 /media/user/SanDiskSDCZ
$ cd /media/user/SanDiskSDCZ/

### Download & Install Build System (Repeat after each DVD Boot) ###
Code:
$ sudo apt-get update
$ sudo apt-get install git-core build-essential libssl-dev libncurses5-dev unzip gawk zlib1g-dev
$ sudo apt-get install python2 wget

### Clone, Setup, & Make Entware Build Env ###
Code:
$ git clone https://github.com/Entware/Entware.git
$ cd Entware

# Update OpenWRT Feeds
$ ./scripts/feeds update -a

# Symlink Packages (Repeat after each DVD Boot)
$ make package/symlinks

# Copy the config specific to your Architecture and Kernel versions
$ cp configs/armv7-2.6.config .config

$ make tools/install && make toolchain/install && make target/compile
or
#$ make -j1 V=sc tools/install
#$ make -j1 V=sc toolchain/install
#$ make -j1 V=sc target/compile

### Download, Prepare, & Compile Test Package from OpenWRT Feed ###
Code:
#$ ./scripts/feeds install screen
or
$ make -j1 V=sc package/screen/download
$ make -j1 V=sc package/screen/check
$ find package/ -iname "*screen*"
package/feeds/packages/screen

$ make -j1 V=sc package/screen/prepare
$ make -j1 V=sc package/screen/compile
#$ make -j1 V=sc package/screen/install
#$ make package/index

$ find bin/ -iname "*screen*"
bin/targets/armv7-2.6/generic-glibc/packages/screen_4.8.0-2_armv7-2.6.ipk

### Download & Prepare OpenWRT Feed Package modified for Entware (When Available) ###
Code:
#$ ./scripts/feeds install torsocks
or
$ make -j1 V=sc package/feeds/packages/torsocks/download
$ make -j1 V=sc package/feeds/packages/torsocks/check
$ find package/ -iname "*torsocks*"
package/feeds/packages/torsocks

### Edit the Makefile to use the /opt directory prefix ###
Code:
$ diff package/feeds/packages/torsocks/Makefile.orig package/feeds/packages/torsocks/Makefile
50c50
< /etc/tor/torsocks.conf
---
> /opt/etc/tor/torsocks.conf
54,59c54,59
< $(INSTALL_DIR) $(1)/etc/tor/
< $(CP) $(PKG_INSTALL_DIR)/etc/tor/torsocks.conf $(1)/etc/tor/
< $(INSTALL_DIR) $(1)/usr/lib/torsocks
< $(CP) $(PKG_INSTALL_DIR)/usr/lib/torsocks/libtorsocks.so* $(1)/usr/lib/torsocks/
< $(INSTALL_DIR) $(1)/usr/bin
< $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/torsocks $(1)/usr/bin/
---
> $(INSTALL_DIR) $(1)/opt/etc/tor/
> $(CP) $(PKG_INSTALL_DIR)/opt/etc/tor/torsocks.conf $(1)/opt/etc/tor/
> $(INSTALL_DIR) $(1)/opt/lib/torsocks
> $(CP) $(PKG_INSTALL_DIR)/opt/lib/torsocks/libtorsocks.so* $(1)/opt/lib/torsocks/
> $(INSTALL_DIR) $(1)/opt/bin
> $(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/torsocks $(1)/opt/bin/

### Select torsocks for [M]odular inclusion under the SECTION => CATEGORY => SUBMENU of menuconfig ###
Code:
$ make menuconfig
define Package/torsocks
SECTION:=net
CATEGORY:=Network
SUBMENU:=IP Addresses and Names
TITLE:=torsocks
URL:=https://trac.torproject.org/projects/tor/wiki/doc/torsocks
DEPENDS:=+tor
endef

### Compile OpenWRT Feed Package modified for Entware ###
Code:
$ make -j1 V=sc package/feeds/packages/torsocks/prepare
$ make -j1 V=sc package/feeds/packages/torsocks/compile
#$ make -j1 V=sc package/feeds/packages/torsocks/install
#$ make package/index

$ find bin/ -iname "*torsocks*"
bin/targets/armv7-2.6/generic-glibc/packages/torsocks_2.3.0-1_armv7-2.6.ipk

### SFTP & SSH torsocks Package to Torsocks Installation Machine(s) ###
Code:
$ cd bin/targets/armv7-2.6/generic-glibc/packages/
$ sftp admin@192.168.0.1
sftp> cd /tmp/mnt/SanDiskSDHC/torsocks/
sftp> put torsocks_2.3.0-1_armv7-2.6.ipk

$ ssh admin@192.168.0.1
# cd /tmp/mnt/SanDiskSDHC/
# opkg install ./torsocks/*

# opkg list-installed|grep -i tor
tor - 0.4.5.7-1
tor-geoip - 0.4.5.7-1
torsocks - 2.3.0-1

# opkg files torsocks
Package torsocks (2.3.0-1) is installed on root and has the following files:
/opt/bin/torsocks
/opt/lib/torsocks/libtorsocks.so.0.0.0
/opt/lib/torsocks/libtorsocks.so.0
/opt/lib/torsocks/libtorsocks.so
/opt/etc/tor/torsocks.conf

# opkg info torsocks
Package: torsocks
Version: 2.3.0-1
Depends: libc, libssp, librt, libpthread, tor
Status: install user installed
Architecture: armv7-2.6
Installed-Time: 1624530763

# /opt/bin/torsocks -h
torsocks 2.3.0

# /opt/bin/torsocks -i -a 127.0.0.1 -P 9050 wget -O - https://ifconfig.me
or
# LD_PRELOAD=/opt/lib/torsocks/libtorsocks.so.0.0.0 wget -O - https://ifconfig.me

### Shell Compatibility Patch ###
Code:
# diff /opt/bin/torsocks.orig /opt/bin/torsocks
@@ -223,8 +223,8 @@
-    local app_path="$(command -v "$1")"
-    local getcap="$(PATH="$PATH:/usr/sbin:/sbin" command -v getcap)"
+    local app_path="$(which "$1")"
+    local getcap="$(PATH="$PATH:/usr/sbin:/sbin" which getcap)"

Congratulations! You've Cross-Compiled a Torsocks Entware Package via Debian Live (Testing) DVD! The Possibilities are Endless with Good-Times Ahead!

References:
Code:
http://bin.entware.net/armv7sf-k2.6/
http://cdimage.debian.org/cdimage/unofficial/non-free/cd-including-firmware/weekly-live-builds/amd64/iso-hybrid/
https://packages.debian.org/search?keywords=search
https://oldwiki.archive.openwrt.org/about/toolchain
https://oldwiki.archive.openwrt.org/doc/howto/buildroot.exigence
https://oldwiki.archive.openwrt.org/doc/howto/build.a.package
https://github.com/Entware/Entware/wiki/How-to-add-a-new-package
https://github.com/Entware/Entware-ng/wiki/Using-gcc-%28native-compilation%29
https://github.com/dgoulet/torsocks
https://github.com/openwrt/packages/blob/openwrt-19.07/net/torsocks/Makefile

### Full Edited torsocks Makefile ###
Code:
$ cat net/torsocks/Makefile
#
# Copyright (C) 2017-2019 CZ.NIC, z. s. p. o. (https://www.nic.cz/)
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#

include $(TOPDIR)/rules.mk

PKG_NAME:=torsocks
PKG_VERSION:=2.3.0
PKG_RELEASE:=1

PKG_SOURCE_URL:=https://people.torproject.org/~dgoulet/torsocks/
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_HASH:=b9f1b981d6b3fd4e1820de1eee325f8a7038c84765d5a6cd9af12571d5cc3622

PKG_MAINTAINER:=Jan Pavlinec <jan.pavlinec@nic.cz>
PKG_LICENSE:=GPLv2
PKG_LICENSE_FILES:=LICENSE

PKG_INSTALL:=1
PKG_BUILD_PARALLEL:=1
PKG_FIXUP:=autoreconf

include $(INCLUDE_DIR)/package.mk

define Package/torsocks
    SECTION:=net
    CATEGORY:=Network
    SUBMENU:=IP Addresses and Names
    TITLE:=torsocks
    URL:=https://trac.torproject.org/projects/tor/wiki/doc/torsocks
    DEPENDS:=+tor
endef

define Package/torsocks/description
Torsocks allows you to use most applications in a safe way with Tor.
It ensures that DNS requests are handled safely and explicitly rejects any traffic other than TCP from the application you're using.
endef

define Build/Configure
    $(call Build/Configure/Default)
ifeq ($(CONFIG_USE_UCLIBC),y)
    find $(PKG_BUILD_DIR) -name 'Makefile' -exec sed -i 's|--param ssp-buffer-size=1 -fstack-protector-all||' \{\} \+
endif
endef

define Package/conffiles
/opt/etc/tor/torsocks.conf
endef

define Package/torsocks/install
    $(INSTALL_DIR) $(1)/opt/etc/tor/
    $(CP) $(PKG_INSTALL_DIR)/opt/etc/tor/torsocks.conf $(1)/opt/etc/tor/
    $(INSTALL_DIR) $(1)/opt/lib/torsocks
    $(CP) $(PKG_INSTALL_DIR)/opt/lib/torsocks/libtorsocks.so* $(1)/opt/lib/torsocks/
    $(INSTALL_DIR) $(1)/opt/bin
    $(INSTALL_BIN) $(PKG_INSTALL_DIR)/opt/bin/torsocks $(1)/opt/bin/
endef

$(eval $(call BuildPackage,torsocks))
 

Attachments

  • torsocks_2.3.0-1_armv7-2.6.txt
    34.4 KB · Views: 134
Last edited:
will you stay around to migrate/update this as Merlin drops support for your testing platform please? the AX series is quite a powerhouse compared to the early AC series stuff
 
will you stay around to migrate/update this as Merlin drops support for your testing platform please? the AX series is quite a powerhouse compared to the early AC series stuff

@heysoundude It should be a trivial matter of just using the desired pre-rolled architecture-kernel.config file.
Code:
# Copy the config specific to your Architecture and Kernel versions
$ cp configs/armv7-2.6.config .config

"Sounds" like a good opportunity for someone else to play in the sandbox. Watch out for the worms, though.

I hate to think that my AiMesh Nodes will have to be migrated, someday. If I do it right, it shouldn't be too painful, though. This is a step in that direction.

Currently, I don't have any wireless devices that make use of 802.11ax.
 
@heysoundude It should be a trivial matter of just using the desired pre-rolled architecture-kernel.config file.
Code:
# Copy the config specific to your Architecture and Kernel versions
$ cp configs/armv7-2.6.config .config

"Sounds" like a good opportunity for someone else to play in the sandbox. Watch out for the worms, though.

I hate to think that my AiMesh Nodes will have to be migrated, someday. If I do it right, it shouldn't be too painful, though. This is a step in that direction.

Currently, I don't have any wireless devices that make use of 802.11ax.
they'll work until they don't...I'm really happy with my ac86 - a big step up from the n66 it replaced, but it's also starting to show signs of middle age, much like its owner ;-p
 

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top