🏡 index : github.com/captn3m0/outliner.git

author Nemo <me@captnemo.in> 2020-04-26 6:14:36.0 +05:30:00
committer Nemo <me@captnemo.in> 2020-04-26 6:19:43.0 +05:30:00
commit
16e5ea504aebc0afbd90b2276df8b93e0e57edd4 [patch]
tree
96d7d0a14d4c832fc26f0138470ee0f49d61dbd4
parent
a264f8c2d9dabd2e82e058aad5403776b15f2983
download
16e5ea504aebc0afbd90b2276df8b93e0e57edd4.tar.gz

[sync] Adds proper sync support



Diff

 .gitignore       |  1 +
 Dockerfile       |  2 +-
 LICENSE          |  4 ++--
 entrypoint.sh    | 28 ++++++++++++++++++++++++----
 env.sample       |  4 ++++
 outliner.gemspec |  2 +-
 6 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/.gitignore b/.gitignore
index 78356df..2784239 100644
--- a/.gitignore
+++ a/.gitignore
@@ -9,3 +9,4 @@
/vendor/
Gemfile.lock
*.gem
.env
diff --git a/Dockerfile b/Dockerfile
index d9113aa..b922cc3 100644
--- a/Dockerfile
+++ a/Dockerfile
@@ -5,7 +5,7 @@

RUN gem install bundler && \
    bundle install && \
    apk add --no-cache git openssh-client && \
    apk add --no-cache git openssh-client rsync && \
    echo -e "StrictHostKeyChecking no" >> /etc/ssh/ssh_config && \
    mkdir /root/.ssh

diff --git a/LICENSE b/LICENSE
index b21898b..1615a9b 100644
--- a/LICENSE
+++ a/LICENSE
@@ -1,7 +1,7 @@
Copyright 2019 Abhay Rana
Copyright 2020 Abhay Rana

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/entrypoint.sh b/entrypoint.sh
index 4ac69cb..f6ad9b5 100755
--- a/entrypoint.sh
+++ a/entrypoint.sh
@@ -41,22 +41,36 @@
    bundle exec outliner-import "$@"
    ;;
  sync)
    tmp_dir=$(mktemp -d)
    BRANCH=${GIT_BRANCH:-master}
    old_git_dir=$(mktemp -d)
    fresh_export_dir=$(mktemp -d)
    if [ -z "$GIT_REMOTE_URL" ]; then
      echo "[E] GIT_REMOTE_URL not set"
      exit 1
    else
      git clone --branch "$BRANCH" "$GIT_REMOTE_URL" "$old_git_dir"
      setup_git
      bundle exec outliner-export "$tmp_dir"
      cd "$tmp_dir"
      git init
      update_git_config
      echo "[+] Exporting data from Outline"
      bundle exec outliner-export "$fresh_export_dir"
      echo "[+] Resetting git repository"
      cd "$old_git_dir"
      # We update so that git forgets all files
      git ls-files -z |xargs -n1 -0 git rm
      # Then we copy across the files from the new export
      cd "$fresh_export_dir"
      echo "[+] Updating git repository"
      rsync -av . "$old_git_dir"
      cd "$old_git_dir"
      echo "[+] Committing to git"
      git add .
      git commit --message "Backup: $(date)" > /dev/null
      BRANCH=${GIT_BRANCH:-master}
      git checkout -b "$BRANCH"
      git status
      git push origin --force "HEAD:$BRANCH"
      echo "[+] Pushing to git remote"
      git push origin "HEAD:$BRANCH"
      echo "[+] Cleaning up"
      rm -rf "$old_git_dir"
      rm -rf "$fresh_export_dir"
    fi
    ;;
  *)
diff --git a/env.sample b/env.sample
new file mode 100644
index 0000000..6d221eb 100644
--- /dev/null
+++ a/env.sample
@@ -1,0 +1,4 @@
OUTLINE_BASE_URI=https://outline.example.com
GIT_BRANCH=master
GIT_REMOTE_URL=git@example.com:org/outline.backup.git
OUTLINE_TOKEN=
diff --git a/outliner.gemspec b/outliner.gemspec
index 9aeda22..06d2ec0 100644
--- a/outliner.gemspec
+++ a/outliner.gemspec
@@ -7,7 +7,7 @@
  spec.name          = "outliner"
  spec.version       = Outliner::VERSION
  spec.authors       = ["Nemo"]
  spec.email         = ["rubygem.outliner@captnemo.in"]
  spec.email         = ["outliner@captnemo.in"]
  spec.licenses      = ["MIT"]

  spec.summary       = "A simple HTTParty based client for outline knowledge base."