append_header() {
local h="$1"
[ -n "$h" ] && \
- echo "header=\"${h}\"" >>"$config_file_tmp"
+ echo "header=\"$h\"" >>"$config_file_tmp"
}
aria2_validate() {
- uci_validate_section "$NAME" aria2 "$1" \
+ uci_load_validate "$NAME" aria2 "$1" "$2" \
'enabled:bool:0' \
'enable_logging:bool' \
'enable_proxy:bool' \
aria2_start() {
local section="$1"
- aria2_validate "$section" || { _err "Validation failed."; return 1; }
+ [ "$2" = "0" ] || { _err "Validation failed."; return 1; }
- [ "$enabled" = "1" ] || { _info "Instance \"${section}\" disabled."; 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}"
+ 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}"
+ _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}"
+ _err "Can't create files: $session_file, $config_file, $config_file_tmp"
return 1
}
# Auto generated file, changes to this file will be lost.
EOF
- append_setting "dir=${dir}"
+ 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}"
+ append_setting "input-file=$session_file"
+ append_setting "save-session=$session_file"
if [ -z "$enable_logging" ]; then
append_options "log" "log_level"
log_dir="$(dirname "$log")"
_make_dir "$log_dir" || {
- _err "Can't create log 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_setting "log=$log"
append_options "log_level"
fi
unset_auth_method() {
uci -q batch <<-EOF
- set ${NAME}.${section}.rpc_auth_method=""
+ 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}"
+ append_setting "rpc-secret=$rpc_secret"
elif [ -n "$rpc_user" ]; then
- append_setting "rpc-user=${rpc_user}"
- append_setting "rpc-passwd=${rpc_passwd}"
+ 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}"
+ 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}"
+ append_setting "rpc-user=$rpc_user"
+ append_setting "rpc-passwd=$rpc_passwd"
else
_info "Please set RPC user."
unset_auth_method
fi
if [ ."$enable_dht" = ."true" ]; then
- dht_file="${config_dir}/dht.dat.${section}"
+ dht_file="$config_dir/dht.dat.$section"
_create_file "$dht_file" || {
- _err "Can't create DHT 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}"
+ append_setting "dht-file-path=$dht_file"
fi
if [ ."$enable_dht6" = ."true" ] && [ ."$disable_ipv6" != ."true" ]; then
- dht6_file="${config_dir}/dht6.dat.${section}"
+ dht6_file="$config_dir/dht6.dat.$section"
_create_file "$dht6_file" || {
- _err "Can't create DHT6 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}"
+ append_setting "dht-file-path6=$dht6_file"
fi
if [ -n "$bt_tracker" ]; then
if [ -z "$bt_tracker_list" ]; then
bt_tracker_list="$t"
else
- bt_tracker_list="${bt_tracker_list},${t}"
+ bt_tracker_list="$bt_tracker_list,$t"
fi
done
- append_setting "bt-tracker=${bt_tracker_list}"
+ append_setting "bt-tracker=$bt_tracker_list"
fi
append_options "auto_save_interval" "bt_enable_lpd" "bt_max_open_files" "bt_max_peers" \
if [ -n "$user" ]; then
if ( user_exists "$user" && _change_owner "$user" "$config_dir" "$log" ); then
- _info "Aria2 will run with user '${user}'."
+ _info "Aria2 will run with user '$user'."
if [ "$user" != "root" ]; then
- _info "Please make sure user '${user}' has write access to download dir: ${dir}"
+ _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."
+ _info "Setting run user to '$user' failed, default user will be used."
user=
fi
fi
- procd_open_instance "${NAME}.${section}"
+ procd_open_instance "$NAME.$section"
procd_set_param command "$PROG"
- procd_append_param command --conf-path="${config_file}"
+ procd_append_param command --conf-path="$config_file"
procd_set_param respawn
procd_set_param stdout 1
[ -n "$user" ] && \
procd_set_param user "$user"
- procd_add_jail "${NAME}.${section}" log
+ 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_start "aria2"
+ config_foreach aria2_validate "aria2" aria2_start
}