From 1edf452e90fd12615d9b3974324f02b646437d5c Mon Sep 17 00:00:00 2001 From: Parabola automatic package builder Date: Mon, 23 Jun 2014 15:44:26 +0000 Subject: fix --- .gitconfig | 2 ++ .ssh/config | 6 ++++++ .ssh/known_hosts | 2 ++ bin/autobuild.c | 54 ++++++++++++++++++++++++++++++++++++++++++------------ bin/autobuild.sh | 34 ++++++++++++++++++++-------------- bin/setup | 25 ++++++++++++++++++++++--- 6 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 .ssh/config create mode 100644 .ssh/known_hosts diff --git a/.gitconfig b/.gitconfig index 74ee438..15afca0 100644 --- a/.gitconfig +++ b/.gitconfig @@ -1,3 +1,5 @@ [user] name = Parabola automatic package builder email = dev@lists.parabolagnulinux.org +[push] + default = simple diff --git a/.ssh/config b/.ssh/config new file mode 100644 index 0000000..1a90be7 --- /dev/null +++ b/.ssh/config @@ -0,0 +1,6 @@ +Host * + Protocol 2 + Compression yes +Host repo + Port 1863 + HostName repo.parabolagnulinux.org diff --git a/.ssh/known_hosts b/.ssh/known_hosts new file mode 100644 index 0000000..927ab67 --- /dev/null +++ b/.ssh/known_hosts @@ -0,0 +1,2 @@ +localhost,projects.parabolagnulinux.org,142.4.205.9,[projects.parabolagnulinux.org]:1863,[142.4.205.9]:1863 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHkqv9ewWyXjrO6P5iYiUYfEYP8ALBg9C2GxA7yOJDa/vwDtx6OS3KMNRkUgx6vL/6/D555Xdypys+lwLmcdmnM= +[repo.parabolagnulinux.org]:1863,[80.87.131.252]:1863 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBK4pzgrqj2qrklFpDZrg56bjVHJyodEtvdU/QUQNPgErfjfn0BJRi4N2zL19VK5ab3kJ6zJrfY7YWOv/Ky+MqUw= diff --git a/bin/autobuild.c b/bin/autobuild.c index 86d164c..4d0580f 100644 --- a/bin/autobuild.c +++ b/bin/autobuild.c @@ -14,13 +14,13 @@ * along with this program. If not, see . */ -#define _GNU_SOURCE /* for unsetenv(3) */ +#define _GNU_SOURCE /* for environment functions */ #include /* for alloca(3) */ #include /* for errno */ #include /* for error(3) */ #include /* for getpwuid(3) */ #include /* for printf(3) */ -#include /* for unsetenv(3) */ +#include /* for environment functions */ #include /* for strlen(3), strcpy(3) */ #include /* for dup2(3), geteuid(3), execl(3) */ @@ -28,7 +28,17 @@ void usage(const char *cmd) { printf("Usage: %s PACKAGE\n", cmd); - printf("This command should be run from the git directory of the package source."); + printf("This command should be run from the git directory of the package source.\n"); +} + +void +mysetenv(const char *name, const char *value) +{ + if (value != NULL) { + if (setenv(name, value, 1) != 0) { + error(127, errno, "could not set %s", name); + } + } } int @@ -40,17 +50,37 @@ main(int argc, char **argv) return 1; } - const char *home = getpwuid(geteuid())->pw_dir; - const char *script_suffix = "/bin/autobuild.sh"; - char *script = alloca(strlen(home)+strlen(script_suffix)); - strcpy(script, home); - strcpy(&(script[strlen(home)]), script_suffix); + struct passwd *user = getpwuid(geteuid()); + setreuid(geteuid(), -1); - unsetenv("IFS"); - unsetenv("PATH"); - unsetenv("LD_PRELOAD"); - unsetenv("BASH_ENV"); + printf("ruid:%d\teuid:%d\n", getuid(), geteuid()); + const char *env_term = getenv("TERM"); + const char *env_lang = getenv("LANG"); + const char *env_lc_all = getenv("LC_ALL"); + const char *env_lc_collate = getenv("LC_COLLATE"); + const char *env_lc_ctype = getenv("LC_CTIME"); + const char *env_lc_messages = getenv("LC_MESSAGES"); + const char *env_lc_monetary = getenv("LC_MONETARY"); + const char *env_lc_numeric = getenv("LC_NUMERIC"); + const char *env_lc_time = getenv("LC_TIME"); + clearenv(); + mysetenv("USER" , user->pw_name ); + mysetenv("LOGNAME" , user->pw_name ); + mysetenv("HOME" , user->pw_dir ); + mysetenv("TERM" , env_term ); + mysetenv("LANG" , env_lang ); + mysetenv("LC_ALL" , env_lc_all ); + mysetenv("LC_COLLATE" , env_lc_collate ); + mysetenv("LC_CTIME" , env_lc_ctype ); + mysetenv("LC_MESSAGES", env_lc_messages); + mysetenv("LC_MONETARY", env_lc_monetary); + mysetenv("LC_NUMERIC" , env_lc_numeric ); + mysetenv("LC_TIME" , env_lc_time ); + const char *script_suffix = "/bin/autobuild.sh"; + char *script = alloca(strlen(user->pw_dir)+strlen(script_suffix)); + strcpy(script, user->pw_dir); + strcpy(&(script[strlen(user->pw_dir)]), script_suffix); execl(script, script, argv[1], NULL); error(127, errno, "%s", script); } diff --git a/bin/autobuild.sh b/bin/autobuild.sh index ccf52ea..e12604c 100755 --- a/bin/autobuild.sh +++ b/bin/autobuild.sh @@ -17,11 +17,19 @@ # Get the date as the *very* first thing newpkgver_date=$(LC_ALL=C date -u +%Y%m%d) -################################################################################ +export PATH # because of setuid safety, path may be currently un-exported . "$(librelib messages)" setup_traps -# Option parsing +# Next: get the gitver as soon as possible, we don't want another commit to +# change it +if [[ $PWD != *.git ]]; then + die "should be run as a hook from a git repository" +fi +newgitver=$(git log -n1 --format='%H' master -- blacklist.txt) + +# Option parsing ############################################################### + if [[ $# != 1 ]]; then die "%q takes exactly 1 argument" "$0" fi @@ -31,21 +39,19 @@ if ! [[ $PACKAGE =~ $package_re ]]; then die "PACKAGE must be in the format REPO/PKGBASE: %s" "$PACKAGE" fi -# init -lock 9 "${HOME}/packages/lockdir/${PACKAGE}" "Waiting for previous run of %q to finish" "$0" +# It doesn't seem like it, but this is the earliest we can possibly lock +lock 9 "${HOME}/packages/lockdir/${PACKAGE}" \ + "Waiting for previous run of %q to finish" "$0" + +################################################################################ . "$(librelib conf)" || exit 1 load_files libretools || exit 1 check_vars libretools WORKDIR ABSLIBRERECV ABSLIBRESEND || exit 1 -if [[ $PWD != *.git ]]; then - die "should be run as a hook from a git repository" -fi -newgitver=$(git log -n1 --format='%H' master -- blacklist.txt) - # Get the ABSLibre tree gitget -f -p "$ABSLIBRESEND" checkout "$ABSLIBRERECV" "$WORKDIR/abslibre" -if [[ -f "${WORKDIR}/abslibre/${PACKAGE}/PKGBUILD" ]]; then +if ! [[ -f "${WORKDIR}/abslibre/${PACKAGE}/PKGBUILD" ]]; then die "package does not exist in abslibre.git: %s" "$PACKAGE" fi cd "$WORKDIR/abslibre/${PACKAGE}" @@ -54,7 +60,7 @@ cd "$WORKDIR/abslibre/${PACKAGE}" oldgitver=$(sed -n 's/^_gitver=//p' PKGBUILD) oldpkgver=$(sed -n 's/^pkgver=//p' PKGBUILD) oldpkgver_date=${oldpkgver%%.*} -oldpkgver_rel=${oldpkgver#${oldpkgver_date}}; oldpkgver_rel=${oldpkgver_rel#.} oldpkgver_rel=${oldpkgver_rel:-0} +oldpkgver_rel=${oldpkgver#${oldpkgver_date}}; oldpkgver_rel=${oldpkgver_rel#.}; oldpkgver_rel=${oldpkgver_rel:-0} # Make sure we actually have changes if [[ "$newgitver" == "$oldgitver" ]]; then @@ -71,8 +77,8 @@ else fi # Update the PKGBUILD -sed -i -e 's|^pkgver=.*|pkgver=${newpkgver}|' \ - -e 's|^_gitver=.*|_gitver=${newgitver}|' \ +sed -i -e "s|^pkgver=.*|pkgver=${newpkgver}|" \ + -e "s|^_gitver=.*|_gitver=${newgitver}|" \ -e 's|^pkgrel=.*|pkgrel=1|' \ PKGBUILD updpkgsums @@ -80,7 +86,7 @@ git add PKGBUILD git commit -m 'Update libre/your-freedom' # Build the new package -makepkg +makepkg -c librestage libre # Publish the updates diff --git a/bin/setup b/bin/setup index ea6b92c..2a81748 100755 --- a/bin/setup +++ b/bin/setup @@ -2,10 +2,23 @@ CFLAGS += -std=c99 -Wall -Wextra -Werror -all: $(HOME)/bin/autobuild $(HOME)/.ssh/id_rsa $(HOME)/.ssh/id_rsa.pub $(HOME)/.gnupg/secring.gpg +dirs = \ + $(HOME)/packages/pkgdest \ + $(HOME)/packages/srcdest \ + $(HOME)/packages/srcpkgdest \ + $(HOME)/packages/logdest \ + $(HOME)/packages/builddir -$(HOME)/bin/autobuild: $(HOME)/bin/autobuild.c - $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ && chmod 6755 $@ +all: \ + $(HOME)/bin/autobuild \ + $(HOME)/.ssh/id_rsa \ + $(HOME)/.ssh/id_rsa.pub \ + $(HOME)/.gnupg/secring.gpg \ + $(HOME)/packages/abslibre \ + $(dirs) + +autobuild $(HOME)/bin/autobuild: $(HOME)/bin/autobuild.c + $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ && chmod 6755 $@ $(HOME)/.ssh/id_rsa $(HOME)/.ssh/id_rsa.pub: ssh-keygen -N '' -f $@ @@ -19,4 +32,10 @@ $(HOME)/.gnupg/secring.gpg: 'Expire-Date: 0' \ | gpg --gen-key --batch +$(HOME)/packages/abslibre: + createworkdir + +$(dirs): %: + mkdir -p -- $@ + .DELETE_ON_ERROR: -- cgit v1.2.2