diff --git a/examples/shell_provider.sh b/examples/shell_provider.sh index 9e949dc..4ffbd4b 100755 --- a/examples/shell_provider.sh +++ b/examples/shell_provider.sh @@ -2,5 +2,6 @@ echo $TUNASYNC_WORKING_DIR echo $TUNASYNC_LOG_FILE echo $TUNASYNC_UPSTREAM_URL +echo $REPO sleep 5 exit 1 diff --git a/examples/tunasync.conf b/examples/tunasync.conf index 6cc2600..6db68c5 100644 --- a/examples/tunasync.conf +++ b/examples/tunasync.conf @@ -58,5 +58,18 @@ command = "./shell_provider.sh" upstream = "https://pypi.python.org/" # log_file = "/tmp/arch4-{date}.log" use_btrfs = false + # set environment varialbes + [mirrors.env] + REPO = "/usr/local/bin/repo" -# vim: ft=toml +[[mirrors]] +name = "arch5" +provider = "shell" +command = "./shell_provider.sh" +upstream = "https://pypi.python.org/" +# log_file = "/tmp/arch4-{date}.log" +use_btrfs = false + [mirrors.env] + REPO = "/usr/local/bin/repo2" + +# vim: ft=toml ts=2 sts=2 sw=2 diff --git a/scripts/android.sh b/scripts/android.sh deleted file mode 100755 index 15a9f38..0000000 --- a/scripts/android.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -function sync_android() { - cd $TUNASYNC_WORKING_DIR - /usr/local/bin/android-repo sync -f -} - -function update_repo_config() { - for repo in $(find $TUNASYNC_WORKING_DIR -type d -not -path "*/.repo/*" -name "*.git") - do - cd $repo - echo $repo - git config pack.threads 1 - done -} - -sync_android -update_repo_config diff --git a/scripts/aosp.sh b/scripts/aosp.sh new file mode 100755 index 0000000..71ac834 --- /dev/null +++ b/scripts/aosp.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +REPO=${REPO:-"/usr/local/bin/repo"} + +function repo_init() { + mkdir -p $TUNASYNC_WORKING_DIR + cd $TUNASYNC_WORKING_DIR + $REPO init -u https://android.googlesource.com/mirror/manifest --mirror +} + +function repo_sync() { + cd $TUNASYNC_WORKING_DIR + $REPO sync -f +} + +if [ ! -d "$TUNASYNC_WORKING_DIR/git-repo.git" ]; then + echo "Initializing AOSP mirror" + repo_init +fi + +repo_sync diff --git a/tunasync/mirror_config.py b/tunasync/mirror_config.py index ea7bc50..8f57198 100644 --- a/tunasync/mirror_config.py +++ b/tunasync/mirror_config.py @@ -53,6 +53,9 @@ class MirrorConfig(object): self.options["use_btrfs"] = self._parent.use_btrfs assert self.options["use_btrfs"] in (True, False) + if "env" in self.options: + assert isinstance(self.options["env"], dict) + def __getattr__(self, key): if key in self.__dict__: return self.__dict__[key] @@ -68,6 +71,7 @@ class MirrorConfig(object): 'log_dir': self.log_dir, 'log_file': self.log_file, 'interval': self.interval, + 'env': self.env, 'hooks': hooks, } diff --git a/tunasync/mirror_provider.py b/tunasync/mirror_provider.py index 7da145a..a7b9bdb 100644 --- a/tunasync/mirror_provider.py +++ b/tunasync/mirror_provider.py @@ -65,7 +65,7 @@ class RsyncProvider(MirrorProvider): def __init__(self, name, upstream_url, local_dir, log_dir, useIPv6=True, password=None, exclude_file=None, - log_file="/dev/null", interval=120, hooks=[]): + log_file="/dev/null", interval=120, env=None, hooks=[]): super(RsyncProvider, self).__init__(name, local_dir, log_dir, log_file, interval, hooks) @@ -73,6 +73,7 @@ class RsyncProvider(MirrorProvider): self.useIPv6 = useIPv6 self.exclude_file = exclude_file self.password = password + self.env = env @property def options(self): @@ -99,6 +100,9 @@ class RsyncProvider(MirrorProvider): new_env = os.environ.copy() if self.password is not None: new_env["RSYNC_PASSWORD"] = self.password + if self.env is not None and isinstance(self.env, dict): + for k, v in self.env.items(): + new_env[k] = v self.p = sh.rsync(*_args, _env=new_env, _out=log_file, _err_to_out=True, _out_bufsize=1, _bg=True) @@ -153,6 +157,9 @@ class TwoStageRsyncProvider(RsyncProvider): new_env = os.environ.copy() if self.password is not None: new_env["RSYNC_PASSWORD"] = self.password + if self.env is not None and isinstance(self.env, dict): + for k, v in self.env.items(): + new_env[k] = v with open(log_file, 'w', buffering=1) as f: def log_output(line): @@ -175,13 +182,15 @@ class TwoStageRsyncProvider(RsyncProvider): class ShellProvider(MirrorProvider): def __init__(self, name, command, upstream_url, local_dir, log_dir, - log_file="/dev/null", log_stdout=True, interval=120, hooks=[]): + log_file="/dev/null", log_stdout=True, interval=120, env=None, + hooks=[]): super(ShellProvider, self).__init__(name, local_dir, log_dir, log_file, interval, hooks) self.upstream_url = str(upstream_url) self.command = shlex.split(command) self.log_stdout = log_stdout + self.env = env def run(self, ctx={}): @@ -194,6 +203,10 @@ class ShellProvider(MirrorProvider): new_env["TUNASYNC_UPSTREAM_URL"] = self.upstream_url new_env["TUNASYNC_LOG_FILE"] = log_file + if self.env is not None and isinstance(self.env, dict): + for k, v in self.env.items(): + new_env[k] = v + _cmd = self.command[0] _args = [] if len(self.command) == 1 else self.command[1:]