remove dependency on sabnzbd default config and use sed for editing
Because initool cannot parse double-nested categories, sed is used instead to edit sabnzbd.ini values. It also appears that SABnzbd will keep any initial values written to sabnzbd.ini and then add any missing keys with their default values. Therefore, we can just generate the bits of config we need and let SABnzbd do the rest on its first run.
This commit is contained in:
@@ -1,319 +0,0 @@
|
||||
__version__ = 19
|
||||
__encoding__ = utf-8
|
||||
[misc]
|
||||
helpful_warnings = 1
|
||||
queue_complete = ""
|
||||
queue_complete_pers = 0
|
||||
bandwidth_perc = 100
|
||||
refresh_rate = 0
|
||||
interface_settings = ""
|
||||
queue_limit = 20
|
||||
config_lock = 0
|
||||
fixed_ports = 1
|
||||
notified_new_skin = 0
|
||||
direct_unpack_tested = 0
|
||||
sorters_converted = 1
|
||||
check_new_rel = 1
|
||||
auto_browser = 0
|
||||
language = en
|
||||
enable_https_verification = 1
|
||||
host = 127.0.0.1
|
||||
port = 8080
|
||||
https_port = ""
|
||||
username = ""
|
||||
password = ""
|
||||
bandwidth_max = ""
|
||||
cache_limit = 1G
|
||||
web_dir = Glitter
|
||||
web_color = Auto
|
||||
https_cert = server.cert
|
||||
https_key = server.key
|
||||
https_chain = ""
|
||||
enable_https = 0
|
||||
inet_exposure = 0
|
||||
api_key = 7e5bba66499740fb99c069230cd750b7
|
||||
nzb_key = 17f2984c97be487283c5a8bb00896415
|
||||
socks5_proxy_url = ""
|
||||
permissions = ""
|
||||
download_dir = Downloads/incomplete
|
||||
download_free = ""
|
||||
complete_dir = Downloads/complete
|
||||
complete_free = ""
|
||||
fulldisk_autoresume = 0
|
||||
script_dir = ""
|
||||
nzb_backup_dir = ""
|
||||
admin_dir = admin
|
||||
backup_dir = ""
|
||||
dirscan_dir = ""
|
||||
dirscan_speed = 5
|
||||
password_file = ""
|
||||
log_dir = logs
|
||||
max_art_tries = 3
|
||||
top_only = 0
|
||||
sfv_check = 1
|
||||
script_can_fail = 0
|
||||
enable_recursive = 1
|
||||
flat_unpack = 0
|
||||
par_option = ""
|
||||
pre_check = 0
|
||||
nice = ""
|
||||
win_process_prio = 3
|
||||
ionice = ""
|
||||
fail_hopeless_jobs = 1
|
||||
fast_fail = 1
|
||||
auto_disconnect = 1
|
||||
pre_script = None
|
||||
end_queue_script = None
|
||||
no_dupes = 0
|
||||
no_series_dupes = 0
|
||||
no_smart_dupes = 0
|
||||
dupes_propercheck = 1
|
||||
pause_on_pwrar = 1
|
||||
ignore_samples = 0
|
||||
deobfuscate_final_filenames = 1
|
||||
auto_sort = ""
|
||||
direct_unpack = 0
|
||||
propagation_delay = 0
|
||||
folder_rename = 1
|
||||
replace_spaces = 0
|
||||
replace_underscores = 0
|
||||
replace_dots = 0
|
||||
safe_postproc = 1
|
||||
pause_on_post_processing = 0
|
||||
enable_all_par = 0
|
||||
sanitize_safe = 0
|
||||
cleanup_list = ,
|
||||
unwanted_extensions = ,
|
||||
action_on_unwanted_extensions = 0
|
||||
unwanted_extensions_mode = 0
|
||||
new_nzb_on_failure = 0
|
||||
history_retention = ""
|
||||
history_retention_option = all
|
||||
history_retention_number = 0
|
||||
quota_size = ""
|
||||
quota_day = ""
|
||||
quota_resume = 0
|
||||
quota_period = m
|
||||
enable_tv_sorting = 0
|
||||
tv_sort_string = ""
|
||||
tv_categories = tv,
|
||||
enable_movie_sorting = 0
|
||||
movie_sort_string = ""
|
||||
movie_sort_extra = -cd%1
|
||||
movie_categories = movies,
|
||||
enable_date_sorting = 0
|
||||
date_sort_string = ""
|
||||
date_categories = tv,
|
||||
schedlines = ,
|
||||
rss_rate = 60
|
||||
ampm = 0
|
||||
start_paused = 0
|
||||
preserve_paused_state = 0
|
||||
enable_par_cleanup = 1
|
||||
process_unpacked_par2 = 1
|
||||
enable_multipar = 1
|
||||
enable_unrar = 1
|
||||
enable_7zip = 1
|
||||
enable_filejoin = 1
|
||||
enable_tsjoin = 1
|
||||
overwrite_files = 0
|
||||
ignore_unrar_dates = 0
|
||||
backup_for_duplicates = 0
|
||||
empty_postproc = 0
|
||||
wait_for_dfolder = 0
|
||||
rss_filenames = 0
|
||||
api_logging = 1
|
||||
html_login = 1
|
||||
warn_dupl_jobs = 0
|
||||
keep_awake = 1
|
||||
tray_icon = 1
|
||||
allow_incomplete_nzb = 0
|
||||
enable_broadcast = 1
|
||||
ipv6_hosting = 0
|
||||
ipv6_staging = 0
|
||||
api_warnings = 1
|
||||
no_penalties = 0
|
||||
x_frame_options = 1
|
||||
allow_old_ssl_tls = 0
|
||||
enable_season_sorting = 1
|
||||
verify_xff_header = 0
|
||||
rss_odd_titles = nzbindex.nl/, nzbindex.com/, nzbclub.com/
|
||||
quick_check_ext_ignore = nfo, sfv, srr
|
||||
req_completion_rate = 100.2
|
||||
selftest_host = self-test.sabnzbd.org
|
||||
movie_rename_limit = 100M
|
||||
episode_rename_limit = 20M
|
||||
size_limit = 0
|
||||
direct_unpack_threads = 3
|
||||
history_limit = 10
|
||||
wait_ext_drive = 5
|
||||
max_foldername_length = 246
|
||||
nomedia_marker = ""
|
||||
ipv6_servers = 1
|
||||
url_base = /sabnzbd
|
||||
host_whitelist = snootflix,
|
||||
local_ranges = ,
|
||||
max_url_retries = 10
|
||||
downloader_sleep_time = 10
|
||||
receive_threads = 2
|
||||
switchinterval = 0.005
|
||||
ssdp_broadcast_interval = 15
|
||||
ext_rename_ignore = ,
|
||||
email_server = ""
|
||||
email_to = ,
|
||||
email_from = ""
|
||||
email_account = ""
|
||||
email_pwd = ""
|
||||
email_endjob = 0
|
||||
email_full = 0
|
||||
email_dir = ""
|
||||
email_rss = 0
|
||||
email_cats = *,
|
||||
[logging]
|
||||
log_level = 1
|
||||
max_log_size = 5242880
|
||||
log_backups = 5
|
||||
[ncenter]
|
||||
ncenter_enable = 0
|
||||
ncenter_cats = *,
|
||||
ncenter_prio_startup = 0
|
||||
ncenter_prio_download = 0
|
||||
ncenter_prio_pause_resume = 0
|
||||
ncenter_prio_pp = 0
|
||||
ncenter_prio_complete = 1
|
||||
ncenter_prio_failed = 1
|
||||
ncenter_prio_disk_full = 1
|
||||
ncenter_prio_new_login = 0
|
||||
ncenter_prio_warning = 0
|
||||
ncenter_prio_error = 0
|
||||
ncenter_prio_queue_done = 0
|
||||
ncenter_prio_other = 1
|
||||
[acenter]
|
||||
acenter_enable = 0
|
||||
acenter_cats = *,
|
||||
acenter_prio_startup = 0
|
||||
acenter_prio_download = 0
|
||||
acenter_prio_pause_resume = 0
|
||||
acenter_prio_pp = 0
|
||||
acenter_prio_complete = 1
|
||||
acenter_prio_failed = 1
|
||||
acenter_prio_disk_full = 1
|
||||
acenter_prio_new_login = 0
|
||||
acenter_prio_warning = 0
|
||||
acenter_prio_error = 0
|
||||
acenter_prio_queue_done = 0
|
||||
acenter_prio_other = 1
|
||||
[ntfosd]
|
||||
ntfosd_enable = 1
|
||||
ntfosd_cats = *,
|
||||
ntfosd_prio_startup = 0
|
||||
ntfosd_prio_download = 0
|
||||
ntfosd_prio_pause_resume = 0
|
||||
ntfosd_prio_pp = 0
|
||||
ntfosd_prio_complete = 1
|
||||
ntfosd_prio_failed = 1
|
||||
ntfosd_prio_disk_full = 1
|
||||
ntfosd_prio_new_login = 0
|
||||
ntfosd_prio_warning = 0
|
||||
ntfosd_prio_error = 0
|
||||
ntfosd_prio_queue_done = 0
|
||||
ntfosd_prio_other = 1
|
||||
[prowl]
|
||||
prowl_enable = 0
|
||||
prowl_cats = *,
|
||||
prowl_apikey = ""
|
||||
prowl_prio_startup = -3
|
||||
prowl_prio_download = -3
|
||||
prowl_prio_pause_resume = -3
|
||||
prowl_prio_pp = -3
|
||||
prowl_prio_complete = 0
|
||||
prowl_prio_failed = 1
|
||||
prowl_prio_disk_full = 1
|
||||
prowl_prio_new_login = -3
|
||||
prowl_prio_warning = -3
|
||||
prowl_prio_error = -3
|
||||
prowl_prio_queue_done = -3
|
||||
prowl_prio_other = 0
|
||||
[pushover]
|
||||
pushover_token = ""
|
||||
pushover_userkey = ""
|
||||
pushover_device = ""
|
||||
pushover_emergency_expire = 3600
|
||||
pushover_emergency_retry = 60
|
||||
pushover_enable = 0
|
||||
pushover_cats = *,
|
||||
pushover_prio_startup = -3
|
||||
pushover_prio_download = -2
|
||||
pushover_prio_pause_resume = -2
|
||||
pushover_prio_pp = -3
|
||||
pushover_prio_complete = -1
|
||||
pushover_prio_failed = -1
|
||||
pushover_prio_disk_full = 1
|
||||
pushover_prio_new_login = -3
|
||||
pushover_prio_warning = 1
|
||||
pushover_prio_error = 1
|
||||
pushover_prio_queue_done = -3
|
||||
pushover_prio_other = -1
|
||||
[pushbullet]
|
||||
pushbullet_enable = 0
|
||||
pushbullet_cats = *,
|
||||
pushbullet_apikey = ""
|
||||
pushbullet_device = ""
|
||||
pushbullet_prio_startup = 0
|
||||
pushbullet_prio_download = 0
|
||||
pushbullet_prio_pause_resume = 0
|
||||
pushbullet_prio_pp = 0
|
||||
pushbullet_prio_complete = 1
|
||||
pushbullet_prio_failed = 1
|
||||
pushbullet_prio_disk_full = 1
|
||||
pushbullet_prio_new_login = 0
|
||||
pushbullet_prio_warning = 0
|
||||
pushbullet_prio_error = 0
|
||||
pushbullet_prio_queue_done = 0
|
||||
pushbullet_prio_other = 1
|
||||
[apprise]
|
||||
apprise_enable = 0
|
||||
apprise_cats = *,
|
||||
apprise_urls = ""
|
||||
apprise_target_startup = ""
|
||||
apprise_target_startup_enable = 0
|
||||
apprise_target_download = ""
|
||||
apprise_target_download_enable = 0
|
||||
apprise_target_pause_resume = ""
|
||||
apprise_target_pause_resume_enable = 0
|
||||
apprise_target_pp = ""
|
||||
apprise_target_pp_enable = 0
|
||||
apprise_target_complete = ""
|
||||
apprise_target_complete_enable = 1
|
||||
apprise_target_failed = ""
|
||||
apprise_target_failed_enable = 1
|
||||
apprise_target_disk_full = ""
|
||||
apprise_target_disk_full_enable = 0
|
||||
apprise_target_new_login = ""
|
||||
apprise_target_new_login_enable = 1
|
||||
apprise_target_warning = ""
|
||||
apprise_target_warning_enable = 0
|
||||
apprise_target_error = ""
|
||||
apprise_target_error_enable = 0
|
||||
apprise_target_queue_done = ""
|
||||
apprise_target_queue_done_enable = 0
|
||||
apprise_target_other = ""
|
||||
apprise_target_other_enable = 1
|
||||
[nscript]
|
||||
nscript_enable = 0
|
||||
nscript_cats = *,
|
||||
nscript_script = ""
|
||||
nscript_parameters = ""
|
||||
nscript_prio_startup = 0
|
||||
nscript_prio_download = 0
|
||||
nscript_prio_pause_resume = 0
|
||||
nscript_prio_pp = 0
|
||||
nscript_prio_complete = 1
|
||||
nscript_prio_failed = 1
|
||||
nscript_prio_disk_full = 1
|
||||
nscript_prio_new_login = 0
|
||||
nscript_prio_warning = 0
|
||||
nscript_prio_error = 0
|
||||
nscript_prio_queue_done = 0
|
||||
nscript_prio_other = 1
|
||||
|
||||
+33
-23
@@ -3,14 +3,13 @@ let
|
||||
cfg = config.nixarr.sabnzbd;
|
||||
nixarr = config.nixarr;
|
||||
ini-file-target = "${cfg.stateDir}/sabnzbd.ini";
|
||||
|
||||
concatStringsCommaIfExists = with lib.strings; stringList: (
|
||||
optionalString (builtins.length stringList > 0) (
|
||||
concatStringsSep "," stringList
|
||||
)
|
||||
);
|
||||
|
||||
dynamic-configs = {
|
||||
user-configs = {
|
||||
misc = {
|
||||
host = if cfg.openFirewall then "0.0.0.0" else "127.0.0.1";
|
||||
port = cfg.guiPort;
|
||||
@@ -22,13 +21,29 @@ let
|
||||
};
|
||||
};
|
||||
|
||||
dynamic-config-set-cmds = with lib.attrsets; mapAttrsToList (
|
||||
api-key-configs = {
|
||||
misc = {
|
||||
api_key = "";
|
||||
nzb_key = "";
|
||||
};
|
||||
};
|
||||
|
||||
compiled-configs = {misc = (user-configs.misc // api-key-configs.misc);};
|
||||
|
||||
ini-base-config-file = pkgs.writeTextFile {
|
||||
name = "base-config.ini";
|
||||
text = lib.generators.toINI {} compiled-configs;
|
||||
};
|
||||
|
||||
mkSedEditValue = name: value: ''sed -E 's%(\b${name} ?= ?).*%\1${builtins.toString value}%g' '';
|
||||
|
||||
user-config-set-cmds = with lib.attrsets; mapAttrsToList (
|
||||
group-n: group-v: (
|
||||
mapAttrsToList (
|
||||
n: v: "| initool set - ${group-n} ${n} \"${builtins.toString v}\" \\\n"
|
||||
n: v: "${mkSedEditValue n v} \\\n"
|
||||
) group-v
|
||||
)
|
||||
) dynamic-configs;
|
||||
) user-configs;
|
||||
|
||||
fix-config-permissions-script = pkgs.writeShellApplication {
|
||||
name = "sabnzbd-fix-config-permissions";
|
||||
@@ -44,9 +59,9 @@ let
|
||||
'';
|
||||
};
|
||||
|
||||
apply-dynamic-configs-script = pkgs.writeShellApplication {
|
||||
name = "sabnzbd-set-dynamic-values";
|
||||
runtimeInputs = with pkgs; [initool util-linux];
|
||||
apply-user-configs-script = pkgs.writeShellApplication {
|
||||
name = "sabnzbd-set-user-values";
|
||||
runtimeInputs = with pkgs; [gnused util-linux];
|
||||
text = with lib; ''
|
||||
if [ ! -f ${ini-file-target} ]; then
|
||||
echo "FAILURE: Cannot write changes to ${ini-file-target}, file does not exist"
|
||||
@@ -54,8 +69,8 @@ let
|
||||
fi
|
||||
|
||||
cp --preserve ${ini-file-target}{,.tmp}
|
||||
initool set ${ini-file-target} "" __comment__ 'edited by nixarr' \
|
||||
'' + (strings.concatStrings (lists.flatten dynamic-config-set-cmds))
|
||||
< ${ini-file-target} \
|
||||
'' + (strings.concatStringsSep "|" (lists.flatten user-config-set-cmds))
|
||||
+ ''
|
||||
> ${ini-file-target}.tmp && mv -f ${ini-file-target}{.tmp,}
|
||||
'';
|
||||
@@ -64,7 +79,7 @@ let
|
||||
bashCheckIfEmptyStr = v: "[[ -z \$${v} || \$${v} == '\"\"' ]]";
|
||||
gen-uuids-script = pkgs.writeShellApplication {
|
||||
name = "sabnzbd-set-random-api-uuids";
|
||||
runtimeInputs = with pkgs; [initool util-linux];
|
||||
runtimeInputs = with pkgs; [initool gnused util-linux];
|
||||
text = ''
|
||||
if [ ! -f ${ini-file-target} ]; then
|
||||
echo "FAILURE: ${ini-file-target} does not exist. Cannot generate crypto strings."
|
||||
@@ -74,28 +89,23 @@ let
|
||||
api_key_value=$(initool get ${ini-file-target} misc api_key -v)
|
||||
nzb_key_value=$(initool get ${ini-file-target} misc nzb_key -v)
|
||||
|
||||
if ${bashCheckIfEmptyStr "api_key_value"} || ${bashCheckIfEmptyStr "nzb_key_value"}; then
|
||||
cp --preserve ${ini-file-target}{,.tmp}
|
||||
if ${bashCheckIfEmptyStr "api_key_value"}; then
|
||||
api_uuid=$(uuidgen --random | tr -d '-')
|
||||
initool set ${ini-file-target} misc api_key "$api_uuid" \
|
||||
> ${ini-file-target}.tmp
|
||||
echo "Generated api_key for ${ini-file-target}"
|
||||
fi
|
||||
if ${bashCheckIfEmptyStr "nzb_key_value"}; then
|
||||
nzb_uuid=$(uuidgen --random | tr -d '-')
|
||||
initool set ${ini-file-target} misc nzb_key "$nzb_uuid" \
|
||||
> ${ini-file-target}.tmp
|
||||
echo "Generated nzb_key for ${ini-file-target}"
|
||||
< ${ini-file-target} \
|
||||
${mkSedEditValue "api_key" "'\"$api_uuid\"'"} \
|
||||
| ${mkSedEditValue "nzb_key" "'\"$nzb_uuid\"'"} \
|
||||
> ${ini-file-target}.tmp && mv -f ${ini-file-target}{.tmp,}
|
||||
fi
|
||||
mv -f ${ini-file-target}{.tmp,}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
systemd.tmpfiles.rules = [ "C ${cfg.stateDir}/sabnzbd.ini - - - - ${./base-config.ini}" ];
|
||||
systemd.tmpfiles.rules = [ "C ${cfg.stateDir}/sabnzbd.ini - - - - ${ini-base-config-file}" ];
|
||||
systemd.services.sabnzbd.serviceConfig.ExecStartPre = lib.mkBefore [
|
||||
("+" + fix-config-permissions-script + "/bin/sabnzbd-fix-config-permissions")
|
||||
(gen-uuids-script + "/bin/sabnzbd-set-random-api-uuids")
|
||||
(apply-dynamic-configs-script + "/bin/sabnzbd-set-dynamic-values")
|
||||
(apply-user-configs-script + "/bin/sabnzbd-set-user-values")
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user