-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathupdate-version.sh
executable file
·134 lines (103 loc) · 4.41 KB
/
update-version.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
# Copyright (C) 2006-2022 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
# wolfSSL is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# wolfSSL 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
get_current() {
CURRENT=`find recipes-wolfssl/$1/*.bb | grep -Eo '[0-9]+.[0-9]+.[0-9]+'`
}
get_new() {
NEW=$(curl -s "https://api.github.com/repos/wolfssl/$1/releases/latest" | jq -r '.tag_name' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
}
update() {
if [ -z "$CURRENT" ] || [ -z "$NEW" ]; then
printf "Error: Current or new version is empty for %s. Skipping update.\n" "$1"
return
fi
if [ "$CURRENT" != "$NEW" ]; then
printf "Updating from %s to %s for %s...\n" "$CURRENT" "$NEW" "$1"
TAG="v$NEW-stable"
if [ "$1" = "wolfmqtt" ] || [ "$1" == "wolftpm" ] || [ "$1" == "wolfprovider" ]; then
TAG="v$NEW"
fi
# Clone the new version repository
if ! git clone --depth 1 -b "$TAG" "[email protected]:wolfssl/$1" &> /dev/null; then
printf "Error cloning %s. Skipping.\n" "$1"
return
fi
# Get the new revision
cd "$1" &> /dev/null
REV=$(git rev-list -n 1 "$TAG")
cd .. && rm -rf "$1"
# Check if the old .bb file exists before attempting to move
if [ ! -f "./recipes-wolfssl/$1/$1_$CURRENT.bb" ]; then
printf "Error: .bb file for %s with version %s not found. Skipping.\n" "$1" "$CURRENT"
return
fi
# Check if the new .bb file already exists
if [ -f "./recipes-wolfssl/$1/$1_$NEW.bb" ]; then
echo "New .bb file for version $NEW already exists. Deleting it to proceed with update."
# Delete the existing new .bb file
rm -f "./recipes-wolfssl/$1/$1_$NEW.bb"
fi
# Move the .bb file to the new version
git mv "./recipes-wolfssl/$1/$1_$CURRENT.bb" "./recipes-wolfssl/$1/$1_$NEW.bb" &> /dev/null
# Update the revision in the new .bb file
if [ -f "./recipes-wolfssl/$1/$1_$NEW.bb" ]; then
sed -i "s/rev=.*/rev=$REV\"/" "./recipes-wolfssl/$1/$1_$NEW.bb"
git add "./recipes-wolfssl/$1/$1_$NEW.bb" &> /dev/null
else
printf "Error updating .bb file for %s to version %s. File not found after move.\n" "$1" "$NEW"
return
fi
# Additional steps for wolfSSL
if [ "$1" = "wolfssl" ]; then
printf "\tUpdating wolfcrypt test and benchmark...\n"
# Update wolfcrypt test
if [ -f "./recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb" ]; then
sed -i "s/rev=.*/rev=$REV\"/" "./recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb"
git add "./recipes-examples/wolfcrypt/wolfcrypttest/wolfcrypttest.bb" &> /dev/null
else
printf "Error: wolfcrypttest.bb file not found.\n"
fi
# Update wolfcrypt benchmark
if [ -f "./recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb" ]; then
sed -i "s/rev=.*/rev=$REV\"/" "./recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb"
git add "./recipes-examples/wolfcrypt/wolfcryptbenchmark/wolfcryptbenchmark.bb" &> /dev/null
else
printf "Error: wolfcryptbenchmark.bb file not found.\n"
fi
fi
else
printf "Version %s is the latest for %s. No update needed.\n" "$CURRENT" "$1"
fi
}
check_and_update() {
printf "Checking version of ${1} to use..."
get_current "${1}"
get_new "${1}"
update "${1}"
}
check_and_update "wolfssl"
check_and_update "wolfmqtt"
check_and_update "wolfssh"
check_and_update "wolftpm"
check_and_update "wolfclu"
check_and_update "wolfssl-py"
check_and_update "wolfcrypt-py"
check_and_update "wolfengine"
check_and_update "wolfprovider"
exit 0