summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/action.py30
-rw-r--r--tools/check.py91
-rw-r--r--tools/config.py5
-rw-r--r--tools/sync-conf.sh41
-rw-r--r--tools/sync-rpi-config.sh52
-rw-r--r--tools/sync-rpi.conf22
6 files changed, 93 insertions, 148 deletions
diff --git a/tools/action.py b/tools/action.py
deleted file mode 100644
index a2d0ba0..0000000
--- a/tools/action.py
+++ /dev/null
@@ -1,30 +0,0 @@
-# The basic workflow is like this:
-# git rsync
-# [remote git] <-> [local git] <-> [local storage]
-#
-# If action PULL is specified:
-# 1. git pull from remote repo
-# 2. rsync local repo to local storage
-#
-# If action PUSH is specified:
-# 1. rsync from local storage to local repo
-# 2. git push to remote repo
-
-# Pull config files from git repo
-
-import git
-
-def repo_pull():
- pass
-
-# Push config files to git repo
-def repo_push():
- pass
-
-# Pull config files from local storage to be pushed to repo
-def local_pull():
- pass
-
-# Push config pulled from repo to local storage
-def local_push():
- pass
diff --git a/tools/check.py b/tools/check.py
deleted file mode 100644
index efa2449..0000000
--- a/tools/check.py
+++ /dev/null
@@ -1,91 +0,0 @@
-import ConfigParser, os, getopt, sys, config
-
-ini = ConfigParser.ConfigParser()
-
-# Parse parameters
-def get_opts(argv):
- try:
- opts, args = getopt.getopt(argv,"ha:c:d:l",["conf=","action=","device=","list-devices"])
- except getopt.GetoptError:
- usage()
- sys.exit(2)
- for opt, arg in opts:
- if opt == '-h':
- return usage()
- sys.exit()
- elif opt in ("-l", "--list-devices"):
- print "You have configured these devices: " + list_devices()
- sys.exit()
- elif opt in ("-a", "--action"):
- config.action = arg
- elif opt in ("-c", "--conf"):
- config.configfile = arg
- elif opt in ("-d", "--device"):
- config.device = arg
-
-# Check parameters for errors
-def check_opts():
- get_opts(sys.argv[1:])
- if not config.action:
- print "Error: No action has been specified. Use -a."
- return usage()
- sys.exit(2)
- if not config.action == "pull" or config.action == "push":
- print "Error: Action \"" + config.action + "\" is invalid."
- return usage()
- sys.exit(2)
- if not config.device:
- print "Error: No device has been specified. Use -d."
- return usage()
- sys.exit(2)
- if config.device:
- load_config(config.configfile)
- if not ini.has_section(config.device):
- print "Error: Device \"" + config.device + "\" not configured. Add it to\"" + config.configfile + "."
- sys.exit(2)
-
-# Load provided config file or use default
-def load_config(configfile):
- if not configfile:
- config.configfile = "/etc/sync-rpi.conf"
- try:
- ini.read([config.configfile])
- except:
- sys.exit(2)
-
-# Check if configuration file is sane
-def check_config(configfile):
- get_opts(sys.argv[1:])
- load_config(config.configfile)
- error = 0
- #print config.configfile
- #print ini.items('config')
- #print ini.items('alcor-01')
- #print config.options_config
- #print config.options_device
- for option in config.options_config:
- if not ini.has_option('config', option):
- print "Error: Option \"" + option + "\" not set in [config]."
- error = 1
- for section in ini.sections():
- for option in config.options_device:
- if section != 'config' and not ini.has_option(section, option):
- print "Error: Option " + option + " not set in [" + section + "]."
- error = 1
-
- if error == 1:
- sys.exit(2)
-
-# List all devices defined in config.configfile
-def list_devices():
- load_config(config.configfile)
- return " ".join(ini.sections()[1:])
-
-# Prin usage
-def usage():
- print """Usage: sync-rpi-config -a ACTION -d DEVICE [ -c [FILE] ] [ -l ]
- Options
- -a, --action ACTION can be either pull or push. You are pushing config from you workstation to device or pulling it back.
- -d, --device DEVICE is set in configuration file. It is the machine you wish to push config to or pull from.
- -c, --conf Path to configuration file.
- -l, --list-devices List all devices defined in current configuration file."""
diff --git a/tools/config.py b/tools/config.py
deleted file mode 100644
index c8e6ec3..0000000
--- a/tools/config.py
+++ /dev/null
@@ -1,5 +0,0 @@
-configfile = ''
-device = ''
-action = ''
-options_config = [ 'repo', 'repo_path', 'rpi1', 'rpi2', 'rpi3', 'rpi1_path', 'rpi2_path', 'rpi3_path' ]
-options_device = [ 'type', ]
diff --git a/tools/sync-conf.sh b/tools/sync-conf.sh
new file mode 100644
index 0000000..561b993
--- /dev/null
+++ b/tools/sync-conf.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+dir="/var/tmp/portage/config/conf/$(hostname)"
+username="ctibor"
+root=/
+repo="ssh://git@git.brancik.cz/rpi-config.git"
+
+if [ $# != 1 ]; then
+ echo "Usage: sync-config <action>. Action can be either pull or push"
+ exit 1
+fi
+
+function check_repo {
+ if [ ! -d /var/tmp/portage/config/.git ]; then
+ echo "Cloning repository with config files."
+ mkdir -p /var/tmp/portage
+ chown ${username}:${username} /var/tmp/portage
+ /bin/su ${username} --command="/usr/bin/git clone --depth=1 ${repo} /var/tmp/portage/config"
+ fi
+}
+
+case $1 in
+ push)
+ check_repo
+ /bin/su ${username} --command="/usr/bin/git pull"
+ echo "Pushing config files to overlay folder ..."
+ /usr/bin/rsync -v --files-from /etc/portage/filelist_sync --recursive ${root} ${dir} --
+ cd ${dir}
+ /bin/su ${username} --command="/usr/bin/git add ."
+ /bin/su ${username} --command="/usr/bin/git commit -a -m \"Update portage config for mizar $(date +%Y%m%d-%H%M%S)\""
+ /bin/su ${username} --command="/usr/bin/git push";;
+ pull)
+ check_repo
+ cd ${dir}
+ /bin/su ${username} --command="/usr/bin/git pull"
+ echo "Pulling config files from overlay folder ..."
+ /usr/bin/rsync -v --files-from /etc/portage/filelist_sync --recursive ${dir} ${root} --;;
+ *)
+ echo "Usage: sync-config <action>. Action can be either pull or push"
+ exit 1
+esac
diff --git a/tools/sync-rpi-config.sh b/tools/sync-rpi-config.sh
new file mode 100644
index 0000000..f09b170
--- /dev/null
+++ b/tools/sync-rpi-config.sh
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+repo=/tmp/rpi-config
+device=${1}
+
+if [ ! -d /tmp/rpi-config/.git ]; then
+ cd /tmp
+ su ctibor --command "/usr/bin/git clone --depth 1 ssh://git@git.brancik.cz/rpi-config.git"
+ su ctibor --command "/usr/bin/git config --global user.name \"Ctibor Brančík\""
+ su ctibor --command "/usr/bin/git config --global user.email \"ctibor@brancik.cz\""
+fi
+
+if [ $# != 2 ]; then
+ echo "Usage sync-rpi-config <device> <action>. Action can be either push or pull."
+ exit 1;
+fi
+
+case $1 in
+ alcor-01|alcor-02|alcor-03)
+ root="/usr/armv6j-hardfloat-linux-gnueabi/";;
+ mizar)
+ root="/usr/armv7a-hardfloat-linux-gnueabi/";;
+ alioth)
+ root="/usr/aarch64-unknown-linux-gnu/";;
+ *)
+ echo "Usage sync-rpi-config <device> <action>."
+ exit 1;;
+esac
+
+case $2 in
+ push)
+ echo "Pushing config files to overlay folder ..."
+ /usr/bin/rsync -v --files-from ${root}/etc/portage/filelist_sync --recursive ${root} ${repo}/conf/${device} --
+ cd ${repo}
+ su ctibor --command "/usr/bin/git pull"
+ su ctibor --command "/usr/bin/git commit -a -m \"Update portage config for ${device} $(date +%Y%m%d-%H%M%S)\""
+ su ctibor --command "/usr/bin/git push";;
+ pull)
+ echo "Pulling config files from overlay folder ..."
+ cd ${repo}
+ su ctibor --command "/usr/bin/git pull"
+ /usr/bin/rsync -v --files-from ${root}/etc/portage/filelist_sync --recursive ${repo}/conf/${device} ${root} --;;
+ *)
+ echo "Usage sync-rpi-config <device> <action>."
+ exit 1;;
+esac
+
+function cleanup {
+ rm -r /tmp/rpi-config
+}
+
+trap cleanup EXIT;
diff --git a/tools/sync-rpi.conf b/tools/sync-rpi.conf
deleted file mode 100644
index b2ac111..0000000
--- a/tools/sync-rpi.conf
+++ /dev/null
@@ -1,22 +0,0 @@
-[config]
-## Define directories, where you store crosscompiled environment
-rpi1=true
-rpi2=true
-#rpi3=true
-rpi1_path=/usr/armv6j-hardlofat-linux-gnueabi
-rpi2_path=/usr/armv7a-hardfloat-linux-gnueabi
-#rpi3_path=/usr/aarch64-uknown-linux-gnu
-
-## Full URI to the git repository holding configuration files
-repo=ssh://git@git.brancik.cz/rpi-config.git
-
-## path to directory in repository where configuration files are stored
-repo_path=conf
-
-## Define values for devices
-## Name the section after the device
-[alcor-01]
-## Define the type of RPi being used
-type=rpi1
-[alcor-02]
-[mizar]