nzbget: Fix script for copying default config file template (#51235)
* nzbget: Fix configFile / dataDir checking in service script * nzbget: improve the description for the `configFile` option * nzbget: Add detail to the `configFile` option description * nzbget: Improve wording of `configFile` option * nzbget: Refactor dataDir management into systemd config * nzbget: Remove debug
This commit is contained in:
parent
b37667a645
commit
58d6951971
@ -4,6 +4,7 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.nzbget;
|
cfg = config.services.nzbget;
|
||||||
|
dataDir = builtins.dirOf cfg.configFile;
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
services.nzbget = {
|
services.nzbget = {
|
||||||
@ -41,6 +42,12 @@ in {
|
|||||||
default = "nzbget";
|
default = "nzbget";
|
||||||
description = "Group under which NZBGet runs";
|
description = "Group under which NZBGet runs";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
configFile = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "/var/lib/nzbget/nzbget.conf";
|
||||||
|
description = "Path for NZBGet's config file. (If this doesn't exist, the default config template is copied here.)";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -54,36 +61,25 @@ in {
|
|||||||
p7zip
|
p7zip
|
||||||
];
|
];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
datadir=${cfg.dataDir}
|
|
||||||
configfile=${cfg.dataDir}/nzbget.conf
|
|
||||||
cfgtemplate=${cfg.package}/share/nzbget/nzbget.conf
|
cfgtemplate=${cfg.package}/share/nzbget/nzbget.conf
|
||||||
test -d $datadir || {
|
if [ ! -f ${cfg.configFile} ]; then
|
||||||
echo "Creating nzbget data directory in $datadir"
|
echo "${cfg.configFile} not found. Copying default config $cfgtemplate to ${cfg.configFile}"
|
||||||
mkdir -p $datadir
|
install -m 0700 $cfgtemplate ${cfg.configFile}
|
||||||
}
|
|
||||||
test -f $configfile || {
|
|
||||||
echo "nzbget.conf not found. Copying default config $cfgtemplate to $configfile"
|
|
||||||
cp $cfgtemplate $configfile
|
|
||||||
echo "Setting $configfile permissions to 0700 (needs to be written and contains plaintext credentials)"
|
|
||||||
chmod 0700 $configfile
|
|
||||||
echo "Setting temporary \$MAINDIR variable in default config required in order to allow nzbget to complete initial start"
|
echo "Setting temporary \$MAINDIR variable in default config required in order to allow nzbget to complete initial start"
|
||||||
echo "Remember to change this to a proper value once NZBGet startup has been completed"
|
echo "Remember to change this to a proper value once NZBGet startup has been completed"
|
||||||
sed -i -e 's/MainDir=.*/MainDir=\/tmp/g' $configfile
|
sed -i -e 's/MainDir=.*/MainDir=\/tmp/g' ${cfg.configFile}
|
||||||
}
|
fi
|
||||||
echo "Ensuring proper ownership of $datadir (${cfg.user}:${cfg.group})."
|
|
||||||
chown -R ${cfg.user}:${cfg.group} $datadir
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
script = ''
|
script = ''
|
||||||
configfile=${cfg.dataDir}/nzbget.conf
|
args="--daemon --configfile ${cfg.configFile}"
|
||||||
args="--daemon --configfile $configfile"
|
# The script in preStart (above) copies nzbget's config template to datadir on first run, containing paths that point to the nzbget derivation installed at the time.
|
||||||
# The script in preStart (above) copies nzbget's config template to datadir on first run, containing paths that point to the nzbget derivation installed at the time.
|
# These paths break when nzbget is upgraded & the original derivation is garbage collected. If such broken paths are found in the config file, override them to point to
|
||||||
# These paths break when nzbget is upgraded & the original derivation is garbage collected. If such broken paths are found in the config file, override them to point to
|
|
||||||
# the currently installed nzbget derivation.
|
# the currently installed nzbget derivation.
|
||||||
cfgfallback () {
|
cfgfallback () {
|
||||||
local hit=`grep -Po "(?<=^$1=).*+" "$configfile" | sed 's/[ \t]*$//'` # Strip trailing whitespace
|
local hit=`grep -Po "(?<=^$1=).*+" "${cfg.configFile}" | sed 's/[ \t]*$//'` # Strip trailing whitespace
|
||||||
( test $hit && test -e $hit ) || {
|
( test $hit && test -e $hit ) || {
|
||||||
echo "In $configfile, valid $1 not found; falling back to $1=$2"
|
echo "In ${cfg.configFile}, valid $1 not found; falling back to $1=$2"
|
||||||
args+=" -o $1=$2"
|
args+=" -o $1=$2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +89,8 @@ in {
|
|||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
StateDirectory = dataDir;
|
||||||
|
StateDirectoryMode = "0700";
|
||||||
Type = "forking";
|
Type = "forking";
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
Group = cfg.group;
|
Group = cfg.group;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user