diff options
author | Zhang Hua | 2024-03-26 20:01:19 +0800 |
---|---|---|
committer | Zhang Hua | 2024-03-26 20:07:43 +0800 |
commit | c532e85c97e1d64f2c1fc424a11cfbf5f677bf3b (patch) | |
tree | 5b566c520faa61e3c3d26925b34dc1de2594e63b | |
parent | 14e85bad542ef69cb4ba6dabf993a5e039f6a31e (diff) | |
download | aur-c532e85c97e1d64f2c1fc424a11cfbf5f677bf3b.tar.gz |
Misc changes
1. Use Type=simple instead Type=fork
Systemd seems to be happier with this
2. Remove tmpfiles.d and sysusers.d
Use DynamicUser instead
3. Remove hardcoded arguments in service
This should let user have more control
4. Adjust sandbox options in service
5. Move depends in package()
So we do not need install aria2 and systemd
when building
6. Update broken tracker link
But users have to update it manually for
installed files
7. aria2.target now runs after service and timer
-rw-r--r-- | .SRCINFO | 36 | ||||
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | PKGBUILD | 109 | ||||
-rw-r--r-- | aria2-system.service | 23 | ||||
-rw-r--r-- | aria2-system.target | 5 | ||||
-rw-r--r-- | aria2-tracker-update-system.service | 10 | ||||
-rw-r--r-- | aria2-tracker-update-user.service | 2 | ||||
-rw-r--r-- | aria2-user.service | 11 | ||||
-rw-r--r-- | aria2-user.target | 5 | ||||
-rw-r--r-- | aria2.conf | 49 | ||||
-rw-r--r-- | aria2.sysusers | 1 | ||||
-rw-r--r-- | aria2.tmpfiles | 7 | ||||
-rw-r--r-- | aria2@.service | 6 | ||||
-rw-r--r-- | notify-user-and-copy-config | 39 | ||||
-rw-r--r-- | tracker-config.sh | 2 | ||||
-rw-r--r-- | update-aria2-tracker | 40 |
16 files changed, 149 insertions, 197 deletions
@@ -1,20 +1,15 @@ pkgbase = aria2cd pkgdesc = A systemd Service to start aria2 automatically. - pkgver = 1.3 - pkgrel = 12 + pkgver = 1.4 + pkgrel = 1 url = https://aur.archlinux.org/packages/aria2cd arch = any - license = custom:WTFPL - depends = aria2 - depends = systemd + license = LicenseRef-WTFPL optdepends = curl: for getting tracker list source = tracker-config.sh source = update-aria2-tracker source = notify-user-and-copy-config source = aria2cd.hook - source = aria2.conf - source = aria2.sysusers - source = aria2.tmpfiles source = aria2-tracker-update-user.service source = aria2-tracker-update-user.timer source = aria2-user.service @@ -25,22 +20,21 @@ pkgbase = aria2cd source = aria2-system.target source = aria2@.service source = LICENSE::http://www.wtfpl.net/txt/copying - sha256sums = 85f465f6f32a1713f65c389b57f81d26cecfb1e7baf06c38f6b9477818fc4f85 - sha256sums = c97d987a51925c4a8b76ca45f97df63c0ea2f9301040c7460294407117b49bc6 - sha256sums = 1046d5807ff575276aad2307560d4281215b3f8fadcc6993864af93dbcde8a2e + sha256sums = 70ff5d088f62cebd2168eca1fd528e4928ac162865c8f5253f9dea171c4184c6 + sha256sums = 5e87e631409387ec14fe12b1e75fcf92d9b46e270b32a2ef2748fcc354b2a335 + sha256sums = dee544a6cb7fb78aa69b37fbcc9ad9f1f48e3289b99bc054084191e93c969922 sha256sums = bdfecc359414d95396c6d19990e262d82a3240a01645a96e38e351fc8c27846e - sha256sums = d3dc278eeddbc910c775124bf474aa2c68b7bbba30226f6322ffc2c457785d27 - sha256sums = ada4e985d9023c6e0f79a8bf8bc77af609f56f832dccd287c45bb62a2bb74946 - sha256sums = 6c02f6fd75db7070f152689121a7485514f1b59aa8ec5afa92d4aaaf300ab2b2 - sha256sums = 98f23383ca1a1264fe9c418580c70eaba3fde2811ae57dab7c9bb48f0d924572 + sha256sums = 6f0171608c2352fe6be43da813fc01d656d9c19a2dab0b393521c7b0d842ec4f sha256sums = f3a81fd686335d8f45bc3aa3075979da40b93945d9b155c0e00d259de94499c1 - sha256sums = 1ab7c6bc690f82838205aec3ecd7482c3e582017c5462119e6ac57603fd12f3b - sha256sums = 2ab0b3c87f29f0b37fff593f9379fb6662775c6d3ce11342a0136a267c5fc8a2 - sha256sums = 0ef8368cf4c9aaf4b04268ce71163da4ae3c26bd8b2093516f855ba98b6f3d86 + sha256sums = 67da4cac7f24a783cb53e3bf6144a9d913782fa5b2e7539aa77440ec2e4a3996 + sha256sums = 6b4ce82e1678e199aca41f8e7017174a4a7e3f0be4e7ae4977ba716d650b4fbc + sha256sums = 478d32f2789e39588384e22eaa57877ae20ca10ce4a75e5189dec9fe9e6658bd sha256sums = f11e1d678b0fcd14f961b1e3ba7888f7ce76fc27e81fc5d6e8e442527e7a0d0d - sha256sums = 5797ee69e214f2c59cfd8d20c4287da97e0955264fa25cb43add56d5097981a0 - sha256sums = ce7de392ff23ac33fda6fa0eebe347aa591e9760b8aee140353b8e00cb93c80e - sha256sums = 1ee51459337fafc9767734d1274cedbc1d5bf5c3092c98040235b7360a9b5925 + sha256sums = 792ab59a0bb4c6123b0f4537174f125b7ed528a96aaa24a24e84b7ec169da916 + sha256sums = 0922a3e463c1c936f24af896cf56e2f2fc9852cc7f7ae4a47bd64be917ff7e85 + sha256sums = 0f4a3901b8b32b0842c5dc6765d808585cb4611561114511867eba65cd3facc1 sha256sums = 0356258391e190dc1d44ea01565cfe627fe44e27dad693a0a54c2483a7b223e5 pkgname = aria2cd + depends = aria2 + depends = systemd diff --git a/.gitignore b/.gitignore index 975f93faed14..212a37b664b5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ pkg src *.pkg.tar.* LICENSE +*.log
\ No newline at end of file @@ -1,75 +1,62 @@ -# Maintainer: ZhangHua<zhanghua.00@qq.com> +# Maintainer: ZhangHua<zhanghua.00 at qq dot com> pkgname=aria2cd -pkgver=1.3 -pkgrel=12 +pkgver=1.4 +pkgrel=1 pkgdesc="A systemd Service to start aria2 automatically." arch=("any") url="https://aur.archlinux.org/packages/aria2cd" -license=(custom:WTFPL) -depends=(aria2 systemd) +license=(LicenseRef-WTFPL) optdepends=( - 'curl: for getting tracker list') + 'curl: for getting tracker list') source=( - tracker-config.sh - update-aria2-tracker - notify-user-and-copy-config - ${pkgname}.hook - aria2.conf - aria2.sysusers - aria2.tmpfiles - aria2-tracker-update-user.service - aria2-tracker-update-user.timer - aria2-user.service - aria2-user.target - aria2-tracker-update-system.service - aria2-tracker-update-system.timer - aria2-system.service - aria2-system.target - aria2@.service - LICENSE::http://www.wtfpl.net/txt/copying + tracker-config.sh + update-aria2-tracker + notify-user-and-copy-config + ${pkgname}.hook + aria2-tracker-update-user.service + aria2-tracker-update-user.timer + aria2-user.service + aria2-user.target + aria2-tracker-update-system.service + aria2-tracker-update-system.timer + aria2-system.service + aria2-system.target + aria2@.service + LICENSE::http://www.wtfpl.net/txt/copying ) -sha256sums=('85f465f6f32a1713f65c389b57f81d26cecfb1e7baf06c38f6b9477818fc4f85' - 'c97d987a51925c4a8b76ca45f97df63c0ea2f9301040c7460294407117b49bc6' - '1046d5807ff575276aad2307560d4281215b3f8fadcc6993864af93dbcde8a2e' +sha256sums=('70ff5d088f62cebd2168eca1fd528e4928ac162865c8f5253f9dea171c4184c6' + '5e87e631409387ec14fe12b1e75fcf92d9b46e270b32a2ef2748fcc354b2a335' + 'dee544a6cb7fb78aa69b37fbcc9ad9f1f48e3289b99bc054084191e93c969922' 'bdfecc359414d95396c6d19990e262d82a3240a01645a96e38e351fc8c27846e' - 'd3dc278eeddbc910c775124bf474aa2c68b7bbba30226f6322ffc2c457785d27' - 'ada4e985d9023c6e0f79a8bf8bc77af609f56f832dccd287c45bb62a2bb74946' - '6c02f6fd75db7070f152689121a7485514f1b59aa8ec5afa92d4aaaf300ab2b2' - '98f23383ca1a1264fe9c418580c70eaba3fde2811ae57dab7c9bb48f0d924572' + '6f0171608c2352fe6be43da813fc01d656d9c19a2dab0b393521c7b0d842ec4f' 'f3a81fd686335d8f45bc3aa3075979da40b93945d9b155c0e00d259de94499c1' - '1ab7c6bc690f82838205aec3ecd7482c3e582017c5462119e6ac57603fd12f3b' - '2ab0b3c87f29f0b37fff593f9379fb6662775c6d3ce11342a0136a267c5fc8a2' - '0ef8368cf4c9aaf4b04268ce71163da4ae3c26bd8b2093516f855ba98b6f3d86' + '67da4cac7f24a783cb53e3bf6144a9d913782fa5b2e7539aa77440ec2e4a3996' + '6b4ce82e1678e199aca41f8e7017174a4a7e3f0be4e7ae4977ba716d650b4fbc' + '478d32f2789e39588384e22eaa57877ae20ca10ce4a75e5189dec9fe9e6658bd' 'f11e1d678b0fcd14f961b1e3ba7888f7ce76fc27e81fc5d6e8e442527e7a0d0d' - '5797ee69e214f2c59cfd8d20c4287da97e0955264fa25cb43add56d5097981a0' - 'ce7de392ff23ac33fda6fa0eebe347aa591e9760b8aee140353b8e00cb93c80e' - '1ee51459337fafc9767734d1274cedbc1d5bf5c3092c98040235b7360a9b5925' + '792ab59a0bb4c6123b0f4537174f125b7ed528a96aaa24a24e84b7ec169da916' + '0922a3e463c1c936f24af896cf56e2f2fc9852cc7f7ae4a47bd64be917ff7e85' + '0f4a3901b8b32b0842c5dc6765d808585cb4611561114511867eba65cd3facc1' '0356258391e190dc1d44ea01565cfe627fe44e27dad693a0a54c2483a7b223e5') package(){ - mkdir -p "${pkgdir}/usr/share/aria2" - touch "${pkgdir}/usr/share/aria2/dht.dat" - touch "${pkgdir}/usr/share/aria2/dht6.dat" - touch "${pkgdir}/usr/share/aria2/aria2.session" - install -Dm644 "${srcdir}/aria2.conf" "${pkgdir}/usr/share/aria2/aria2.conf" - install -Dm644 "${srcdir}/tracker-config.sh" "${pkgdir}/usr/share/aria2/tracker-config.sh" - install -Dm644 "${srcdir}/aria2@.service" "${pkgdir}/usr/lib/systemd/system/aria2@.service" - install -Dm644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" - install -Dm644 "${srcdir}/${pkgname}.hook" "${pkgdir}/usr/share/libalpm/hooks/${pkgname}.hook" - install -Dm755 "${srcdir}/notify-user-and-copy-config" \ - "${pkgdir}/usr/share/libalpm/scripts/notify-user-and-copy-config" - install -Dm755 "${srcdir}/update-aria2-tracker" "${pkgdir}/usr/bin/update-aria2-tracker" - install -Dm644 "${srcdir}/aria2.sysusers" "${pkgdir}/usr/lib/sysusers.d/aria2cd.conf" - install -Dm644 "${srcdir}/aria2.tmpfiles" "${pkgdir}/usr/lib/tmpfiles.d/aria2cd.conf" - for target in user system - do - install -Dm644 "${srcdir}/aria2-tracker-update-${target}.service" \ - "${pkgdir}/usr/lib/systemd/${target}/aria2-tracker-update.service" - install -Dm644 "${srcdir}/aria2-tracker-update-${target}.timer" \ - "${pkgdir}/usr/lib/systemd/${target}/aria2-tracker-update.timer" - install -Dm644 "${srcdir}/aria2-${target}.service" \ - "${pkgdir}/usr/lib/systemd/${target}/aria2.service" - install -Dm644 "${srcdir}/aria2-${target}.target" \ - "${pkgdir}/usr/lib/systemd/${target}/aria2.target" - done + depends=(aria2 systemd) + install -Dm644 "${srcdir}/tracker-config.sh" "${pkgdir}/usr/share/aria2/tracker-config.sh" + install -Dm644 "${srcdir}/aria2@.service" "${pkgdir}/usr/lib/systemd/system/aria2@.service" + install -Dm644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE" + install -Dm644 "${srcdir}/${pkgname}.hook" "${pkgdir}/usr/share/libalpm/hooks/${pkgname}.hook" + install -Dm755 "${srcdir}/notify-user-and-copy-config" \ + "${pkgdir}/usr/share/libalpm/scripts/notify-user-and-copy-config" + install -Dm755 "${srcdir}/update-aria2-tracker" "${pkgdir}/usr/bin/update-aria2-tracker" + for target in user system + do + install -Dm644 "${srcdir}/aria2-tracker-update-${target}.service" \ + "${pkgdir}/usr/lib/systemd/${target}/aria2-tracker-update.service" + install -Dm644 "${srcdir}/aria2-tracker-update-${target}.timer" \ + "${pkgdir}/usr/lib/systemd/${target}/aria2-tracker-update.timer" + install -Dm644 "${srcdir}/aria2-${target}.service" \ + "${pkgdir}/usr/lib/systemd/${target}/aria2.service" + install -Dm644 "${srcdir}/aria2-${target}.target" \ + "${pkgdir}/usr/lib/systemd/${target}/aria2.target" + done } diff --git a/aria2-system.service b/aria2-system.service index a6e270e75542..c9f0760d3c32 100644 --- a/aria2-system.service +++ b/aria2-system.service @@ -4,31 +4,32 @@ After=network-online.target Wants=network-online.target [Service] -Type=forking +Type=simple +DynamicUser=true User=aria2cd # Arguments here will override config file. ExecStart=/usr/bin/aria2c --conf-path=/etc/aria2cd/aria2.conf \ - --dir=/var/lib/aria2cd/Downloads --remote-time=true --daemon=true --enable-rpc=true \ - --bt-enable-lpd=true --bt-save-metadata=true \ - --enable-dht=true --enable-dht6=true \ - --optimize-concurrent-downloads=true \ - --parameterized-uri=true \ + --daemon=false --enable-rpc=true \ + --dir=/var/lib/aria2cd/Downloads \ --save-session=/var/lib/aria2cd/aria2.session \ --input-file=/var/lib/aria2cd/aria2.session \ --dht-file-path=/var/lib/aria2cd/aria2.dht \ --dht-file-path6=/var/lib/aria2cd/aria2.dht6 \ --save-cookies=/var/lib/aria2cd/aria2.cookies \ --load-cookies=/var/lib/aria2cd/aria2.cookies \ - --log=/var/log/aria2cd.log -ExecReload=/usr/bin/kill -HUP ${MAINPID} + --log=/var/log/aria2cd/aria2cd.log # Sandboxing ProtectSystem=strict -ReadWritePaths=/var/lib/aria2cd /var/log/aria2cd.log +StateDirectory=aria2cd +LogsDirectory=aria2cd +ConfigurationDirectory=aria2cd ReadOnlyPaths=/etc/aria2cd -NoExecPaths=/ -ExecPaths=/usr/bin/aria2c /usr/lib + +ProtectKernelTunables=yes +ProtectKernelModules=yes ProtectHome=yes +ProtectControlGroups=yes NoNewPrivileges=yes [Install] diff --git a/aria2-system.target b/aria2-system.target index 111278fe8573..36362d63326d 100644 --- a/aria2-system.target +++ b/aria2-system.target @@ -2,7 +2,10 @@ Description=System Aria2 Daemons with Trackers Updated Automatically After=network-online.target Wants=network-online.target -Wants=aria2.service aria2-tracker-update.timer +Requires=aria2.service +After=aria2.service +Wants=aria2-tracker-update.timer +After=aria2-tracker-update.timer [Install] WantedBy=multi-user.target diff --git a/aria2-tracker-update-system.service b/aria2-tracker-update-system.service index da539ff4a865..9ea59e38e3f2 100644 --- a/aria2-tracker-update-system.service +++ b/aria2-tracker-update-system.service @@ -5,13 +5,15 @@ Wants=network-online.target [Service] Type=oneshot +DynamicUser=yes +User=aria2cd ExecStart=/usr/bin/update-aria2-tracker --systemd -RestartSec=60s -Restart=on-failure # Sandboxing ProtectSystem=strict +ReadOnlyPaths=/ ReadWritePaths=/etc/aria2cd -NoExecPaths=/ -ExecPaths=/usr/bin /usr/lib +ProtectKernelTunables=yes +ProtectKernelModules=yes ProtectHome=yes +ProtectControlGroups=yes NoNewPrivileges=yes diff --git a/aria2-tracker-update-user.service b/aria2-tracker-update-user.service index f425bba61605..16f640f8e023 100644 --- a/aria2-tracker-update-user.service +++ b/aria2-tracker-update-user.service @@ -6,5 +6,3 @@ Wants=network-online.target [Service] Type=oneshot ExecStart=/usr/bin/update-aria2-tracker -RestartSec=60s -Restart=on-failure diff --git a/aria2-user.service b/aria2-user.service index 8ce7f05c4a0c..a2b20a5e7eca 100644 --- a/aria2-user.service +++ b/aria2-user.service @@ -4,16 +4,9 @@ After=network-online.target Wants=network-online.target [Service] -Type=forking +Type=simple # Arguments here will override config file. -ExecStart=/usr/bin/aria2c \ - --remote-time=true --daemon=true --enable-rpc=true \ - --bt-enable-lpd=true --bt-save-metadata=true \ - --enable-dht=true --enable-dht6=true \ - --optimize-concurrent-downloads=true \ - --parameterized-uri=true -ExecReload=/usr/bin/kill -HUP ${MAINPID} - +ExecStart=/usr/bin/aria2c --daemon=false --enable-rpc=true [Install] WantedBy=aria2.target diff --git a/aria2-user.target b/aria2-user.target index 4201d615ce5e..0c3b2381285e 100644 --- a/aria2-user.target +++ b/aria2-user.target @@ -2,7 +2,10 @@ Description=User Aria2 Daemons with Trackers Updated Automatically After=network-online.target Wants=network-online.target -Wants=aria2.service aria2-tracker-update.timer +Requires=aria2.service +After=aria2.service +Wants=aria2-tracker-update.timer +After=aria2-tracker-update.timer [Install] WantedBy=default.target diff --git a/aria2.conf b/aria2.conf deleted file mode 100644 index b7e05b02e31c..000000000000 --- a/aria2.conf +++ /dev/null @@ -1,49 +0,0 @@ -# Aria2 Config -## Download Directory -dir=${HOME}/Downloads -## Max Download Numbers -max-concurrent-downloads=8 -## Check Integrity -check-integrity=true -## Auto Continue -continue=true -## Max Connections Per Server -max-connection-per-server=16 -## Retry Wait -retry-wait=5 -## Accept gzip Headers -http-accept-gzip=true -## BT Force Encryption -#bt-force-encryption=true -## BT Save Torrent -bt-save-metadata=true -## Enable RPC -enable-rpc=true -## RPC Certificate -#rpc-certificate=${HOME}/.config/aria2/aria2.crt -## RPC Private Key -#rpc-private-key=${HOME}/.config/aria2/aria2.key -## RPC Listen Port -#rpc-listen-port=6800 -## RPC Secret -rpc-secret=SeCRetoFArIa@C -## RPC Secure -#rpc-secure=true -## Daemon -daemon=true -## Enable Map Files Into Memory -enable-mmap=true -## File Allocation -file-allocation=falloc -## Paramiterized URI -parameterized-uri=true -## Save Session -save-session=${HOME}/.config/aria2/aria2.session -## Input File -input-file=${HOME}/.config/aria2/aria2.session -## DHT File -dht-file-path=${HOME}/.cache/aria2/dht.dat -## DHT 6 File -dht-file-path6=${HOME}/.cache/aria2/dht6.dat -## BT Trackers -bt-tracker= diff --git a/aria2.sysusers b/aria2.sysusers deleted file mode 100644 index 63dffecf8c00..000000000000 --- a/aria2.sysusers +++ /dev/null @@ -1 +0,0 @@ -u aria2cd - "Aria2 Daemon User" /var/lib/aria2cd diff --git a/aria2.tmpfiles b/aria2.tmpfiles deleted file mode 100644 index 4e4bd3648c59..000000000000 --- a/aria2.tmpfiles +++ /dev/null @@ -1,7 +0,0 @@ -v /var/lib/aria2cd 755 aria2cd aria2cd -d /var/lib/aria2cd/Downloads 755 aria2cd aria2cd 30d -f /var/lib/aria2cd/aria2.session 640 aria2cd aria2cd -f /var/lib/aria2cd/aria2.dht 640 aria2cd aria2cd -f /var/lib/aria2cd/aria2.dht6 640 aria2cd aria2cd -f /var/lib/aria2cd/aria2.cookies 640 aria2cd aria2cd -f /var/log/aria2cd.log 644 aria2cd aria2cd diff --git a/aria2@.service b/aria2@.service index 100535529416..cbde576d114d 100644 --- a/aria2@.service +++ b/aria2@.service @@ -1,13 +1,13 @@ [Unit] -Description=Aria2c Daemon for %i +Description=Aria2c Daemon for user %i After=network-online.target Wants=network-online.target [Service] -Type=forking +Type=simple User=%i ExecStartPre=/usr/bin/update-aria2-tracker -ExecStart=/usr/bin/aria2c --daemon=true +ExecStart=/usr/bin/aria2c --daemon=false ExecReload=/usr/bin/kill -HUP ${MAINPID} [Install] diff --git a/notify-user-and-copy-config b/notify-user-and-copy-config index b891fbb91ed6..f518cd467182 100644 --- a/notify-user-and-copy-config +++ b/notify-user-and-copy-config @@ -2,25 +2,34 @@ echo "aria2cd has been installed/updated successfully, but there is something extra to do." echo "" -echo "If you are using user service, there are two options:" +echo "If you are using user service, you need to copy /usr/share/aria2/ to <aria2-config-dir>" echo "" -echo "1. You need to copy /usr/share/aria2/ to \${HOME}/.aria2/, \${HOME} is the home directory of the user who runs aria2c." -echo "2. Copy aria2.conf and tracker-config.sh in /usr/share/aria2 to \${XDG_CONFIG_HOME:-\${HOME}/.config}/aria2/" -echo " Copy aria2.session, dht.dat and dnt6.dat in /usr/share/aria2 to \${XDG_CACHE_HOME:-\${HOME}/.config}/aria2/" -echo "" -echo "The latter(\${XDG_CACHE_HOME}/aria2/ and \${XDG_CONFIG_HOME}/aria2/) is preferered to use because it follows freedesktop's specification." +echo "<aria2-config-dir> means ~/.aria2 or \${XDG_CONFIG_HOME:-\${HOME}/.config}/aria2" echo "" echo "According to systemd document, you also need to enable NetworkManager-wait-online.service or systemd-networkd-wait-online.service if you want to use aria2-update-tracker.timer." echo "" -echo "Note: aria2@username.service is deprecated now, it may be removed in the future. You can use system wide aria2.service or user wide aria2.service instead." -echo " Files downloaded by system service is placed at /var/lib/aria2cd/Downloads and will be cleaned after 30 days, please copy it to a safe place if needed." +echo "Notes:" +echo " aria2@username.service is deprecated now, it may be removed in the future. You can use system wide aria2.service or user wide aria2.service instead." +echo " Files downloaded by system service is placed at /var/lib/aria2cd/Downloads." echo "" +# create_config $file +function create_config() { + if [[ ! -f "/etc/aria2cd/${1}" ]] + then + if [[ -f "/usr/share/aria2/${1}" ]] + then + echo "Copying ${1}..." + cp "/usr/share/aria2/${1}" "/etc/aria2cd/${1}" + else + echo "Creating empty ${1}..." + touch "/etc/aria2cd/${1}" + fi + else + echo "${1} is found so we will skip it." + fi +} + mkdir -p /etc/aria2cd -for file in aria2.conf tracker-config.sh -do - echo "Copying ${file}..." - [[ ! -f /etc/aria2cd/${file} ]] && \ - cp /usr/share/aria2/${file} /etc/aria2cd/${file} -done -echo "Finished copying config." +create_config tracker-config.sh +create_config aria2.conf diff --git a/tracker-config.sh b/tracker-config.sh index e48ad3f55f9d..8aa785f1a345 100644 --- a/tracker-config.sh +++ b/tracker-config.sh @@ -1,4 +1,4 @@ # Set $ENABLED to false to disable auto updating tracker # Please fill $TRACKER with proper content, you can see the sample address for more info. ENABLED=false -TRACKER=$(curl -Ls https://cdn.staticaly.com/gh/XIU2/TrackersListCollection/master/best_aria2.txt)
\ No newline at end of file +TRACKER=$(curl -Ls https://cf.trackerslist.com/best_aria2.txt)
\ No newline at end of file diff --git a/update-aria2-tracker b/update-aria2-tracker index f48505ce05fc..928cb05ced48 100644 --- a/update-aria2-tracker +++ b/update-aria2-tracker @@ -3,25 +3,43 @@ set -e function get_aria2_home(){ - [[ $(id -nu) == "root" && $1 == "--systemd" ]] && echo /etc/aria2cd && return 0 + if [[ "$1" == "--systemd" ]] + then + echo /etc/aria2cd + return 0 + fi for path in ${HOME}/.aria2 ${XDG_CONFIG_HOME:-${HOME}/.config}/aria2 do - [[ -f ${path}/aria2.conf ]] && echo ${path} && return 0 + if [[ -f ${path}/aria2.conf ]] + then + echo "${path}" + return 0 + fi done - echo ${HOME}/.aria2 && return 0 + echo "${HOME}/.aria2" + return 0 } -ARIA2_CONFIG_HOME=$(get_aria2_home $1) +ARIA2_CONFIG_HOME=$(get_aria2_home "$1") echo "Aria2 config is placing at ${ARIA2_CONFIG_HOME}" if [[ -f "${ARIA2_CONFIG_HOME}/tracker-config.sh" ]] then echo "Loading config from ${ARIA2_CONFIG_HOME}/tracker-config.sh" source "${ARIA2_CONFIG_HOME}/tracker-config.sh" fi -[[ -z $ENABLED ]] && ENABLED=false -$ENABLED || exit 0 -[[ -z $TRACKER ]] && \ - TRACKER=$(curl -Ls https://cdn.staticaly.com/gh/XIU2/TrackersListCollection/master/best_aria2.txt) -grep -q 'bt-tracker=' "${ARIA2_CONFIG_HOME}/aria2.conf" && \ - sed -i "s@bt-tracker=.*@bt-tracker=$TRACKER@" "${ARIA2_CONFIG_HOME}/aria2.conf" || \ - sed -i "\$a bt-tracker=$TRACKER" "${ARIA2_CONFIG_HOME}/aria2.conf" +ENABLED=${ENABLED:-false} +if $ENABLED +then + if [[ -z $TRACKER ]] + then + exit 1 + fi + if grep -q 'bt-tracker=' "${ARIA2_CONFIG_HOME}/aria2.conf" + then + echo "Replacing tracker line" + sed -i "s@bt-tracker=.*@bt-tracker=$TRACKER@" "${ARIA2_CONFIG_HOME}/aria2.conf" + else + echo "Adding tracker line" + sed -i "\$a bt-tracker=$TRACKER" "${ARIA2_CONFIG_HOME}/aria2.conf" + fi +fi |