summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCtibor Brančík <ctibor@brancik.cz>2017-06-18 17:21:11 +0200
committerCtibor Brančík <ctibor@brancik.cz>2017-06-18 17:21:11 +0200
commitffb59a852274db5a9686671239ca0b51bd9f8796 (patch)
treeff54ac1739d8bba0202ec24c103d94a77b75d46d /tools
parent0996f26be8d1f23676804c14d6ce374432489e24 (diff)
downloadrpi-config-ffb59a852274db5a9686671239ca0b51bd9f8796.tar.gz
rpi-config-ffb59a852274db5a9686671239ca0b51bd9f8796.tar.bz2
Replace python scripts with simple bash solution
Diffstat (limited to 'tools')
-rw-r--r--tools/action.py30
-rw-r--r--tools/check.py91
-rw-r--r--tools/config.py5
-rw-r--r--tools/sync-conf.sh40
-rw-r--r--tools/sync-rpi.conf22
5 files changed, 40 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..6b1a934
--- /dev/null
+++ b/tools/sync-conf.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+dir="/var/tmp/portage/config/conf/$(hostname)"
+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 ctibor:ctibor /var/tmp/portage
+ /bin/su ctibor --command="/usr/bin/git clone --depth=1 ${repo} /var/tmp/portage/config"
+ fi
+}
+
+case $1 in
+ push)
+ check_repo
+ /bin/su ctibor --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 ctibor --command="/usr/bin/git add ."
+ /bin/su ctibor --command="/usr/bin/git commit -a -m \"Update portage config for mizar $(date +%Y%m%d-%H%M%S)\""
+ /bin/su ctibor --command="/usr/bin/git push";;
+ pull)
+ check_repo
+ cd ${dir}
+ /bin/su ctibor --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.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]