Created
October 13, 2019 06:38
-
-
Save caadar/40644e9dc296dea9c90e459020f1edec to your computer and use it in GitHub Desktop.
Pure-FTPd with uploadscript on NixOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/run/current-system/sw/bin/bash | |
SCANNED="$1" | |
AFFIX="${1##*.}" | |
DATESTAMP=$(date '+%Y%m%d') | |
TIMESTAMP=$(date '+%H%M%S') | |
mv "${SCANNED}" "/home/user/${DATESTAMP}..scan-${TIMESTAMP}.${AFFIX}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, ... }: | |
let uploadScript = "/etc/nixos/pkgs/pure-ftpd/ftp-uploadscript.sh"; | |
in { | |
nixpkgs.config.packageOverrides = pkgs: | |
{ pure-ftpd = pkgs.pure-ftpd.overrideAttrs (oldAttrs: { | |
configureFlags = [ "--with-uploadscript" ];}); | |
}; | |
users.groups.ftp.gid = config.ids.gids.ftp; | |
users.users.ftp = { | |
uid = config.ids.uids.ftp; | |
group = "ftp"; | |
description = "Anonymous FTP user"; | |
home = "/home/ftp"; | |
}; | |
users.users.scr.extraGroups = [ "ftp" ]; | |
systemd.services.pure-ftpd = { | |
description = "Pure-FTPd Server"; | |
wantedBy = [ "multi-user.target" ]; | |
after = [ "network.target" ]; | |
serviceConfig.ExecStart = "${pkgs.pure-ftpd}/bin/pure-ftpd --daemonize --anonymousonly --anonymouscancreatedirs --uploadscript --passiveportrange 30000:50000"; | |
serviceConfig.Type = "forking"; | |
serviceConfig.Restart = "always"; | |
}; | |
systemd.services.pure-uploadscript = { | |
description = "Pure-FTPd helper"; | |
wantedBy = [ "multi-user.target" ]; | |
requires = [ "pure-ftpd.service" ]; | |
after = [ "pure-ftpd.service" ]; | |
serviceConfig.ConditionPathExists = uploadScript; | |
serviceConfig.ExecStart = "${pkgs.pure-ftpd}/bin/pure-uploadscript -B -r ${uploadScript}"; | |
serviceConfig.Type = "forking"; | |
serviceConfig.Restart = "always"; | |
}; | |
networking.firewall.allowedTCPPortRanges = [ { from = 30000; to = 50000; } ]; | |
networking.firewall.allowedUDPPortRanges = [ { from = 30000; to = 50000; } ]; | |
networking.firewall.allowedTCPPorts = [ 21 ]; | |
networking.firewall.allowedUDPPorts = [ 21 ]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment