# [[OpenNDS]] Dev Setup via [[Debian]] on [[Docker]]
https://hub.docker.com/_/debian
## Attempt 1
```shell
# Open dev folder
cd ~/projects
# Get the docker image
docker pull debian
# Enter the container
docker run -it debian
# Go to home dir
cd
# Update packages
apt update
# Install OpenWrt Debian build system prerequisites
# Documented here:
# https://openwrt.org/docs/guide-developer/build-system/install-buildsystem#debianubuntu
apt install build-essential ccache ecj fastjar file g++ gawk \
gettext git java-propose-classpath libelf-dev libncurses5-dev \
libncursesw5-dev libssl-dev python python2.7-dev python3 unzip wget \
python3-distutils python3-setuptools python3-dev rsync subversion \
swig time xsltproc zlib1g-dev
# (To Philip) if that doesn't work, try adding these too
# Documented here: https://openwrt.org/docs/guide-developer/build-system/install-buildsystem
# apt install asciidoc bash binutils bzip2 flex g++ gawk gcc \
# gettext git-core help2man intltool libelf-dev libncurses5-dev \
# libssl-dev make patch perl-modules python2-dev python3-dev \
# unzip util-linux wget xsltproc zlib1g-dev zlib1g-dev
# Install OpenNDS build system prerequisites
# Documented here (duplicates intentionally left in):
# https://opennds.readthedocs.io/en/stable/compile.html#openwrt-package
apt install git subversion g++ libncurses5-dev gawk zlib1g-dev build-essential
# Clone OpenWrt and the Higher-Brothers fork of OpenNDS:
git clone https://git.openwrt.org/openwrt/openwrt.git
git clone git://github.com/Higher-Brothers/opennds.git
# Run the OpenWrt installation scripts, uninstalling the OpenNDS that comes packaged with OpenWrt by default:
cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
./scripts/feeds uninstall opennds
# Copy the Higher-Brothers OpenNDS package into OpenWrt:
cp -rf ~/opennds/linux_openwrt/opennds ~/openwrt/package/feeds/routing
# Generate config files
make defconfig
# Config, follow the OpenNDS instructions
make menuconfig
# Compile / build
# Optionally add -jN to parallize to N cores,
# e.g. if your computer has 4 cores, run `make -j4`
make
```
This will take a while, possibly a few hours.
### Failure
![[Screen Shot 2021-08-23 at 3.09.28 AM.png]]
```
make[3] -C tools/tar compile
ERROR: tools/tar failed to build.
make -r world: build failed. Please re-run make with -j1 V=s or V=sc for a higher verbosity level to see what's going on
make: *** [/root/openwrt/include/toplevel.mk:230: world] Error 1
```
Verbose output with:
```shell
make -j1 V=s
```
![[Screen Shot 2021-08-23 at 3.14.58 AM.png]]
```
checking whether mknod can create fifo without root privileges... configure: error: in `/root/openwrt/build_dir/host/tar-1.32':
configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check)
See `config.log' for more details
make[3]: *** [Makefile:32: /root/openwrt/build_dir/host/tar-1.32/.configured] Error 1
make[3]: Leaving directory '/root/openwrt/tools/tar'
time: tools/tar/compile#12.10#10.30#25.06
ERROR: tools/tar failed to build.
make[2]: *** [tools/Makefile:158: tools/tar/compile] Error 1
make[2]: Leaving directory '/root/openwrt'
make[1]: *** [tools/Makefile:154: /root/openwrt/staging_dir/host/stamp/.tools_compile_yyynyynnyyyynyyyyyynyynnyyynyyyyyyyyyyyyyyyyynynnyyyyyyyy] Error 2
make[1]: Leaving directory '/root/openwrt'
make: *** [/root/openwrt/include/toplevel.mk:230: world] Error 2
```
With environment variable set:
```shell
FORCE_UNSAFE_CONFIGURE=1 make -j3
```
#### Potential fix: Run *not* as root by creating a user
openwrt/docker/Dockerfile creates a user called `build`:
https://github.com/openwrt/docker/blob/master/Dockerfile
##### How to add a user to a docker container:
https://stackoverflow.com/questions/27701930/how-to-add-users-to-docker-container
```docker
RUN useradd -ms /bin/bash newuser
```
Add to Dockerfile:
```docker
USER newuser
WORKDIR /home/newuser
```
Every command afterwards as well as interactive sessions will be executed as user `newuser`:
```shell
docker run -t -i image
newuser@131b7ad86360:~$
```
### After using M module: OpenNDS fails
```shell
FORCE_UNSAFE_CONFIGURE=1 make -j2
```
![[Screen Shot 2021-08-23 at 3.36.02 PM.png]]