-
Notifications
You must be signed in to change notification settings - Fork 3
/
template.sh
executable file
·40 lines (31 loc) · 974 Bytes
/
template.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
#!/bin/bash
# Check if there is one argument that starts with a `v`. Read the file
# `snapcraft.tpl.yaml` and replace `<tag>` with the first argument. Also replace
# `<version>` with the argument without the leading `v`. Write the resulting
# file to `snap/snapcraft.yaml`.
set -e
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <tag>"
exit 1
fi
if [[ "$1" = "main" ]]; then
tag=$1
version=git-$(date +"%Y-%m-%dT%H:%M:%SZ")
echo "Version: $version"
echo "Tag: $tag"
mkdir -p snap
sed "s/source-tag: \"<tag>\"/source-branch: $tag/g; s/<version>/$version/g" snapcraft.tpl.yaml > snap/snapcraft.yaml
echo "Written snap/snapcraft.yaml"
exit 0
fi
if [[ ! "$1" =~ ^v ]]; then
echo "Argument must start with a 'v'"
exit 1
fi
tag=$1
version=${tag:1}
echo "Version: $version"
echo "Tag: $tag"
mkdir -p snap
sed "s/<tag>/$tag/g; s/<version>/$version/g" snapcraft.tpl.yaml > snap/snapcraft.yaml
echo "Written snap/snapcraft.yaml"