update dae config
This commit is contained in:
parent
85c8b22542
commit
19e24d0719
2 changed files with 73 additions and 76 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
rootPath,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
|
|
@ -20,35 +20,68 @@
|
|||
};
|
||||
systemd.services =
|
||||
let
|
||||
new_proxy = "/etc/dae/proxy.d.new";
|
||||
head = "user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36";
|
||||
update = ''
|
||||
head="user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"
|
||||
new_proxy=/etc/dae/proxy.d.new
|
||||
num=0
|
||||
check=1
|
||||
urls="$(${pkgs.coreutils}/bin/cat ${config.sops.secrets.url.path})"
|
||||
mkdir -p ${new_proxy}
|
||||
for url in "''${urls}"; do
|
||||
txt=${new_proxy}/''${num}.txt
|
||||
config="${new_proxy}/''${num}.dae"
|
||||
${pkgs.curl}/bin/curl -H "${head}" "''${url}" > "''${txt}"
|
||||
${pkgs.coreutils}/bin/echo "" > ''${config}
|
||||
${pkgs.coreutils}/bin/echo 'subscription {' >> ''${config}
|
||||
${pkgs.coreutils}/bin/echo \ \ wget:\ \"file\://proxy.d/''${num}.txt\" >> ''${config}
|
||||
${pkgs.coreutils}/bin/echo } >> ''${config}
|
||||
urls="$(cat ${config.sops.secrets.url.path})"
|
||||
mkdir -p ''${new_proxy}
|
||||
for url in ''${urls}; do
|
||||
txt=''${new_proxy}/''${num}.txt
|
||||
config="''${new_proxy}/''${num}.dae"
|
||||
echo \'curl -LH \""''${head}"\" \""''${url}"\" -o \""''${txt}"\"\'
|
||||
curl -LH "''${head}" "''${url}" -o "''${txt}"
|
||||
echo End curl
|
||||
echo "" > ''${config}
|
||||
{
|
||||
echo 'subscription {'
|
||||
echo \ \ wget:\ \"file://proxy.d/''${num}.txt\"
|
||||
echo "}"
|
||||
} >> ''${config}
|
||||
if [[ ! -s ''${txt} ]]; then
|
||||
check=0
|
||||
fi
|
||||
${pkgs.coreutils}/bin/chmod 0640 ''${txt}
|
||||
${pkgs.coreutils}/bin/chmod 0640 ''${config}
|
||||
link=$((link+1))
|
||||
chmod 0640 ''${txt}
|
||||
chmod 0640 ''${config}
|
||||
num=$((num+1))
|
||||
|
||||
if [[ ''${check} -eq 0 ]]; then
|
||||
exit -1
|
||||
echo "''${txt}" is empty
|
||||
exit 103
|
||||
fi
|
||||
done
|
||||
${pkgs.coreutils}/bin/rm -r /etc/dae/proxy.d
|
||||
${pkgs.coreutils}/bin/mv ${new_proxy} /etc/dae/proxy.d
|
||||
if [[ -d /etc/dae/proxy.d ]]; then
|
||||
mv /etc/dae/proxy.d /etc/dae/proxy.d.old
|
||||
fi
|
||||
mv ''${new_proxy} /etc/dae/proxy.d
|
||||
'';
|
||||
updateScript = pkgs.writeShellApplication {
|
||||
name = "update.sh";
|
||||
runtimeInputs = with pkgs; [
|
||||
coreutils
|
||||
curl
|
||||
];
|
||||
text = ''
|
||||
mkdir -p /etc/proxy.d
|
||||
if [ -z "$(ls -A /etc/dae/proxy.d 2>/dev/null)" ]; then
|
||||
echo "No subscription file found in /etc/dae/proxy.d. Update now..."
|
||||
${update}
|
||||
else
|
||||
echo "Found existing subscription files. Skipping immediate update."
|
||||
fi
|
||||
'';
|
||||
};
|
||||
updateForceScript = pkgs.writeShellApplication {
|
||||
name = "update-force.sh";
|
||||
runtimeInputs = with pkgs; [
|
||||
coreutils
|
||||
curl
|
||||
];
|
||||
text = ''
|
||||
${update}
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
"update-dae-subscription-immediate" = {
|
||||
|
|
@ -58,62 +91,26 @@
|
|||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "root";
|
||||
ExecStart =
|
||||
let
|
||||
script = pkgs.writeTextFile {
|
||||
name = "update-dae-subscription-immediate";
|
||||
executable = true;
|
||||
destination = "/bin/script";
|
||||
text = ''
|
||||
${pkgs.coreutils}/bin/mkdir -p /etc/proxy.d
|
||||
if [ -z "$(ls -A /etc/dae/proxy.d 2>/dev/null)" ]; then
|
||||
${pkgs.coreutils}/bin/echo "No subscription file found in /etc/dae/proxy.d. Update now..."
|
||||
${update}
|
||||
else
|
||||
${pkgs.coreutils}/bin/echo "Found existing subscription files. Skipping immediate update."
|
||||
fi
|
||||
'';
|
||||
};
|
||||
in
|
||||
[
|
||||
"${pkgs.bash}/bin/bash ${script}/bin/script"
|
||||
];
|
||||
ExecStart = [
|
||||
"${updateScript}/bin/update.sh"
|
||||
];
|
||||
};
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
};
|
||||
|
||||
# "update-dae-subscription-weekly" = {
|
||||
# after = [ "network-online.target" ];
|
||||
# wants = [ "network-online.target" ];
|
||||
# wantedBy = [ "multi-user.target" ];
|
||||
# serviceConfig = {
|
||||
# Type = "oneshot";
|
||||
# ExecStart =
|
||||
# let
|
||||
# script = pkgs.writeTextFile {
|
||||
# name = "update-dae-subscription-weekly";
|
||||
# executable = true;
|
||||
# destination = "/bin/script";
|
||||
# text = ''
|
||||
# ${pkgs.coreutils}/bin/echo "Force subscription update..."
|
||||
# ${pkgs.coreutils}/bin/mkdir -p /etc/proxy.d
|
||||
# ${update}
|
||||
# '';
|
||||
# };
|
||||
# in
|
||||
# [
|
||||
# "${pkgs.bash}/bin/bash ${script}/bin/script"
|
||||
# ];
|
||||
# };
|
||||
# };
|
||||
"update-dae-subscription-force" = {
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = "root";
|
||||
ExecStartPre = [
|
||||
"-${pkgs.systemd}/bin/systemctl stop dae.service"
|
||||
];
|
||||
ExecStartPost = [
|
||||
"-${pkgs.systemd}/bin/systemctl start dae.service"
|
||||
];
|
||||
ExecStart = [
|
||||
"${updateForceScript}/bin/update-force.sh"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# systemd.timers."dae-update" = {
|
||||
# wantedBy = [ "timers.target" ];
|
||||
# timerConfig = {
|
||||
# OnCalendar = "weekly";
|
||||
# Unit = "dae-update.service";
|
||||
# Persistent = true;
|
||||
# };
|
||||
# };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue