FROM alpine:latest

# Installs
# - BorgBackup
# - OpenSSH client
RUN echo "Installing packages."
RUN apk update && apk add --no-cache \
    borgbackup \
    openssh \
    bash \
    tzdata

RUN echo "Copying app."   
COPY ./docker/app /app



# having some problems if app/scripts files not set with executable permissions 
# this is not working, so please confirm files are executable on host building docker file
# setting app owner.
# RUN chown -R root:root /app
#RUN echo "Setting app permissions"
#RUN chown -R root:root /app/scripts && find /app/scripts -type f -exec chmod +x {} \;
# use this entrypoint to verify final permissions on container
#ENTRYPOINT ["ls", "-lah", "/app/scripts"]


RUN echo "creating symbolic links to app/scripts."
RUN ln -s /app/scripts/loadenv /usr/local/bin/loadenv
RUN ln -s /app/scripts/remote-connect /usr/local/bin/remote-connect
RUN ln -s /app/scripts/remote-get-folder-size /usr/local/bin/remote-get-folder-size

RUN echo "creating .ssh folder."
RUN mkdir /root/.ssh
RUN echo "setting .ssh folder permissions."
RUN chmod 700 /root/.ssh

# for files inside correct permission is chmod 600 /root/.ssh/key

RUN echo "Setting loadenv to bashrc and bash_profile"

RUN echo "source /usr/local/bin/loadenv" > /root/.bash_profile 
RUN echo "source /usr/local/bin/loadenv" > /root/.bashrc

RUN echo "setting entrypoint."
ENTRYPOINT ["/app/scripts/entrypoint.sh"]

#CMD ["--help"]