source: packages/net/transmission/files/transmission.init @ 29006

Last change on this file since 29006 was 29006, checked in by obsy, 4 years ago

[packages] transmission: cleanup and drop some bashizm

File size: 2.9 KB
Line 
1#!/bin/sh /etc/rc.common
2
3START=99
4BIN=/usr/bin/transmission-daemon
5SSD=start-stop-daemon
6
7LIST_SEP="
8"
9append_params() {
10        local p; local v; local s="$1"; shift
11        for p in $*; do
12                config_get v "$s" "$p"
13                IFS="$LIST_SEP"
14                for v in $v; do
15                        [ -n "$v" ] && (
16                                echo "\""$p"\": "$v"," | sed -e 's|_|-|g' >> $config_dir/settings.json
17                        )
18                done
19                unset IFS
20        done
21}
22
23append_params_quotes() {
24        local p; local v; local s="$1"; shift
25        for p in $*; do
26                config_get v "$s" "$p"
27                IFS="$LIST_SEP"
28                for v in $v; do
29                        [ -n "$v" ] && (
30                                echo -n "\""$p | sed -e 's|/|\\/|g;s|_|-|g' >> $config_dir/settings.json; \
31                                echo "\": \""$v"\"," >> $config_dir/settings.json
32                        )
33                done
34                unset IFS
35        done
36}
37
38start_service() {
39        local s="$1"
40        local enabled=0
41        local run_as_usr='root'
42        local open_file_limit=0
43        local ulimit_files=$(ulimit -n)
44
45        # disabled?
46        config_get_bool enabled "$s" enabled 0
47        [ "$enabled" = 0 ] && return 0
48        config_get config_dir "$s" config_dir '/tmp/transmission'
49        mkdir -p "$config_dir"
50        config_get run_as_usr "$s" run_daemon_as_user 'root'
51
52        echo "{" > $config_dir/settings.json
53
54        append_params "$s" \
55                alt_speed_down alt_speed_enabled alt_speed_time_begin alt_speed_time_day \
56                alt_speed_time_enabled alt_speed_time_end alt_speed_up blocklist_enabled \
57                cache_size_mb download_queue_enabled download_queue_size \
58                dht_enabled encryption idle_seeding_limit idle_seeding_limit_enabled \
59                incomplete_dir_enabled lazy_bitfield_enabled lpd_enabled message_level \
60                open_file_limit peer_limit_global peer_limit_per_torrent peer_port \
61                peer_port_random_high peer_port_random_low peer_port_random_on_start \
62                peer_socket_tos pex_enabled port_forwarding_enabled preallocation prefetch_enabled \
63                ratio_limit ratio_limit_enabled rename_partial_files rpc_authentication_required \
64                rpc_enabled rpc_port rpc_whitelist_enabled queue_stalled_enabled \
65                queue_stalled_minutes scrape_paused_torrents_enabled script_torrent_done_enabled \
66                seed_queue_enabled seed_queue_size \
67                speed_limit_down speed_limit_down_enabled speed_limit_up \
68                speed_limit_up_enabled start_added_torrents trash_original_torrent_files \
69                umask upload_slots_per_torrent utp_enabled scrape_paused_torrents \
70                watch_dir_enabled
71
72        append_params_quotes "$s" \
73                blocklist_url bind_address_ipv4 bind_address_ipv6 download_dir incomplete_dir \
74                peer_congestion_algorithm rpc_bind_address rpc_password rpc_url \
75                rpc_username rpc_whitelist script_torrent_done_filename watch_dir
76
77        echo "\""invalid-key"\": false" >> $config_dir/settings.json
78        echo "}" >> $config_dir/settings.json
79
80        chown -R $run_as_usr $config_dir
81
82        config_get open_file_limit "$s" open_file_limit 32
83        open_limit_files=$(($open_file_limit + 8))
84
85        if [ ${open_file_limit} -gt ${ulimit_files} ]; then
86                ulimit -n $open_limit_files
87        fi
88
89        eval "$SSD -c $run_as_usr -q -b -x $BIN -S -- -g $config_dir"
90}
91
92start() {
93        config_load transmission
94        config_foreach start_service transmission
95}
96
97stop() {
98        service_kill $(basename $BIN)
99}
100
101restart() {
102        stop; sleep 5; start
103}
Note: See TracBrowser for help on using the repository browser.