Skip to content

Instantly share code, notes, and snippets.

@i026e
Created October 24, 2020 13:36
Show Gist options
  • Save i026e/6994fb631a029701860dc23d67018536 to your computer and use it in GitHub Desktop.
Save i026e/6994fb631a029701860dc23d67018536 to your computer and use it in GitHub Desktop.
Build redsocks2
#!/usr/bin/bash
set -xe
REDSOCKS_DIR="./redsocks"
PACKAGE_DIR="./debian_package"
VERSION=$(date "+%Y.%m")
# Dependencies
sudo apt install -y git libevent-dev libssl-dev
# Download if necessary
if [ ! -d "${REDSOCKS_DIR}" ]; then
git clone https://github.com/semigodking/redsocks.git
fi
cd "${REDSOCKS_DIR}"
# Clean old binaries and update code
make clean
rm -rf "${PACKAGE_DIR}"
git pull
# Compile
make DISABLE_SHADOWSOCKS=true
## Make Deb Package
# Make directories
mkdir -p "${PACKAGE_DIR}/DEBIAN/"
mkdir -p "${PACKAGE_DIR}/usr/bin/"
mkdir -p "${PACKAGE_DIR}/etc/conf.d/"
mkdir -p "${PACKAGE_DIR}/etc/systemd/system/"
# Copy files
cp "./redsocks2" "${PACKAGE_DIR}/usr/bin/redsocks2"
cp "./redsocks2.service" "${PACKAGE_DIR}/etc/systemd/system/redsocks2.service"
# Add configuration
cat <<EOF > "${PACKAGE_DIR}/etc/redsocks.conf"
base {
// debug: connection progress & client list on SIGUSR1
log_debug = off;
// info: start and end of client session
log_info = on;
// possible `log` values are:
// stderr
// "file:/path/to/file"
// syslog:FACILITY facility is any of "daemon", "local0"..."local7"
//
log = stderr;
// log = "file:/path/to/file";
// log = "syslog:local7";
// detach from console
daemon = on;
// Change uid, gid and root directory, these options require root
// privilegies on startup.
// Note, your chroot may requre /etc/localtime if you write log to syslog.
// Log is opened before chroot & uid changing.
// Debian, Ubuntu and some other distributions use `nogroup` instead of
// `nobody`, so change it according to your system if you want redsocks
// to drop root privileges.
//
// user = nobody;
// group = nobody;
// chroot = "/var/chroot";
// possible `redirector` values are:
// iptables - for Linux
// ipf - for FreeBSD
// pf - for OpenBSD
// generic - some generic redirector that MAY work
//
redirector = iptables;
// Override per-socket values for TCP_KEEPIDLE, TCP_KEEPCNT,
// and TCP_KEEPINTVL. see man 7 tcp for details.
// `redsocks` relies on SO_KEEPALIVE option heavily. */
//tcp_keepalive_time = 0;
//tcp_keepalive_probes = 0;
//tcp_keepalive_intvl = 0;
}
redsocks {
bind = "0.0.0.0:10080";
relay = "127.0.0.1:1080";
type = socks5;
}
tcpdns {
// Transform UDP DNS requests into TCP DNS requests.
// You can also redirect connections to external TCP DNS server to
// REDSOCKS transparent proxy via iptables.
bind = "0.0.0.0:1053"; // Local server to act as DNS server
tcpdns1 = 8.8.4.4; // DNS server that supports TCP DNS requests
tcpdns2 = 8.8.8.8; // DNS server that supports TCP DNS requests
timeout = 4; // Timeout value for TCP DNS requests
}
EOF
cat <<EOF > "${PACKAGE_DIR}/etc/conf.d/redsocks2"
REDSOCKS_CONF="/etc/redsocks.conf"
EOF
cat <<EOF > "${PACKAGE_DIR}/DEBIAN/control"
Package: redsocks2
Architecture: all
Maintainer: @redsocks2
Priority: optional
Version: ${VERSION}
Description: Redsocks2
Depends: libevent-dev, libssl-dev
EOF
cat <<EOF > "${PACKAGE_DIR}/DEBIAN/conffiles"
etc/redsocks.conf
etc/conf.d/redsocks2
etc/systemd/system/redsocks2.service
EOF
cat <<EOF > "${PACKAGE_DIR}/DEBIAN/postinst"
#!/bin/sh
useradd -G dialout,netdev redsocks
mkdir -p -m 777 "/run/redsocks2/"
EOF
chmod 755 "${PACKAGE_DIR}/DEBIAN/postinst"
cat <<EOF > "${PACKAGE_DIR}/DEBIAN/postrm"
#!/bin/sh
service redsocks2 stop
deluser redsocks
rm -rf "/run/redsocks2/"
EOF
chmod 755 "${PACKAGE_DIR}/DEBIAN/postrm"
# Build
dpkg-deb --build "${PACKAGE_DIR}" "redsocks2.deb"
cp *.deb ../
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment