-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathcreate_archive.sh
executable file
·72 lines (56 loc) · 2.32 KB
/
create_archive.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Temoa - Tools for Energy Model Optimization and Analysis
# linear optimization; least cost; dynamic system visualization
#
# Copyright (C) 2011-2014 Kevin Hunter, Joseph DeCarolis
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
#
# Developers of this script will check out a complete copy of the GNU Affero
# General Public License in the file COPYING.txt. Users uncompressing this from
# an archive may not have received this license file. If not, see
# <http://www.gnu.org/licenses/>.
# This script creates the 'temoa.py' zip archive/executable. I do not know if
# it is portable, but I know that it correctly creates the executable with the
# Ubuntu Linux distribution's version of Zip, Info-ZIP.
# To create the archive, execute with no arguments (in this directory), or
# with '--save'. The save argument merely saves the temporary zip file from
# which 'temoa.py' is created.
set -e
TMP_DIR=$(mktemp -d --suffix='.TemoaArchive')
cleanup() {
# Called unless --debug passed as first argument to script
\rm -rf "$TMP_DIR"
}
if [[ "$1" != "--debug" ]]; then
trap cleanup KILL TERM EXIT
fi
PKG_NAME=temoa.py
PKG_PATH=./temoa_model
CWD=$(pwd)
git diff --quiet || (echo "Uncommitted changes in branch. Exiting ..." && exit 1)
git diff --cached --quiet || (echo "Uncommitted changes in index. Exiting ..." && exit 1)
VERSION=$(git rev-parse HEAD)
TODAY="$(date -u +"%F")"
( cd "$PKG_PATH"
find . -name "*.py" -print0 | xargs -0 -I FILES cp FILES "$TMP_DIR"
)
( cd "$TMP_DIR"
find . -name "*.py" -print0 | xargs -0 \
sed -i "{
s|\\(TEMOA_GIT_VERSION \\+= \\)'HEAD'|\\1'$VERSION'|;
s|\\(TEMOA_RELEASE_DATE \\+= \\)'Today'|\\1'$TODAY'|;
}"
find . -name "*.py" -print0 | xargs -0 zip "$PKG_NAME".zip -q9@ --symlinks
echo "#!/usr/bin/env coopr_python" > "$PKG_NAME"
cat "$PKG_NAME".zip >> "$PKG_NAME"
chmod 755 "$PKG_NAME"
mv "$PKG_NAME" "$CWD"
)