--- /dev/null
+#
+# Copyright (C) 2009-2010 OpenWrt.org
+# Copyright (C) 2009 Jakob Pfeiffer
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=c-ares
+PKG_VERSION:=1.15.0
+PKG_RELEASE:=4
+PKG_LICENSE:=MIT
+PKG_CPE_ID:=cpe:/a:c-ares_project:c-ares
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://c-ares.haxx.se/download
+PKG_HASH:=6cdb97871f2930530c97deb7cf5c8fa4be5a0b02c7cea6e7c7667672a39d6852
+
+PKG_FIXUP:=autoreconf
+PKG_INSTALL:=1
+
+include $(INCLUDE_DIR)/package.mk
+
+TARGET_CPPFLAGS += $(filter -D%,$(TARGET_CFLAGS))
+TARGET_CFLAGS := $(filter-out -D%,$(TARGET_CFLAGS))
+
+define Package/libcares
+ SECTION:=libs
+ CATEGORY:=Libraries
+ TITLE:=Library for asyncronous DNS Requests (including name resolves)
+ URL:=http://c-ares.haxx.se/
+ MAINTAINER:=Karl Palsson <karlp@etactica.com>
+endef
+
+define Package/libcares/description
+ c-ares is a C library for asynchronous DNS requests (including name resolves)
+
+C89 compatibility, MIT licensed, builds for and runs on POSIX, Windows,
+Netware, Android and many more operating systems.
+
+endef
+
+define Package/libcares/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/*.so.* $(1)/usr/lib/
+endef
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)
+ $(CP) $(PKG_INSTALL_DIR)/* $(1)/
+endef
+
+$(eval $(call BuildPackage,libcares))
--- /dev/null
+if PACKAGE_libssh2
+
+choice
+ prompt "Choose crypto backend"
+ default LIBSSH2_MBEDTLS
+
+ config LIBSSH2_MBEDTLS
+ bool "mbedtls"
+
+ config LIBSSH2_OPENSSL
+ bool "openssl"
+
+endchoice
+
+endif
--- /dev/null
+#
+# Copyright (C) 2015-2018 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=libssh2
+PKG_VERSION:=1.8.2
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://www.libssh2.org/download
+PKG_HASH:=088307d9f6b6c4b8c13f34602e8ff65d21c2dc4d55284dfe15d502c4ee190d67
+
+PKG_FIXUP:=autoreconf
+
+PKG_INSTALL:=1
+
+PKG_LICENSE:=BSD
+PKG_LICENSE_FILES:=COPYING
+PKG_CPE_ID:=cpe:/a:libssh2:libssh2
+
+PKG_CONFIG_DEPENDS:= \
+ CONFIG_LIBSSH2_MBEDTLS \
+ CONFIG_LIBSSH2_OPENSSL
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/libssh2
+ SECTION:=libs
+ CATEGORY:=Libraries
+ TITLE:=SSH2 library
+ URL:=https://www.libssh2.org/
+ DEPENDS:=+LIBSSH2_MBEDTLS:libmbedtls +LIBSSH2_OPENSSL:libopenssl +zlib
+ MAINTAINER:=Jiri Slachta <jiri@slachta.eu>
+endef
+
+define Package/libssh2/description
+ libssh2 is a client-side C library implementing the SSH2 protocol.
+endef
+
+define Package/libssh2/config
+ source "$(SOURCE)/Config.in"
+endef
+
+CONFIGURE_ARGS += \
+ --disable-examples-build \
+ --disable-silent-rules \
+ $(if $(CONFIG_LIBSSH2_MBEDTLS),--with-mbedtls --with-libmbedtls-prefix=$(STAGING_DIR)/usr) \
+ $(if $(CONFIG_LIBSSH2_OPENSSL),--with-openssl --with-libssl-prefix=$(STAGING_DIR)/usr) \
+ --with-libz-prefix=$(STAGING_DIR)/usr
+
+define Build/InstallDev
+ $(INSTALL_DIR) $(1)/usr/include
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(INSTALL_DIR) $(1)/usr/lib/pkgconfig
+ $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include/
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libssh2.so* $(1)/usr/lib/
+ $(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libssh2.pc $(1)/usr/lib/pkgconfig/
+endef
+
+define Package/libssh2/install
+ $(INSTALL_DIR) $(1)/usr/lib
+ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libssh2.so* $(1)/usr/lib/
+endef
+
+$(eval $(call BuildPackage,libssh2))
--- /dev/null
+--- a/acinclude.m4
++++ b/acinclude.m4
+@@ -386,9 +386,9 @@ AC_DEFUN([LIBSSH2_CHECKFOR_MBEDTLS], [
+
+ old_LDFLAGS=$LDFLAGS
+ old_CFLAGS=$CFLAGS
+- if test -n "$use_mbedtls" && test "$use_mbedtls" != "no"; then
+- LDFLAGS="$LDFLAGS -L$use_mbedtls/lib"
+- CFLAGS="$CFLAGS -I$use_mbedtls/include"
++ if test -n "$with_libmbedtls_prefix" && test "$use_mbedtls" != "no"; then
++ LDFLAGS="$LDFLAGS -L$with_libmbedtls_prefix/lib"
++ CFLAGS="$CFLAGS -I$with_libmbedtls_prefix/include"
+ fi
+
+ AC_LIB_HAVE_LINKFLAGS([mbedtls], [], [
+@@ -412,9 +412,9 @@ AC_DEFUN([LIBSSH2_CHECKFOR_GCRYPT], [
+
+ old_LDFLAGS=$LDFLAGS
+ old_CFLAGS=$CFLAGS
+- if test -n "$use_libgcrypt" && test "$use_libgcrypt" != "no"; then
+- LDFLAGS="$LDFLAGS -L$use_libgcrypt/lib"
+- CFLAGS="$CFLAGS -I$use_libgcrypt/include"
++ if test -n "$with_libgcrypt_prefix" && test "$use_libgcrypt" != "no"; then
++ LDFLAGS="$LDFLAGS -L$with_libgcrypt_prefix/lib"
++ CFLAGS="$CFLAGS -I$with_libgcrypt_prefix/include"
+ fi
+ AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [
+ #include <gcrypt.h>
--- /dev/null
+diff --git a/src/openssl.c b/src/openssl.c
+index 4f63ef9..411f9f6 100644
+--- a/src/openssl.c
++++ b/src/openssl.c
+@@ -1062,6 +1062,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
+ "Unable to extract public key from private key "
+ "file: Unable to open private key file");
+ }
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ if (!EVP_get_cipherbyname("des")) {
+ /* If this cipher isn't loaded it's a pretty good indication that none
+ * are. I have *NO DOUBT* that there's a better way to deal with this
+@@ -1070,6 +1071,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
+ */
+ OpenSSL_add_all_ciphers();
+ }
++#endif
+ BIO_reset(bp);
+ pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void*)passphrase);
+ BIO_free(bp);
+@@ -1138,6 +1140,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
+ if (!bp) {
+ return -1;
+ }
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ if (!EVP_get_cipherbyname("des")) {
+ /* If this cipher isn't loaded it's a pretty good indication that none
+ * are. I have *NO DOUBT* that there's a better way to deal with this
+@@ -1146,6 +1149,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session,
+ */
+ OpenSSL_add_all_ciphers();
+ }
++#endif
+ BIO_reset(bp);
+ pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void*)passphrase);
+ BIO_free(bp);
+diff --git a/src/openssl.h b/src/openssl.h
+index 3ca71fa..7a89793 100644
+--- a/src/openssl.h
++++ b/src/openssl.h
+@@ -40,7 +40,9 @@
+ #include <openssl/opensslconf.h>
+ #include <openssl/sha.h>
+ #include <openssl/rsa.h>
++#ifndef OPENSSL_NO_ENGINE
+ #include <openssl/engine.h>
++#endif
+ #ifndef OPENSSL_NO_DSA
+ #include <openssl/dsa.h>
+ #endif
+@@ -226,10 +228,18 @@ int _libssh2_md5_init(libssh2_md5_ctx *ctx);
+ #define libssh2_hmac_cleanup(ctx) HMAC_cleanup(ctx)
+ #endif
+
++#if OPENSSL_VERSION_NUMBER < 0x10100000L
++#ifndef OPENSSL_NO_ENGINE
+ #define libssh2_crypto_init() \
+ OpenSSL_add_all_algorithms(); \
+ ENGINE_load_builtin_engines(); \
+ ENGINE_register_all_complete()
++#else
++#define libssh2_crypto_init() OpenSSL_add_all_algorithms()
++#endif
++#else
++#define libssh2_crypto_init()
++#endif
+
+ #define libssh2_crypto_exit()
+
--- /dev/null
+menu "Aria2 Configuration"
+ depends on PACKAGE_aria2
+
+choice
+ prompt "SSL Library"
+ default ARIA2_OPENSSL
+
+config ARIA2_OPENSSL
+ bool "OpenSSL"
+
+config ARIA2_GNUTLS
+ bool "GnuTLS"
+
+config ARIA2_NOSSL
+ bool "No SSL Support"
+
+endchoice
+
+choice
+ prompt "Crypto Library"
+ depends on !ARIA2_OPENSSL
+ default ARIA2_NOCRYPTO
+
+config ARIA2_NETTLE
+ bool "Nettle"
+
+config ARIA2_LIBGCRYPT
+ bool "Libgcrypt"
+
+config ARIA2_NOCRYPTO
+ bool "No Crypto Library"
+
+endchoice
+
+choice
+ prompt "XML Library"
+ default ARIA2_NOXML
+
+config ARIA2_LIBXML2
+ bool "Libxml2"
+
+config ARIA2_EXPAT
+ bool "Expat"
+
+config ARIA2_NOXML
+ bool "No XML Library"
+
+endchoice
+
+config ARIA2_GMP
+ bool "GNU Multiple Precision Arithmetic Library"
+ depends on ARIA2_NETTLE
+ default n
+
+config ARIA2_BITTORRENT
+ bool "Enable Bittorrent Support"
+ depends on ARIA2_OPENSSL || ARIA2_LIBGCRYPT || \
+ (ARIA2_NETTLE && ARIA2_GMP)
+ default y
+
+config ARIA2_METALINK
+ bool "Enable Metalink Support"
+ depends on !ARIA2_NOXML
+ default n
+
+config ARIA2_SFTP
+ bool "Enable SFTP Support"
+ default n
+
+config ARIA2_ASYNC_DNS
+ bool "Enable Async DNS Support"
+ default n
+
+config ARIA2_COOKIE
+ bool "Enable Firefox3/Chromium Cookie Support"
+ default n
+
+config ARIA2_WEBSOCKET
+ bool "Enable JSON-RPC over WebSocket Support"
+ depends on ARIA2_OPENSSL || ARIA2_LIBGCRYPT || ARIA2_NETTLE
+ default y
+
+endmenu
--- /dev/null
+#
+# Copyright (C) 2012-2018 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=aria2
+PKG_VERSION:=1.34.0
+PKG_RELEASE:=6
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
+PKG_SOURCE_URL:=https://github.com/aria2/aria2/releases/download/release-$(PKG_VERSION)/
+PKG_HASH:=3a44a802631606e138a9e172a3e9f5bcbaac43ce2895c1d8e2b46f30487e77a3
+PKG_INSTALL:=1
+PKG_BUILD_PARALLEL:=1
+PKG_USE_MIPS16:=0
+
+PKG_MAINTAINER:=Imre Kaloz <kaloz@openwrt.org>, \
+ Hsing-Wang Liao <kuoruan@gmail.com>
+PKG_LICENSE:=GPLv2
+PKG_LICENSE_FILES:=COPYING
+
+PKG_CONFIG_DEPENDS := \
+ CONFIG_ARIA2_NOSSL \
+ CONFIG_ARIA2_OPENSSL \
+ CONFIG_ARIA2_GNUTLS \
+ CONFIG_ARIA2_NOCRYPTO \
+ CONFIG_ARIA2_NETTLE \
+ CONFIG_ARIA2_LIBGCRYPT \
+ CONFIG_ARIA2_LIBXML2 \
+ CONFIG_ARIA2_EXPAT \
+ CONFIG_ARIA2_GMP \
+ CONFIG_ARIA2_BITTORRENT \
+ CONFIG_ARIA2_METALINK \
+ CONFIG_ARIA2_SFTP \
+ CONFIG_ARIA2_ASYNC_DNS \
+ CONFIG_ARIA2_COOKIE \
+ CONFIG_ARIA2_WEBSOCKET
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/aria2/config
+ source "$(SOURCE)/Config.in"
+endef
+
+define Package/aria2
+ SECTION:=net
+ CATEGORY:=Network
+ SUBMENU:=File Transfer
+ TITLE:=lightweight download utility
+ URL:=https://aria2.github.io/
+ DEPENDS:=+zlib +libstdcpp +ARIA2_OPENSSL:libopenssl +ARIA2_GNUTLS:libgnutls \
+ +ARIA2_NETTLE:libnettle +ARIA2_LIBGCRYPT:libgcrypt +ARIA2_GMP:libgmp \
+ +ARIA2_LIBXML2:libxml2 +ARIA2_EXPAT:libexpat +ARIA2_SFTP:libssh2 \
+ +ARIA2_ASYNC_DNS:libcares +ARIA2_COOKIE:libsqlite3
+ USERID:=aria2=6800:aria2=6800
+endef
+
+define Package/aria2/description
+ aria2 is a lightweight multi-protocol & multi-source command-line download
+ utility
+endef
+
+CONFIGURE_ARGS += \
+ --disable-nls \
+ $(if $(CONFIG_ARIA2_NOSSL),--disable,--enable)-ssl \
+ $(if $(CONFIG_ARIA2_BITTORRENT),--enable,--disable)-bittorrent \
+ $(if $(CONFIG_ARIA2_METALINK),--enable,--disable)-metalink \
+ $(if $(CONFIG_ARIA2_WEBSOCKET),--enable,--disable)-websocket \
+ $(if $(CONFIG_ARIA2_OPENSSL),--with,--without)-openssl \
+ $(if $(CONFIG_ARIA2_GNUTLS),--with,--without)-gnutls \
+ $(if $(CONFIG_ARIA2_NETTLE),--with,--without)-libnettle \
+ $(if $(CONFIG_ARIA2_LIBGCRYPT),--with,--without)-libgcrypt \
+ $(if $(CONFIG_ARIA2_GMP),--with,--without)-libgmp \
+ $(if $(CONFIG_ARIA2_LIBXML2),--with,--without)-libxml2 \
+ $(if $(CONFIG_ARIA2_EXPAT),--with,--without)-libexpat \
+ $(if $(CONFIG_ARIA2_SFTP),--with,--without)-libssh2 \
+ $(if $(CONFIG_ARIA2_ASYNC_DNS),--with,--without)-libcares \
+ $(if $(CONFIG_ARIA2_COOKIE),--with,--without)-sqlite3 \
+ --without-libuv \
+ --with-libz
+
+TARGET_CXXFLAGS += -ffunction-sections -fdata-sections -flto
+TARGET_LDFLAGS += -Wl,--gc-sections -flto
+
+define Package/aria2/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/aria2c $(1)/usr/bin
+
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/aria2.init $(1)/etc/init.d/aria2
+
+ $(INSTALL_DIR) $(1)/etc/config
+ $(INSTALL_CONF) ./files/aria2.conf $(1)/etc/config/aria2
+endef
+
+$(eval $(call BuildPackage,aria2))
--- /dev/null
+
+# You can use most aria2 command-line options, replace '-' with '_'.
+# eg. 'rpc-secret' ==> 'rpc_secret'
+#
+# We do not support all options at this time. But you can add any option
+# with 'list extra_settings'.
+#
+# You can also add new config sections to define multi instance.
+#
+config aria2 'main'
+ option enabled '0'
+ option user 'aria2'
+ option dir '/mnt/sda1/aria2'
+ option config_dir '/var/etc/aria2'
+ option bt_enable_lpd 'true'
+ option enable_dht 'true'
+ option follow_torrent 'true'
+ option file_allocation 'none'
+ option save_session_interval '30'
+
+ # Add addition Headers here.
+ # eg. list header 'Content-Encoding: gzip'
+ list header ''
+
+ # Add BT trackers here.
+ # eg. list bt_tracker 'http://tracker.example.com/announce'
+ list bt_tracker ''
+
+ # Add extra settings here.
+ # eg. list extra_settings 'option=value'
+ list extra_settings ''
--- /dev/null
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2016-2017 Hsing-wang Liao <kuoruan@gmail.com>
+# Licensed to the public under the Apache License 2.0.
+
+START=99
+USE_PROCD=1
+
+NAME=aria2
+PROG=/usr/bin/aria2c
+
+_info() {
+ logger -p daemon.info -t "$NAME" "$*"
+}
+
+_err() {
+ logger -p daemon.err -t "$NAME" "$*"
+}
+
+_make_dir() {
+ local d
+ for d in "$@"; do
+ if [ ! -d "$d" ]; then
+ mkdir -p "$d" 2>/dev/null || return 1
+ fi
+ done
+
+ return 0
+}
+
+_create_file() {
+ touch "$@" 2>/dev/null
+}
+
+_change_owner() {
+ local u="$1"; shift
+
+ local d
+ for d in "$@"; do
+ if [ -f "$d" ]; then
+ chown "$u" "$d" 2>/dev/null || return 1
+ elif [ -d "$d" ]; then
+ chown -R "$u" "$d" 2>/dev/null || return 1
+ fi
+ done
+
+ return 0
+}
+
+_change_file_mode() {
+ local mod="$1"; shift
+ chmod "$mod" "$@" 2>/dev/null
+}
+
+_reset_dir_mode() {
+ local d
+ for d in "$@"; do
+ if [ -d "$d" ]; then
+ find "$d" -type d -exec chmod 755 {} \; 2>/dev/null
+ find "$d" -type f -exec chmod 644 {} \; 2>/dev/null
+ fi
+ done
+}
+
+append_options() {
+ local o; local v
+ for o in "$@"; do
+ v="$(eval echo "\$$o")"
+ [ -n "$v" ] && \
+ echo "${o//_/-}=$v" >>"$config_file_tmp"
+ done
+}
+
+append_setting() {
+ local s="$1"
+ [ -n "$s" ] && \
+ echo "$s" >>"$config_file_tmp"
+}
+
+append_header() {
+ local h="$1"
+ [ -n "$h" ] && \
+ echo "header=\"$h\"" >>"$config_file_tmp"
+}
+
+aria2_validate() {
+ uci_load_validate "$NAME" aria2 "$1" "$2" \
+ 'enabled:bool:0' \
+ 'enable_logging:bool' \
+ 'enable_proxy:bool' \
+ 'config_dir:string:/var/etc/aria2' \
+ 'user:string' \
+ 'all_proxy:string' \
+ 'all_proxy_passwd:string' \
+ 'all_proxy_user:string' \
+ 'auto_save_interval:range(0,600)' \
+ 'bt_enable_lpd:or("true","false")' \
+ 'bt_detach_seed_only:or("true","false")' \
+ 'bt_load_saved_metadata:or("true","false")' \
+ 'bt_prioritize_piece:string' \
+ 'bt_max_open_files:uinteger' \
+ 'bt_max_peers:uinteger' \
+ 'bt_remove_unselected_file:or("true","false")' \
+ 'bt_request_peer_speed_limit:string' \
+ 'bt_save_metadata:or("true","false")' \
+ 'bt_seed_unverified:or("true","false")' \
+ 'bt_stop_timeout:uinteger' \
+ 'bt_tracker:list(string)' \
+ 'ca_certificate:file' \
+ 'certificate:file' \
+ 'check_certificate:or("true","false"):true' \
+ 'check_integrity:or("true","false")' \
+ 'connect_timeout:uinteger' \
+ 'dht_listen_port:string' \
+ 'dir:string' \
+ 'disable_ipv6:or("true","false")' \
+ 'disk_cache:string' \
+ 'enable_dht:or("true","false"):true' \
+ 'enable_dht6:or("true","false")' \
+ 'enable_peer_exchange:or("true","false")' \
+ 'event_poll:or("epoll","kqueue","port","poll","select")' \
+ 'file_allocation:or("none","prealloc","trunc","falloc")' \
+ 'follow_torrent:or("true","false","mem")' \
+ 'force_save:or("true","false")' \
+ 'http_accept_gzip:or("true","false")' \
+ 'http_no_cache:or("true","false")' \
+ 'listen_port:string' \
+ 'log:string' \
+ 'log_level:or("debug","info","notice","warn","error")' \
+ 'lowest_speed_limit:string' \
+ 'max_concurrent_downloads:uinteger' \
+ 'max_connection_per_server:uinteger' \
+ 'max_download_limit:string' \
+ 'max_overall_download_limit:string' \
+ 'max_overall_upload_limit:string' \
+ 'max_tries:uinteger' \
+ 'max_upload_limit:string' \
+ 'min_split_size:string' \
+ 'pause:or("true","false")' \
+ 'pause_metadata:or("true","false")' \
+ 'peer_id_prefix:string' \
+ 'private_key:file' \
+ 'retry_wait:uinteger' \
+ 'rpc_auth_method:or("none","user_pass","token")' \
+ 'rpc_certificate:file' \
+ 'rpc_listen_port:range(1024,65535)' \
+ 'rpc_passwd:string' \
+ 'rpc_private_key:file' \
+ 'rpc_secret:string' \
+ 'rpc_secure:or("true","false")' \
+ 'rpc_user:string' \
+ 'save_session_interval:uinteger' \
+ 'seed_ratio:ufloat' \
+ 'seed_time:ufloat' \
+ 'split:uinteger' \
+ 'timeout:uinteger' \
+ 'user_agent:string'
+}
+
+aria2_start() {
+ local section="$1"
+ [ "$2" = "0" ] || { _err "Validation failed."; return 1; }
+
+ [ "$enabled" = "1" ] || { _info "Instance \"$section\" disabled."; return 1; }
+ [ -n "$dir" ] || { _err "Please set download dir."; return 1; }
+ [ -d "$dir" ] || { _err "Please create download dir first."; return 1; }
+
+ config_file="$config_dir/$NAME.conf.$section"
+ config_file_tmp="$config_dir/$NAME.conf.tmp"
+ session_file="$config_dir/$NAME.session.$section"
+
+ _make_dir "$config_dir" || {
+ _err "Can't create config dir: $config_dir"
+ return 1
+ }
+
+ _create_file "$session_file" "$config_file" "$config_file_tmp" || {
+ _err "Can't create files: $session_file, $config_file, $config_file_tmp"
+ return 1
+ }
+
+ # create tmp file
+ cat >"$config_file_tmp" <<-EOF
+ # Auto generated file, changes to this file will be lost.
+ EOF
+
+ append_setting "dir=$dir"
+ append_setting "enable-rpc=true"
+ append_setting "rpc-allow-origin-all=true"
+ append_setting "rpc-listen-all=true"
+ append_setting "quiet=true"
+ append_setting "continue=true"
+ append_setting "input-file=$session_file"
+ append_setting "save-session=$session_file"
+
+ if [ -z "$enable_logging" ]; then
+ append_options "log" "log_level"
+ elif [ "$enable_logging" = "1" ]; then
+ log=${log:-"/var/log/aria2.log"}
+
+ local log_dir
+ log_dir="$(dirname "$log")"
+
+ _make_dir "$log_dir" || {
+ _err "Can't create log dir: $log_dir"
+ return 1
+ }
+
+ # create or clear log file
+ echo >"$log"
+
+ append_setting "log=$log"
+ append_options "log_level"
+ fi
+
+ if [ -z "$enable_proxy" ] || [ "$enable_proxy" = "1" ]; then
+ append_options "all_proxy" "all_proxy_user" "all_proxy_passwd"
+ fi
+
+ unset_auth_method() {
+ uci -q batch <<-EOF
+ set $NAME.$section.rpc_auth_method=""
+ commit $NAME
+ EOF
+ }
+
+ if [ -z "$rpc_auth_method" ]; then
+ if [ -n "$rpc_secret" ]; then
+ append_setting "rpc-secret=$rpc_secret"
+ elif [ -n "$rpc_user" ]; then
+ append_setting "rpc-user=$rpc_user"
+ append_setting "rpc-passwd=$rpc_passwd"
+ else
+ _info "It is recommended to set RPC secret."
+ fi
+ elif [ "$rpc_auth_method" = "token" ]; then
+ if [ -n "$rpc_secret" ]; then
+ append_setting "rpc-secret=$rpc_secret"
+ else
+ unset_auth_method
+ fi
+ elif [ "$rpc_auth_method" = "user_pass" ]; then
+ if [ -n "$rpc_user" ]; then
+ append_setting "rpc-user=$rpc_user"
+ append_setting "rpc-passwd=$rpc_passwd"
+ else
+ _info "Please set RPC user."
+ unset_auth_method
+ fi
+ fi
+
+ if [ ."$rpc_secure" = ."true" ] && [ -n "$rpc_certificate" ]; then
+ append_setting "rpc-secure=true"
+ append_options "rpc_certificate" "rpc_private_key"
+ fi
+
+ if [ ."$check_certificate" = ."true" ]; then
+ append_setting "check-certificate=true"
+ append_options "ca_certificate"
+ elif [ ."$check_certificate" = ."false" ]; then
+ append_setting "check-certificate=false"
+ fi
+
+ if [ ."$enable_dht" = ."true" ]; then
+ dht_file="$config_dir/dht.dat.$section"
+ _create_file "$dht_file" || {
+ _err "Can't create DHT file: $dht_file"
+ return 1
+ }
+
+ append_setting "enable-dht=true"
+ append_setting "dht-file-path=$dht_file"
+ fi
+
+ if [ ."$enable_dht6" = ."true" ] && [ ."$disable_ipv6" != ."true" ]; then
+ dht6_file="$config_dir/dht6.dat.$section"
+ _create_file "$dht6_file" || {
+ _err "Can't create DHT6 file: $dht6_file"
+ return 1
+ }
+
+ append_setting "enable-dht6=true"
+ append_setting "dht-file-path6=$dht6_file"
+ fi
+
+ if [ -n "$bt_tracker" ]; then
+ local bt_tracker_list; local t
+ for t in $bt_tracker; do
+ if [ -z "$bt_tracker_list" ]; then
+ bt_tracker_list="$t"
+ else
+ bt_tracker_list="$bt_tracker_list,$t"
+ fi
+ done
+
+ append_setting "bt-tracker=$bt_tracker_list"
+ fi
+
+ append_options "auto_save_interval" "bt_enable_lpd" "bt_max_open_files" "bt_max_peers" \
+ "bt_remove_unselected_file" "bt_request_peer_speed_limit" "bt_prioritize_piece" \
+ "bt_stop_timeout" "bt_detach_seed_only" "bt_save_metadata" "bt_load_saved_metadata" \
+ "bt_seed_unverified" "certificate" "check_integrity" "connect_timeout" "dht_listen_port" \
+ "disable_ipv6" "disk_cache" "enable_peer_exchange" "event_poll" "file_allocation" \
+ "follow_torrent" "force_save" "http_accept_gzip" "http_no_cache" "listen_port" \
+ "lowest_speed_limit" "max_concurrent_downloads" "max_connection_per_server" \
+ "max_download_limit" "max_overall_download_limit" "max_overall_upload_limit" "max_tries" \
+ "max_upload_limit" "min_split_size" "pause" "pause_metadata" "peer_id_prefix" "private_key" \
+ "retry_wait" "rpc_listen_port" "save_session_interval" "seed_ratio" "seed_time" "split" "timeout" \
+ "user_agent"
+
+ config_list_foreach "$section" "header" append_header
+ config_list_foreach "$section" "extra_settings" append_setting
+
+ sed '/^$/d' "$config_file_tmp" >"$config_file"
+ rm -f "$config_file_tmp"
+
+ _reset_dir_mode "$config_dir"
+ _change_file_mode 600 "$config_file"
+
+ if [ -n "$user" ]; then
+ if ( user_exists "$user" && _change_owner "$user" "$config_dir" "$log" ); then
+ _info "Aria2 will run with user '$user'."
+ if [ "$user" != "root" ]; then
+ _info "Please make sure user '$user' has write access to download dir: $dir"
+ fi
+ else
+ _info "Setting run user to '$user' failed, default user will be used."
+ user=
+ fi
+ fi
+
+ procd_open_instance "$NAME.$section"
+ procd_set_param command "$PROG"
+ procd_append_param command --conf-path="$config_file"
+
+ procd_set_param respawn
+ procd_set_param stdout 1
+ procd_set_param stderr 1
+
+ procd_set_param file "$config_file"
+ [ -n "$user" ] && \
+ procd_set_param user "$user"
+
+ procd_add_jail "$NAME.$section" log
+ procd_add_jail_mount "$config_file"
+ procd_add_jail_mount_rw "$dir" "$config_dir" "$log"
+ procd_close_instance
+}
+
+service_triggers() {
+ procd_add_reload_trigger "$NAME"
+ procd_add_validation aria2_validate
+}
+
+start_service() {
+ config_load "$NAME"
+ config_foreach aria2_validate "aria2" aria2_start
+}
--- /dev/null
+From 0e31e37c0f6ad0b3f393f024d1f6d8ce448e4746 Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Sat, 8 Dec 2018 18:39:50 -0800
+Subject: [PATCH] Platform: Fix compilation without deprecated OpenSSL APIs
+
+---
+ src/Platform.cc | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/src/Platform.cc b/src/Platform.cc
+index ea73b6c6..d7882a97 100644
+--- a/src/Platform.cc
++++ b/src/Platform.cc
+@@ -44,6 +44,7 @@
+ #ifdef HAVE_OPENSSL
+ #include <openssl/err.h>
+ #include <openssl/ssl.h>
++#include "libssl_compat.h"
+ #endif // HAVE_OPENSSL
+ #ifdef HAVE_LIBGCRYPT
+ #include <gcrypt.h>
+@@ -111,11 +112,13 @@ bool Platform::setUp()
+ #endif // ENABLE_NLS
+
+ #ifdef HAVE_OPENSSL
++#if !OPENSSL_101_API
+ // for SSL initialization
+ SSL_load_error_strings();
+ SSL_library_init();
+ // Need this to "decrypt" p12 files.
+ OpenSSL_add_all_algorithms();
++#endif // !OPENSSL_101_API
+ #endif // HAVE_OPENSSL
+ #ifdef HAVE_LIBGCRYPT
+ if (!gcry_check_version("1.2.4")) {
+--
+2.17.1
+