diff --git a/Makefile b/Makefile index fd850b4..b96df97 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,11 @@ +ifeq ('$(origin SUDO)', 'command line') +SUDO_MODE = $(SUDO) +endif +ifeq ($(SUDO_MODE),1) + S = $(S) +else + S = +endif .PHONY: test test-tls build run run-tls kill enter setup-bob test-bob push pull test: build run logs-for-5 setup-bob test-bob @@ -9,30 +17,30 @@ logs-for-%: @echo "-----" @echo "watching logs for next $* seconds" @echo "-----" - -timeout -s9 $* sudo docker logs -f ftpd_server + -timeout -s9 $* $(S)docker logs -f ftpd_server build: - sudo docker build --rm -t pure-ftp-demo . + $(S)docker build --rm -t stilliard/pure-ftpd:bmcclure . run: kill - sudo docker run -d --name ftpd_server -p 21:21 -p 30000-30009:30000-30009 -e "PUBLICHOST=localhost" -e "ADDED_FLAGS=-d -d" pure-ftp-demo + $(S)docker run -d --name ftpd_server -p 21:21 -p 30000-30009:30000-30009 -e "PUBLICHOST=localhost" -e "ADDED_FLAGS=-d -d" pure-ftp-demo # runs with auto generated tls cert & creates test bob user run-tls: kill - -sudo docker volume rm ftp_tls - sudo docker volume create --name ftp_tls - sudo docker run -d --name ftpd_server -p 21:21 -p 30000-30009:30000-30009 -e "PUBLICHOST=localhost" -e "ADDED_FLAGS=-d -d --tls 2" -e "TLS_CN=localhost" -e "TLS_ORG=Demo" -e "TLS_C=UK" -e"TLS_USE_DSAPRAM=true" -e FTP_USER_NAME=bob -e FTP_USER_PASS=test -e FTP_USER_HOME=/home/ftpusers/bob -v ftp_tls:/etc/ssl/private/ pure-ftp-demo + -$(S)docker volume rm ftp_tls + $(S)docker volume create --name ftp_tls + $(S)docker run -d --name ftpd_server -p 21:21 -p 30000-30009:30000-30009 -e "PUBLICHOST=localhost" -e "ADDED_FLAGS=-d -d --tls 2" -e "TLS_CN=localhost" -e "TLS_ORG=Demo" -e "TLS_C=UK" -e"TLS_USE_DSAPRAM=true" -e FTP_USER_NAME=bob -e FTP_USER_PASS=test -e FTP_USER_HOME=/home/ftpusers/bob -v ftp_tls:/etc/ssl/private/ pure-ftp-demo kill: - -sudo docker kill ftpd_server - -sudo docker rm ftpd_server + -$(S)docker kill ftpd_server + -$(S)docker rm ftpd_server enter: - sudo docker exec -it ftpd_server sh -c "export TERM=xterm && bash" + $(S)docker exec -it ftpd_server sh -c "export TERM=xterm && bash" # Setup test "bob" user with "test" as password setup-bob: - sudo docker exec -it ftpd_server sh -c "(echo test; echo test) | pure-pw useradd bob -f /etc/pure-ftpd/passwd/pureftpd.passwd -m -u ftpuser -d /home/ftpusers/bob" + $(S)docker exec -it ftpd_server sh -c "(echo test; echo test) | pure-pw useradd bob -f /etc/pure-ftpd/passwd/pureftpd.passwd -m -u ftpuser -d /home/ftpusers/bob" @echo "User bob setup with password: test" # simple test to list files, upload a file, download it to a new name, delete it via ftp and read the new local one to make sure it's in tact @@ -51,7 +59,7 @@ test-bob: # test again but with tls (uses lftp for tls support) test-bob-tls: echo "Test file was read successfully!" > test-orig-file.txt - cert="$$(sudo docker volume inspect --format '{{ .Mountpoint }}' ftp_tls)/pure-ftpd.pem";\ + cert="$$($(S)docker volume inspect --format '{{ .Mountpoint }}' ftp_tls)/pure-ftpd.pem";\ echo "ls -alh\n\ put test-orig-file.txt\n\ echo '~ uploaded file ~'\n\ @@ -59,9 +67,9 @@ test-bob-tls: get test-orig-file.txt -o test-new-file.txt\n\ rm test-orig-file.txt\n\ echo '~ removed file ~'\n\ - ls -alh" | sudo lftp -u bob,test -e "set ssl:ca-file '$$cert'" localhost 21 + ls -alh" | $(S)lftp -u bob,test -e "set ssl:ca-file '$$cert'" localhost 21 cat test-new-file.txt - sudo rm test-orig-file.txt test-new-file.txt + $(S)rm test-orig-file.txt test-new-file.txt # git commands for quick chaining of make commands push: diff --git a/run.sh b/run.sh index 6f65f61..b405412 100644 --- a/run.sh +++ b/run.sh @@ -56,7 +56,7 @@ then # Generate the file that will be used to inject in the password prompt stdin PWD_FILE="$(mktemp)" echo "$FTP_USER_PASS -$FTP_USER_PASS" > "$PWD_FILE" + $FTP_USER_PASS" > "$PWD_FILE" # Set uid/gid PURE_PW_ADD_FLAGS="" @@ -95,8 +95,21 @@ $FTP_USER_PASS" > "$PWD_FILE" fi rm "$PWD_FILE" +else + echo 'Setting up anonymous access due to absence of user parameters' + useradd -d /var/ftp -s /sbin/nologin ftp + mkdir /var/ftp + pure-pw mkdb + #pure-pw useradd "ftp" -f "$PASSWD_FILE" -m -d "/var/ftp" + echo "done setting up anonymous access" fi +# # Setup anonymous access +# if [ -z "$ANONYMOUS" ] +# then +# echo 'Setting up anonymous access' +# useradd -d /var/ftp -s /sbin/nologin ftp +# fi # Set a default value to the env var FTP_PASSIVE_PORTS if [ -z "$FTP_PASSIVE_PORTS" ] then