From 37a0f576f84b8da7e18c3b104763ec670dbb3c1c Mon Sep 17 00:00:00 2001 From: sparklyballs Date: Sun, 21 Aug 2016 02:57:48 +0100 Subject: [PATCH] first save up --- Dockerfile | 16 ++++++++++++++++ README.md | 6 ++++++ root/defaults/backup | 2 ++ root/defaults/script.sh | 23 +++++++++++++++++++++++ root/etc/cont-init.d/30-config | 21 +++++++++++++++++++++ root/etc/services.d/cron/run | 4 ++++ 6 files changed, 72 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 root/defaults/backup create mode 100644 root/defaults/script.sh create mode 100644 root/etc/cont-init.d/30-config create mode 100644 root/etc/services.d/cron/run diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..369ae8e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM lsiobase/alpine +MAINTAINER sparklyballs + +# install packages +RUN \ + apk add --no-cache \ + curl \ + findutils \ + git \ + python + +# add local files +COPY root/ / + +# ports and volumes +VOLUME /backup /config diff --git a/README.md b/README.md new file mode 100644 index 0000000..cdc14cc --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +THIS IS NOT SOMETHING FOR PUBLIC USE + +YOU HAVE BEEN WARNED !!!! + +HERE BE DRAGONS + diff --git a/root/defaults/backup b/root/defaults/backup new file mode 100644 index 0000000..120e7b1 --- /dev/null +++ b/root/defaults/backup @@ -0,0 +1,2 @@ +21 02 * * * /bin/sh /defaults/script.sh + diff --git a/root/defaults/script.sh b/root/defaults/script.sh new file mode 100644 index 0000000..dd7720a --- /dev/null +++ b/root/defaults/script.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# set variables +unset FOLDER_DATE FOLDER_MAKE REPO_USER +FOLDER_DATE=$(date '+%d-%b-%Y') +FOLDER_MAKE="/backup/${FOLDER_DATE}" +REPO_USER="" + +# delete folders older than 20 days +for i in $(find /backup/ -maxdepth 1 -type d -mtime +20 -print); do echo -e "Deleting directory $i";rm -rf $i; done + +# make today's folder +if [ -d "${FOLDER_MAKE}" ]; then +rm -rf "${FOLDER_MAKE}" +fi +mkdir -p "${FOLDER_MAKE}" && touch "${FOLDER_MAKE}" + +# clone git repositories into todays folder +cd "${FOLDER_MAKE}" +curl -s "https://api.github.com/users/${REPO_USER}/repos?per_page=200" | python -c $'import json, sys, os\nfor repo in json.load(sys.stdin): os.system("git clone " + repo["clone_url"])' + +# permissions +chown -R abc:abc "${FOLDER_MAKE}" diff --git a/root/etc/cont-init.d/30-config b/root/etc/cont-init.d/30-config new file mode 100644 index 0000000..e372831 --- /dev/null +++ b/root/etc/cont-init.d/30-config @@ -0,0 +1,21 @@ +#!/usr/bin/with-contenv bash + +# copy cronjob to /config +[[ ! -e /config/backup ]] && \ +cp /defaults/backup /config/backup + +# set user repo +if [[ -z $USER_REPO ]]; then +USER_REPO="linuxserver" +fi + +sed -i "s/REPO_USER=\".*\"/REPO_USER=\"${USER_REPO}\"/g" /defaults/script.sh + +# set cron job +crontab /config/backup + +# permissions +chown -R abc:abc \ + /config +chown abc:abc \ + /backup diff --git a/root/etc/services.d/cron/run b/root/etc/services.d/cron/run new file mode 100644 index 0000000..9d6dfe3 --- /dev/null +++ b/root/etc/services.d/cron/run @@ -0,0 +1,4 @@ +#!/usr/bin/with-contenv bash + +/usr/sbin/crond -f -S -l 0 -c /etc/crontabs +