forked from hyphanet/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreenet-scripts-common
executable file
·106 lines (94 loc) · 3.15 KB
/
freenet-scripts-common
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#
# Contains shared utility functions.
#
# Path to configuration file.
configPath="$HOME/.freenetrc"
# Takes a build number as an argument
# Saves a comparsion between the localization of that build and the previous
# as "$oldBuild-$newBuild.diff.txt" in the release directory.
function compareL10n {
pushd "$fredDir"
newBuild="$1"
oldBuild=$((newBuild - 1))
echo Checking for English localization changes between $newBuild and $oldBuild
for build in "$oldBuild" "$newBuild"
do
git checkout $(printf 'build%05d' "$build") || exit 1003
cp "src/freenet/l10n/freenet.l10n.en.properties" "$build"
done
diffName="$oldBuild-$newBuild.diff.txt"
diff -u0 "$oldBuild" "$newBuild" > "$diffName"
less "$diffName"
cp "$diffName" "$releaseDir" || exit 1002
popd
}
# Sets $gitVersion, $buildNumber, and $commitID.
# All of these are set for the highest build number.
function getBuildInfo {
pushd "$fredDir" || exit
if [[ x"$1" == x"snapshot" || x"$1" == x"testing" ]]; then
versionMatcher='testing-build[-0-9]*-pre*';
else
versionMatcher='build[0-9]*';
fi
# Get highest build number, sorted numerically.
# Git tag includes only those tags starting with "build", and the awk
# substring excludes the first 5 characters, which are "build".
buildNumber=$(git tag -l "${versionMatcher}" | grep -o "[0-9]*" | sort --numeric-sort | tail -n1)
buildNumber=${buildNumber##0}
# Get tag with highest build number.
gitVersion=$(git tag -l "${versionMatcher}" | grep "[0-]*$buildNumber" | tail -n1)
getTagInfo $gitVersion
popd
}
# Sets $gitVersion, $buildNumber, and $commitID.
# All these are set for the tag given as an argument.
# This tag must be of the form "build<BUILDNUM>" where <BUILDNUM> is the build
# number, possibly with leading zeros.
function getTagInfo {
pushd "$fredDir" || exit
gitVersion=$1
# Strip away everything until the end of "build"
buildNumber=${gitVersion##*build}
# Strip possible leading zeros or minusses.
buildNumber=${buildNumber#[0-]}
# Resolve tag to commit hash.
commitID=$(git rev-parse $gitVersion^{})
popd
}
# Read configuration file if it exists.
function readConfig {
if [ -f "$configPath" ]; then
source "$configPath" || exit
else
echo Config file does not exist: "$configPath"
exit 1
fi
}
# Reads a case insensitive y/n response to the question given in the argument.
# Prints "Aborting." and exits if it is not y.
function require {
echo -n "$1 [y/N]"
read response
if [[ $(echo "$response" | tr '[:upper:]' '[:lower:]') != "y" ]]; then
echo "Aborting."
exit 1
fi
}
# Create a temporary directory, set it to $buildDir, and set a trap to remove it
# on exit.
function makeBuildDir {
buildDir="$(mktemp -d)" || exit 2
function rmTemp {
popd
echo "Removing temporary build directory."
rm -rf "$buildDir"
echo "Done."
}
trap rmTemp EXIT
}
function put() {
fcpput --persistence=forever --global --priority=1 --nowait -H "$fcpHost" -P "$fcpPort" -m "$2" "freenet:CHK@/$(basename "$1")" "$1"
}
readConfig