summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-03-11 14:38:51 +0100
committerdrebs <drebs@leap.se>2017-03-11 14:38:51 +0100
commit3ec21a7a6b39b4fe8885f3050ab75402e6812a1f (patch)
tree300a2d8da67bbc7c6484f9ee136a4a18c41c48c6 /scripts
parentc379a58d84fbf061b8d046057e45089f0e3c65f6 (diff)
parent3eefcb7d138ef41932a748ae729bfa0b629758d2 (diff)
Merge tag '0.9.3' into debian/platform-0.9
0.9.3 Conflicts: server/pkg/soledad-server server/pkg/soledad-server.service
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/deploy/deploy_soledad_from_git52
-rwxr-xr-xscripts/migration/0.9.0/migrate.py4
-rw-r--r--scripts/migration/0.9.0/migrate_couch_schema/__init__.py35
-rwxr-xr-xscripts/packaging/build-deb.sh32
-rwxr-xr-xscripts/packaging/build_debian_package.sh32
5 files changed, 118 insertions, 37 deletions
diff --git a/scripts/deploy/deploy_soledad_from_git b/scripts/deploy/deploy_soledad_from_git
new file mode 100755
index 00000000..3c4ac8be
--- /dev/null
+++ b/scripts/deploy/deploy_soledad_from_git
@@ -0,0 +1,52 @@
+#!/bin/bash
+######################################################
+# Deploy soledad-server from a given remote and branch
+# valid remotes are: origin shyba drebs kali
+# DO NOT USE IN PRODUCTION OR I'LL SEND NINJAS TO YOUR
+# HOUSE!!!!
+# (c) LEAP, 2017
+######################################################
+set -e
+
+REMOTE=$1
+BRANCH=$2
+
+if [ "$#" -lt 2 ]; then
+ echo "USAGE: $0 REMOTE BRANCH"
+ exit 1
+fi
+
+SOLEDADPATH="/usr/lib/python2.7/dist-packages/leap/soledad/server"
+REPO="https://0xacab.org/leap/soledad"
+LOCALREPO="$HOME/soledad"
+SYSTEMDINIT="/lib/systemd/system/soledad-server.service"
+
+apt remove --yes soledad-server
+
+if [ ! -d "$LOCALREPO" ]; then
+ echo "soledad repo not found, cloning..."
+ cd $HOME
+ git clone $REPO
+ cd $LOCALREPO
+ git remote add shyba https://0xacab.org/shyba/soledad.git
+ git remote add drebs https://0xacab.org/drebs/soledad.git
+ git remote add kali https://0xacab.org/kali/soledad.git
+fi
+
+cd $LOCALREPO && git checkout -- . && git fetch $REMOTE && git checkout $REMOTE/$BRANCH
+rm -rf $SOLEDADPATH
+
+# copy over some stuff that we'll need -- stolen from debian package
+cp -r $LOCALREPO/server/src/leap/soledad/server $SOLEDADPATH
+cp $LOCALREPO/server/pkg/soledad-server.service $SYSTEMDINIT
+cp $LOCALREPO/server/pkg/create-user-db /usr/bin/
+cp $LOCALREPO/server/pkg/soledad-sudoers /etc/sudoers.d/
+
+# Let's append the branch info to the version string! So that nobody is lost
+cd $LOCALREPO && echo "__version__ = '"`git describe`"~"`git status | head -n 1 | cut -d' ' -f 4`"'" >> $SOLEDADPATH/__init__.py
+
+# restart the daemon
+systemctl --system daemon-reload >/dev/null || true
+deb-systemd-invoke restart soledad-server.service >/dev/null || true
+
+tail -n 20 /var/log/syslog
diff --git a/scripts/migration/0.9.0/migrate.py b/scripts/migration/0.9.0/migrate.py
index 6ad5bc2d..7b2ec005 100755
--- a/scripts/migration/0.9.0/migrate.py
+++ b/scripts/migration/0.9.0/migrate.py
@@ -27,14 +27,14 @@ import os
from argparse import ArgumentParser
-from leap.soledad.server import load_configuration
+from leap.soledad.server import get_config
from migrate_couch_schema import migrate
TARGET_VERSION = '0.8.2'
DEFAULT_COUCH_URL = 'http://127.0.0.1:5984'
-CONF = load_configuration('/etc/soledad/soledad-server.conf')
+CONF = get_config()
NETRC_PATH = CONF['soledad-server']['admin_netrc']
diff --git a/scripts/migration/0.9.0/migrate_couch_schema/__init__.py b/scripts/migration/0.9.0/migrate_couch_schema/__init__.py
index f0b456e4..d1560c59 100644
--- a/scripts/migration/0.9.0/migrate_couch_schema/__init__.py
+++ b/scripts/migration/0.9.0/migrate_couch_schema/__init__.py
@@ -30,7 +30,7 @@ def _get_couch_server(couch_url):
return Server(couch_url)
-def _is_migrateable(db):
+def _has_u1db_config_doc(db):
config_doc = db.get('u1db_config')
return bool(config_doc)
@@ -63,6 +63,35 @@ def _get_user_dbs(server):
# migration main functions
#
+def _report_missing_u1db_config_doc(dbname, db):
+ config_doc = db.get(CONFIG_DOC_ID)
+ if not config_doc:
+ logger.warning(
+ "[%s] no '%s' or '%s' documents found, possibly an empty db? I "
+ "don't know what to do with this db, so I am skipping it."
+ % (dbname, 'u1db_config', CONFIG_DOC_ID))
+ else:
+ if SCHEMA_VERSION_KEY in config_doc:
+ version = config_doc[SCHEMA_VERSION_KEY]
+ if version == SCHEMA_VERSION:
+ logger.info(
+ "[%s] '%s' document exists, and schema versions match "
+ "(expected %r and found %r). This database reports to be "
+ "using the new schema version, so I am skipping it."
+ % (dbname, CONFIG_DOC_ID))
+ else:
+ logger.error(
+ "[%s] '%s' document exists, but schema versions don't "
+ "match (expected %r, found %r instead). I don't know "
+ "how to migrate such a db, so I am skipping it."
+ % (dbname, CONFIG_DOC_ID, SCHEMA_VERSION, version))
+ else:
+ logger.error(
+ "[%s] '%s' document exists, but has no schema version "
+ "information in it. I don't know how to migrate such a db, "
+ "so I am skipping it." % (dbname, CONFIG_DOC_ID))
+
+
def migrate(args, target_version):
server = _get_couch_server(args.couch_url)
logger.info('starting couch schema migration to %s' % target_version)
@@ -71,8 +100,8 @@ def migrate(args, target_version):
user_dbs = _get_user_dbs(server)
for dbname in user_dbs:
db = server[dbname]
- if not _is_migrateable(db):
- logger.warning("[%s] skipping not migrateable user db" % dbname)
+ if not _has_u1db_config_doc(db):
+ _report_missing_u1db_config_doc(dbname, db)
continue
logger.info("[%s] starting migration of user db" % dbname)
try:
diff --git a/scripts/packaging/build-deb.sh b/scripts/packaging/build-deb.sh
new file mode 100755
index 00000000..f7dd22a0
--- /dev/null
+++ b/scripts/packaging/build-deb.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# This script generates a debian package from your current repository tree
+# (including modified and unstaged files), using the debian directory from the
+# latest debian/platform-X.Y branch.
+#
+# In order to achieve that, what it does is:
+#
+# - copy the current repository into a temporary directory.
+# - find what is the latest "debian/platform-X.Y" branch.
+# - checkout the "debian/" directory from that branch.
+# - update the "debian/changelog" file with dummy information.
+# - run "debuild -uc -us".
+
+debemail="Leap Automatic Deb Builder <deb@leap.se>"
+scriptdir=$(dirname "${0}")
+gitroot=$(git -C "${scriptdir}" rev-parse --show-toplevel)
+deb_branch=$(git -C "${gitroot}" branch | grep "debian/platform" | sort | tail -n 1 | xargs)
+reponame=$(basename "${gitroot}")
+tempdir=$(mktemp -d)
+targetdir="${tempdir}/${reponame}"
+
+cp -r "${gitroot}" "${tempdir}/${reponame}"
+git -C "${targetdir}" checkout "${deb_branch}" -- debian
+
+(cd "${targetdir}" && DEBEMAIL="${debemail}" dch -b "Automatic build.")
+(cd "${targetdir}" && debuild -uc -us)
+
+echo "****************************************"
+echo "Packages can be found in: ${tempdir}"
+ls "${tempdir}"
+echo "****************************************"
diff --git a/scripts/packaging/build_debian_package.sh b/scripts/packaging/build_debian_package.sh
deleted file mode 100755
index b9fb93a9..00000000
--- a/scripts/packaging/build_debian_package.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-
-# This script generates Soledad Debian packages.
-#
-# When invoking this script, you should pass a git repository URL and the name
-# of the branch that contains the code you wish to build the packages from.
-#
-# The script will clone the given branch from the given repo, as well as the
-# main Soledad repo in github which contains the most up-to-date debian
-# branch. It will then merge the desired branch into the debian branch and
-# build the packages.
-
-if [ $# -ne 2 ]; then
- echo "Usage: ${0} <url> <branch>"
- exit 1
-fi
-
-SOLEDAD_MAIN_REPO=git://github.com/leapcode/soledad.git
-
-url=$1
-branch=$2
-workdir=`mktemp -d`
-
-git clone -b ${branch} ${url} ${workdir}/soledad
-export GIT_DIR=${workdir}/soledad/.git
-export GIT_WORK_TREE=${workdir}/soledad
-git remote add leapcode ${SOLEDAD_MAIN_REPO}
-git fetch leapcode
-git checkout -b debian/experimental leapcode/debian/experimental
-git merge --no-edit ${branch}
-(cd ${workdir}/soledad && debuild -uc -us)
-echo "Packages generated in ${workdir}"