aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-05-31 02:52:43 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-05-31 02:52:43 +0200
commit4ab4c1d0ba31d437e05792719fba664a94521819 (patch)
tree953bf2925e1c96f95be28132a5459b82bd5a51bf
parent56e07b6224fce7e213bfb9b4d00b93628a50aca7 (diff)
downloadblogc-4ab4c1d0ba31d437e05792719fba664a94521819.tar.gz
blogc-4ab4c1d0ba31d437e05792719fba664a94521819.tar.bz2
blogc-4ab4c1d0ba31d437e05792719fba664a94521819.zip
git-receiver: allow users to define builds dir
-rw-r--r--man/blogc-git-receiver.1.ronn16
-rw-r--r--src/blogc-git-receiver/pre-receive.c9
-rw-r--r--src/blogc-git-receiver/settings.c19
-rw-r--r--src/blogc-git-receiver/settings.h3
-rw-r--r--src/blogc-git-receiver/shell.c2
-rwxr-xr-xtests/blogc-git-receiver/check_post_receive.sh.in2
-rwxr-xr-xtests/blogc-git-receiver/check_pre_receive.sh.in5
-rw-r--r--tests/blogc-git-receiver/check_settings.c2
8 files changed, 40 insertions, 18 deletions
diff --git a/man/blogc-git-receiver.1.ronn b/man/blogc-git-receiver.1.ronn
index 7386909..5759bac 100644
--- a/man/blogc-git-receiver.1.ronn
+++ b/man/blogc-git-receiver.1.ronn
@@ -147,13 +147,21 @@ your mirror repository.
## ENVIRONMENT
-The following variable can be set in the SSH Server (usually in `~/.ssh/environment`)
+The following variables can be set in the SSH Server (usually in `~/.ssh/environment`)
to change `blogc-git-receiver` behaviour:
- * `BLOGC_GIT_RECEIVER_BASEDIR`:
- Path to a directory that should be used by `blogc-git-receiver` instead of the
- user's home directory. Useful for shared hosting environments that only provide
+ * `BLOGC_GIT_RECEIVER_BASE_DIR`:
+ Path to the base directory that should be used by `blogc-git-receiver`. Defaults
+ to user's home directory. Useful for shared hosting environments that only provide
one shell user.
+ * `BLOGC_GIT_RECEIVER_BUILDS_DIR`:
+ Path to the directory that should be used to store the blogc builds. Defaults
+ to `$BLOGC_GIT_RECEIVER_BASE_DIR/builds`. This directory must be readable by
+ your webserver. This variable is useful to keep your git repositories unreadable,
+ while letting your webserver access the built files`1. In this case, users need to
+ also define custom symlinks for every repository in
+ `$BLOGC_GIT_RECEIVER_BASE_DIR/blogc-git-receiver.ini`, because the default
+ `htdocs` symlink inside the git repositories won't be acessible by the webserver.
The following variable is exported by `blogc-git-receiver` when building websites
with make(1):
diff --git a/src/blogc-git-receiver/pre-receive.c b/src/blogc-git-receiver/pre-receive.c
index 897e8f0..9611567 100644
--- a/src/blogc-git-receiver/pre-receive.c
+++ b/src/blogc-git-receiver/pre-receive.c
@@ -199,15 +199,16 @@ default_sym:
goto cleanup;
}
- const char *bd = bgr_settings_get_basedir();
- if (bd == NULL) {
- fprintf(stderr, "error: failed to find user base directory path\n");
+ char *buildsd = bgr_settings_get_builds_dir();
+ if (buildsd == NULL) {
+ fprintf(stderr, "error: failed to find builds directory path\n");
rv = 3;
goto cleanup;
}
unsigned long epoch = time(NULL);
- output_dir = bc_strdup_printf("%s/builds/%s-%lu", bd, master, epoch);
+ output_dir = bc_strdup_printf("%s/%s-%lu", buildsd, master, epoch);
+ free(buildsd);
if (0 == access(output_dir, F_OK)) {
char *tmp = output_dir;
diff --git a/src/blogc-git-receiver/settings.c b/src/blogc-git-receiver/settings.c
index 514fcdf..4cfcaf7 100644
--- a/src/blogc-git-receiver/settings.c
+++ b/src/blogc-git-receiver/settings.c
@@ -20,9 +20,9 @@
const char*
-bgr_settings_get_basedir(void)
+bgr_settings_get_base_dir(void)
{
- char *rv = getenv("BLOGC_GIT_RECEIVER_BASEDIR");
+ char *rv = getenv("BLOGC_GIT_RECEIVER_BASE_DIR");
if (rv != NULL) {
return rv;
}
@@ -31,9 +31,20 @@ bgr_settings_get_basedir(void)
char*
+bgr_settings_get_builds_dir(void)
+{
+ char *rv = getenv("BLOGC_GIT_RECEIVER_BUILDS_DIR");
+ if (rv != NULL) {
+ return bc_strdup(rv);
+ }
+ return bc_strdup_printf("%s/builds", bgr_settings_get_base_dir());
+}
+
+
+char*
bgr_settings_get_section(bc_config_t *config, const char *repo_path)
{
- const char *bd = bgr_settings_get_basedir();
+ const char *bd = bgr_settings_get_base_dir();
if (bd == NULL) {
return NULL;
}
@@ -62,7 +73,7 @@ bgr_settings_get_section(bc_config_t *config, const char *repo_path)
bc_config_t*
bgr_settings_parse(void)
{
- const char *bd = bgr_settings_get_basedir();
+ const char *bd = bgr_settings_get_base_dir();
if (bd == NULL) {
return NULL;
}
diff --git a/src/blogc-git-receiver/settings.h b/src/blogc-git-receiver/settings.h
index 1b89d0f..bb6649a 100644
--- a/src/blogc-git-receiver/settings.h
+++ b/src/blogc-git-receiver/settings.h
@@ -11,7 +11,8 @@
#include "../common/config-parser.h"
-const char* bgr_settings_get_basedir(void);
+const char* bgr_settings_get_base_dir(void);
+char* bgr_settings_get_builds_dir(void);
char* bgr_settings_get_section(bc_config_t *config, const char *repo_path);
bc_config_t* bgr_settings_parse(void);
diff --git a/src/blogc-git-receiver/shell.c b/src/blogc-git-receiver/shell.c
index f2eaf32..8c45b54 100644
--- a/src/blogc-git-receiver/shell.c
+++ b/src/blogc-git-receiver/shell.c
@@ -36,7 +36,7 @@ bgr_shell(int argc, char *argv[])
}
// get base dir path
- const char *bd = bgr_settings_get_basedir();
+ const char *bd = bgr_settings_get_base_dir();
if (bd == NULL) {
fprintf(stderr, "error: failed to find base directory path\n");
rv = 3;
diff --git a/tests/blogc-git-receiver/check_post_receive.sh.in b/tests/blogc-git-receiver/check_post_receive.sh.in
index f0dde80..74d4df2 100755
--- a/tests/blogc-git-receiver/check_post_receive.sh.in
+++ b/tests/blogc-git-receiver/check_post_receive.sh.in
@@ -110,7 +110,7 @@ mirror = ${TEMP}/repos/bar6.git
mirror = lol
EOF
git init --bare "${TEMP}/repos/bar6.git" &> /dev/null
-BLOGC_GIT_RECEIVER_BASEDIR="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo.git/hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
+BLOGC_GIT_RECEIVER_BASE_DIR="${TEMP}" ${TESTS_ENVIRONMENT} ./repos/foo.git/hooks/post-receive 2>&1 | tee "${TEMP}/output.txt"
grep "[new branch] *master" "${TEMP}/output.txt" &> /dev/null
rm "${TEMP}/output.txt"
diff --git a/tests/blogc-git-receiver/check_pre_receive.sh.in b/tests/blogc-git-receiver/check_pre_receive.sh.in
index 4a670e1..2a9aa91 100755
--- a/tests/blogc-git-receiver/check_pre_receive.sh.in
+++ b/tests/blogc-git-receiver/check_pre_receive.sh.in
@@ -100,7 +100,7 @@ symlink = ${TEMP}/chunda
symlink = ${TEMP}/guda
EOF
-SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
+SHELL="${SELF}" HOME="${TEMP}" GIT_DIR=. BLOGC_GIT_RECEIVER_BUILDS_DIR="${TEMP}/foooo" ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt"
grep "echo lol" "${TEMP}/output.txt" &> /dev/null
[[ -h "${TEMP}/chunda" ]]
@@ -108,6 +108,7 @@ grep "echo lol" "${TEMP}/output.txt" &> /dev/null
DEST="$(readlink "${TEMP}/chunda")"
[[ -e "${DEST}" ]]
+[[ "${DEST}" == "${TEMP}/foooo/"* ]]
cd "${TEMP}"
git init --bare "${TEMP}/repos/foo2a.git" &> /dev/null
@@ -278,7 +279,7 @@ EOF
0000000000000000000000000000000000000000 $(git rev-parse HEAD) refs/heads/master
EOF
- SHELL="${SELF}" BLOGC_GIT_RECEIVER_BASEDIR="${TEMP}" PATH="@abs_top_builddir@:${PATH}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" || true
+ SHELL="${SELF}" BLOGC_GIT_RECEIVER_BASE_DIR="${TEMP}" PATH="@abs_top_builddir@:${PATH}" GIT_DIR=. ${TESTS_ENVIRONMENT} ./hooks/pre-receive < "${TEMP}/payload.txt" 2>&1 | tee "${TEMP}/output.txt" || true
grep "blogc-make: error: settings: " "${TEMP}/output.txt" &> /dev/null
fi
diff --git a/tests/blogc-git-receiver/check_settings.c b/tests/blogc-git-receiver/check_settings.c
index 63caa0c..3c757b2 100644
--- a/tests/blogc-git-receiver/check_settings.c
+++ b/tests/blogc-git-receiver/check_settings.c
@@ -59,7 +59,7 @@ test_settings_get_section(void **state)
free(s);
bc_config_free(config);
- setenv("BLOGC_GIT_RECEIVER_BASEDIR", "/home/bola", 1);
+ setenv("BLOGC_GIT_RECEIVER_BASE_DIR", "/home/bola", 1);
will_return(__wrap_realpath, NULL);
will_return(__wrap_realpath, "/home/bola/repos/asd/bar.git");
conf =