Skip to content

Yicons/qbittorrent-nox-static

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qbittorrent-nox-static

Codacy Badge CodeFactor

There is one bash script for 3 platforms. This script will do these three things on Debian Stable, Ubuntu 18.04/20.04 or Alpine 3.10+ (can be used with docker images):

  • Update the system and install the core build dependencies - Requires root privileges if dependencies are missing.
  • Install and build the qbittorrent-nox dependencies locally with no special privileges required.
  • Build a fully static and portable qbittorrent-nox binary which automatically uses the latest version of all supported dependencies.

Here is an example build profile:

qBittorrent 4.3.4.1 was built with the following libraries:

Qt: 5.15.2
Libtorrent: 1.2.13.0
Boost: 1.76.0
OpenSSL: 1.1.1k
zlib: 1.2.11

This script can be used on any supported system directly or via a docker deployment. As long your system meets the core dependency requirements tested for by the script, the script can be run on that system as a local user.

Debian or Ubuntu platforms

The script creates a fully static qbittorrent-nox binary using libc.

The final result will show this when using ldd

ldd ~/qb-build/bin/qbittorrent-nox

Gives this result:

not a dynamic executable

Alpine Linux platform

The script creates a fully static qbittorrent-nox binary using musl.

The final result will show this when using ldd

ldd ~/qb-build/bin/qbittorrent-nox

Gives this result:

statically linked

Script information

Fully static builds were built on:

Debian 10 (buster) amd64 / arm64 using qemu static + multiarch docker

Alpine Linux 3.12 amd64 / arm64 using qemu static + multiarch docker

Note: GitHub actions use Alpine containers but this could be skipped at the expense of a longer build time (glibc)

Script usage

Follow these instructions to install and use this build tool.

Note: Executing the scripts will configure your build environment and may require a reboot to make sure you can successfully build qbittorrent-nox but will not start the build process until all or a specific module name is passed as an argument to the script.

Use these commands via ssh on your Linux platform.

Debian or Ubuntu or Alpine Linux

User

wget -qO ~/qbittorrent-nox-static.sh https://git.io/qbstatic
chmod 700 ~/qbittorrent-nox-static.sh

For Alpine specifically, you need to install bash to use this script.

apk add bash

To execute the script use this command:

~/qbittorrent-nox-static.sh

docker Debian

docker run -it -v $HOME:/root debian:latest /bin/bash -c 'apt-get update && apt-get install -y curl && cd && curl -sL git.io/qbstatic | bash -s all'

docker Ubuntu

docker run -it -v $HOME:/root ubuntu:latest /bin/bash -c 'apt-get update && apt-get install -y curl && cd && curl -sL git.io/qbstatic | bash -s all'

docker Alpine

docker run -it -v $HOME:/root alpine:latest /bin/ash -c 'apk update && apk add bash curl && cd && curl -sL git.io/qbstatic | bash -s all'

Note: Please see the flag summary section below to see what options you can pass and how to use them

You can modify the installation command by editing this part of the docker command.

bash -s all

For example, to use ICU using -i and optimise for the system CPU using -o:

bash -s all -i -o

Build help

Once the script has successfully configured the platform you can execute the help argument to see how it works and what options you have available to you.

~/qbittorrent-nox-static.sh -h

Flags and arguments summarised

Please use this feature to get help with a script option. Here is what you will see.

Here are a list of available options

 Use: -b  or --build-directory    Help: -h-b  or --help-build-directory
 Use: -d  or --debug              Help: -h-d  or --help-debug
 Use: -bs or --boot-strap         Help: -h-bs or --help-boot-strap
 Use: -i  or --icu                Help: -h-i  or --help-icu
 Use: -lm or --libtorrent-master  Help: -h-lm or --help-libtorrent-master
 Use: -lt or --libtorrent-tag     Help: -h-lt or --help-libtorrent-tag
 Use: -m  or --master             Help: -h-m  or --help-master
 Use: -n  or --no-delete          Help: -h-n  or --help-no-delete
 Use: -o  or --optimize           Help: -h-o  or --help-optimize
 Use: -p  or --proxy              Help: -h-p  or --help-proxy
 Use: -pr or --patch-repo         Help: -h-pr or --help-patch-repo
 Use: -qm or --qbittorrent-master Help: -h-qm or --help-qbittorrent-master
 Use: -qt or --qbittorrent-tag    Help: -h-qt or --help-qbittorrent-tag

Module specific help - flags are used with the modules listed here.

 Use: all or module-name          Usage: ~/qbittorrent-nox-static.sh all -i

 all         - Install all modules
 install     - optional Install the ~/qb-build/completed/qbittorrent-nox binary
 zlib        - required Build zlib locally
 icu         - optional Build ICU locally
 openssl     - required Build openssl locally
 boost       - required Download, extract and build the boost library files
 qtbase      - required Build qtbase locally
 qttools     - required Build qttools locally
 libtorrent  - required Build libtorrent locally with b2
 qbittorrent - required Build qbitorrent locally

Build - default profile

Install all default modules and build qbittorrent-nox to the default build directory.

~/qbittorrent-nox-static.sh all

Build - modules (optional and mostly for debugging and testing)

~/qbittorrent-nox-static.sh module

Supported modules

bison (Debian/Ubuntu only)
gawk (Debian/Ubuntu only)
glibc (Debian/Ubuntu only)
zlib (default)
icu (optional on either platform)
openssl (default)
boost (default)
qtbase (default)
qttools (default)
libtorrent (default)
qbittorrent (default)

Build - paths

By default the script will built to a hard coded path defined by the scripts $install_dir variable as to avoid installing files to a server and causing conflicts.

Note: This path is relative to the scripts location by default.

qbittorrent-build

You can modify this dynamically with the -b argument

./qbittorrent-nox-static.sh all -b "/usr/local"

Patching

The script supports the automatic patching of libtorrent and qbittorrent when building, providing certain conditions are met. You can do it in two ways.

Local patching via boot strapping

Using this command: ~/qbittorrent-nox-static.sh -bs the script will create the required directory structure using the current defaults.

qb-build/patches/qbittorrent/4.3.4.1
qb-build/patches/libtorrent/v1.2.12

You can change the defaults by using the qt and lt switches to specify a tag. So for example if you used this command:

~/qbittorrent-nox-static.sh -qt master -lt RC_2_0 -bs

The boot strapped directory structure will look like this instead:

qb-build/patches/qbittorrent/master
qb-build/patches/libtorrent/RC_2_0

Place your patch file named patch inside the relevant directories. So it would look something like this:

qb-build/patches/qbittorrent/4.3.4.1/patch
qb-build/patches/libtorrent/v1.2.12/patch

Then the patch file will be automatically matched to the tag used by the script and loaded.

Git based patching

Instead of a local patch you can use github hosted patch files. Your patches need to be hosted in the root of the repo like this:

patches/qbittorrent/master/patch
patches/qbittorrent/4.3.4.1/patch
patches/qbittorrent/4.3.3/patch
patches/libtorrent/RC_2_0/patch
patches/libtorrent/RC_1_2/patch
patches/libtorrent/v1.2.12/patch

The all you do is use the pr switch when using the script. The repo URL is abbreviated to your username and repo:

~/qbittorrent-nox-static.sh all -pr username/repo

Then the patch file will be automatically matched to the tag used by the script and loaded.

How to make a patch

Using qbittorrent as an example we will edit the src/base/bittorrent/session.cpp to apply some session defaults.

Download the relevant git repo:

git clone --no-tags --single-branch --branch release-4.3.4.1 --shallow-submodules --recurse-submodules --depth 1 https://github.com/qbittorrent/qBittorrent.git

Copy the file that we need to edit to our home directory.

cp qBittorrent/src/base/bittorrent/session.cpp ~/session.cpp

Now edit the ~/session.cpp. Once you have finished making your changes you can create a patch file using this command

diff -Naru qBittorrent/src/base/bittorrent/session.cpp ~/session.cpp > ~/patch

Then you place that patch file in the matching tag directory.

patches/qbittorrent/4.3.4.1/patch

Github Actions

There are some actions created that will build the binary and create and artifact. They can be viewed here

https://github.com/userdocs/qbittorrent-nox-static/actions

All these action are triggered manually by clicking on the action running the workflow.

You can fork the repo and build it yourself.

Patching will work with actions as long as you configure it correctly.

These the currently available actions.

qb-amd64
qb-amd64-patch
qb-amd64-icu
qb-amd64-icu-patch
qb-arm64
qb-arm64-patch
qb-arm64-icu
qb-arm64-icu-patch
sh-checker

Installation

Once the script has successfully built qbittorrent-nox you can install it using this command:

./qbittorrent-nox-static.sh install

Note: If you built to a custom directory you will need to specify this to the install command using the -b argument.

./qbittorrent-nox-static.sh install -b "/path/to/built/binary"

The default installation path is determined by type of user executing the script.

Root - Built to - qbittorrent-build

Root - Optionally installed to /usr/local

Note: A local user still requires the core dependencies are installed to proceed.

Local user - Built to - qbittorrent-build

Local user - Optionally installed to $HOME/bin

Download and install static builds

Configuration

If you want to configure qBittorrent before you start it you this method

Create the default configuration directory.

mkdir -p ~/.config/qBittorrent

Create the configuration file.

touch ~/.config/qBittorrent/qBittorrent.conf

Edit the file

nano ~/.config/qBittorrent/qBittorrent.conf

Add this. Make sure to change your web ui port.

[LegalNotice]
Accepted=true

[Preferences]
WebUI\Port=PORT

glibc static

amd64

mkdir -p ~/bin && source ~/.profile
wget -qO ~/bin/qbittorrent-nox https://github.com/userdocs/qbittorrent-nox-static/releases/download/release-4.3.4.1_v1.2.13/amd64-glibc-qbittorrent-nox
chmod 700 ~/bin/qbittorrent-nox

Now you just run it and enjoy!

~/bin/qbittorrent-nox

musl static

amd64:

mkdir -p ~/bin && source ~/.profile
wget -qO ~/bin/qbittorrent-nox https://github.com/userdocs/qbittorrent-nox-static/releases/download/release-4.3.4.1_v1.2.13/amd64-musl-qbittorrent-nox
chmod 700 ~/bin/qbittorrent-nox

Now you just run it and enjoy!

~/bin/qbittorrent-nox

Default login:

username: admin
password: adminadmin

Some key start-up arguments to help you along. Using the command above with no arguments will loads the defaults or the settings defined in the ~/.config/qBittorrent/qBittorrent.conf

Usage:
    ./qbittorrent-nox [options][(<filename> | <url>)...]
Options:
    \-v | --version                Display program version and exit
    \-h | --help                   Display this help message and exit
    \--webui-port=<port>           Change the Web UI port
    \-d | --daemon                 Run in daemon-mode (background)
    \--profile=<dir>               Store configuration files in <dir>
    \--configuration=<name>        Store configuration files in directories
                                   qBittorrent\_<name>
    \--relative-fastresume         Hack into libtorrent fastresume files and make
                                   file paths relative to the profile directory
    files or URLs                  Download the torrents passed by the user

Options when adding new torrents:
    \--save-path=<path>            Torrent save path
    \--add-paused=&lt;true|false>  Add torrents as started or paused
    \--skip-hash-check             Skip hash check
    \--category=<name>             Assign torrents to category. If the category
                                   doesn't exist, it will be created.
    \--sequential                  Download files in sequential order
    \--first-and-last              Download first and last pieces first
    \--skip-dialog=&lt;true|false> Specify whether the "Add New Torrent" dialog
                                   opens when adding a torrent.

Option values may be supplied via environment variables. For option named
'parameter-name', environment variable name is 'QBT_PARAMETER_NAME' (in upper
case, '-' replaced with '_'). To pass flag values, set the variable to '1' or
'TRUE'. For example, to disable the splash screen:
QBT_NO_SPLASH=1 ./qbittorrent-nox
Command line parameters take precedence over environment variables

Second instance

When you simply call the binary using ~/qbittorrent-nox it will look for it's configuration in ~/.config/qbittorrent.

If you would like to run a second instance using another configuration you can do so like this

~/bin/qbittorrent-nox --configuration=NAME

This will create a new configuration directory using this suffix.

~/.config/qbittorrent_NAME

You will also need a custom nginx proxypass and systemd service.

And you can now configure this instance separately.

Nginx proxypass

location /qbittorrent/ {
	proxy_pass               http://127.0.0.1:8080/;
	proxy_http_version       1.1;
	proxy_set_header         X-Forwarded-Host        $http_host;
	http2_push_preload on; # Enable http2 push

	# The following directives effectively nullify Cross-site request forgery (CSRF)
	# protection mechanism in qBittorrent, only use them when you encountered connection problems.
	# You should consider disable "Enable Cross-site request forgery (CSRF) protection"
	# setting in qBittorrent instead of using these directives to tamper the headers.
	# The setting is located under "Options -> WebUI tab" in qBittorrent since v4.1.2.
	#proxy_hide_header       Referer;
	#proxy_hide_header       Origin;
	#proxy_set_header        Referer                 '';
	#proxy_set_header        Origin                  '';

	# Not needed since qBittorrent v4.1.0
	#add_header              X-Frame-Options         "SAMEORIGIN";
}

Systemd service

Location for the systemd service file:

/etc/systemd/system/qbittorrent.service

Modify the path to the binary and your local username.

[Unit]
Description=qBittorrent-nox service
Wants=network-online.target
After=network-online.target nss-lookup.target

[Service]
Type=exec
User=qbtuser
ExecStart=/usr/local/bin/qbittorrent-nox
Restart=on-failure
SyslogIdentifier=qbittorrent-nox

[Install]
WantedBy=multi-user.target

After any changes to the services reload using this command.

systemctl daemon-reload

Now you can enable the service

systemctl enable --now qbittorrent.service

Now you can use these commands

systemctl stop qbittorrent
systemctl start qbittorrent
systemctl restart qbittorrent

Systemd local user service

You can also use a local systemd service.

~/.config/systemd/user/qbittorrent.service

You can use this configuration with no modification required.

[Unit]
Description=qbittorrent
Wants=network-online.target
After=network-online.target nss-lookup.target

[Service]
Type=exec
ExecStart=%h/bin/qbittorrent-nox
Restart=on-failure
SyslogIdentifier=qbittorrent-nox

[Install]
WantedBy=default.target

After any changes to the services reload using this command.

systemctl --user daemon-reload

Now you can enable the service

systemctl --user enable --now qbittorrent.service

Now you can use these commands

systemctl --user stop qbittorrent
systemctl --user start qbittorrent
systemctl --user restart qbittorrent

Credits

Inspired by these gists

https://gist.github.com/notsure2

About

A build script for qBittorent nox static.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 100.0%