-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: librefactor: implement download functions
test version Signed-off-by: YuLong Yao <[email protected]> add Signed-off-by: YuLong Yao <[email protected]>
- Loading branch information
Showing
19 changed files
with
200 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tmp | ||
dest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
rm -rf tmp | ||
rm -rf dest |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME=gd32e10x | ||
VER=1.3.0 | ||
|
||
URL=https://gd32mcu.com/download/down/document_id/230/path_type/1 | ||
FILENAME=${NAME}.rar | ||
HASH=a395cdc5b4689259176e0bbbcd5350f10a026ceb | ||
|
||
function after_compress() { | ||
find $2/*/ -maxdepth 1 -exec mv {} $2 \; | ||
find $2/ -maxdepth 1 -name "*Firmware_Library*" -exec rm -rv {} \; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME=gd32f3x0 | ||
VER=2.2.1 | ||
|
||
URL=https://www.gd32mcu.com/download/down/document_id/143/path_type/1 | ||
FILENAME=${NAME}.rar | ||
HASH=9619dc83b0252926ab709f1a602d49e978f54fcd | ||
|
||
function after_compress() { | ||
find $2/*/ -maxdepth 1 -exec mv {} $2 \; | ||
find $2/ -maxdepth 1 -name "*Firmware_Library*" -exec rm -rv {} \; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME=gd32f403 | ||
VER=2.1.4 | ||
|
||
URL=https://www.gd32mcu.com/download/down/document_id/132/path_type/1 | ||
FILENAME=${NAME}.rar | ||
HASH=e1cc01fafc03afd47bd0f4f3a088cf53de414051 | ||
|
||
function after_compress() { | ||
find $2/*/ -maxdepth 1 -exec mv {} $2 \; | ||
find $2/ -maxdepth 1 -name "*Firmware_Library*" -exec rm -rv {} \; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
NAME=gd32f4xx | ||
VER=3.0.1 | ||
|
||
URL=https://www.gd32mcu.com/download/down/document_id/247/path_type/1 | ||
FILENAME=${NAME}.rar | ||
HASH=46e35c69ea2483b377af03d50da0ca6a4efaf69f | ||
|
||
function after_compress() { | ||
echo $1 $2 | ||
find $2/*/ -maxdepth 1 -exec mv {} $2 \; | ||
find $2/*/ -maxdepth 1 -exec mv {} $2 \; | ||
find $2/ -maxdepth 1 -name "*Firmware_Library*" -exec rm -rv {} \; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NAME=gd32vf103 | ||
VER=1.1.4 | ||
|
||
URL=https://www.gd32mcu.com/download/down/document_id/386/path_type/1 | ||
FILENAME=${NAME}.rar | ||
HASH=81a2e0fb119604e595066064d9ff423803933c00 | ||
|
||
function after_compress() { | ||
find $2/*/ -maxdepth 1 -exec mv {} $2 \; | ||
find $2/ -maxdepth 1 -name "*Firmware_Library*" -exec rm -rv {} \; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
find ./resources -name "*.conf" | xargs -n1 ./utils/build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
find ./resources -name "*.conf" | xargs -n1 ./utils/gen_hash.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
# prepare env var | ||
source utils/utils.sh | ||
source $1 | ||
|
||
TMPDIR=tmp | ||
DESTDIR=dest/${NAME} | ||
|
||
echo Processing ${NAME} | ||
|
||
# make workspace folder | ||
mkdir -p ${TMPDIR} | ||
mkdir -p ${DESTDIR} | ||
|
||
# download files | ||
getfile ${TMPDIR}/${FILENAME} ${URL} ${HASH} | ||
checkfilehash ${HASH} ${TMPDIR}/${FILENAME} | ||
if [ $? -ne 0 ]; then | ||
# abort if hash not match | ||
echo "file ${NAME}:${FILENAME} download failed!" | ||
exit 1 | ||
fi | ||
|
||
uncompress ${TMPDIR}/${FILENAME} ${DESTDIR} | ||
|
||
drop_unnessary_files ${DESTDIR} | ||
change_file_format ${DESTDIR} | ||
patch_cocci ${DESTDIR} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
source utils/utils.sh | ||
source $1 | ||
|
||
TMPDIR=tmp | ||
|
||
# make workspace folder | ||
mkdir -p ${TMPDIR} | ||
|
||
# force re-download | ||
download ${TMPDIR}/${FILENAME} ${URL} | ||
if [ $? -ne 0 ]; then | ||
# abort if hash not match | ||
echo "file ${NAME}:${FILENAME} hash update failed!" | ||
exit 1 | ||
fi | ||
|
||
HASH=$(sha1sum ${TMPDIR}/${FILENAME} | cut -d ' ' -f 1) | ||
echo "file ${NAME}:${FILENAME} hash update to ${HASH}" | ||
sed -i -r "s/^HASH=.*$/HASH=${HASH}/" $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env bash | ||
|
||
function after_compress() { | ||
echo "no actions in after_compress hook" | ||
} | ||
|
||
function download() { | ||
wget -O $1 $2 | ||
return $? | ||
} | ||
|
||
function checkfilehash() { | ||
echo "$1 $2" | ||
echo "$1 $2" | sha1sum -c - | ||
return $? | ||
} | ||
|
||
function getfile() { | ||
checkfilehash $3 $1 | ||
if [ $? -ne 0 ]; then | ||
# download if not exist or hash not match | ||
download $1 $2 | ||
fi | ||
} | ||
|
||
function uncompress_rar() { | ||
unrar x $1 $2 | ||
} | ||
|
||
function uncompress() { | ||
rm -rvf $2 | ||
mkdir -p $2 | ||
|
||
ftpye=$(file "$1") | ||
case "$ftpye" in | ||
"$1: RAR archive"*) | ||
uncompress_rar $1 $2 | ||
;; | ||
*) | ||
echo unsupport file format: $ftpye | ||
;; | ||
esac | ||
|
||
after_compress $1 $2 # call hook | ||
} | ||
|
||
function rename_to_lower() { | ||
mv -v $(dirname $1 | tr '[:upper:]' '[:lower:]')/$(basename $1) $(echo $1 | tr '[:upper:]' '[:lower:]') | ||
} | ||
export -f rename_to_lower | ||
|
||
function drop_unnessary_files() { | ||
libbak=$1.bak | ||
rm -rf $libbak | ||
mv $1 $libbak | ||
mkdir -p $1 | ||
|
||
cp -rv $libbak/Firmware/CMSIS $1/cmsis | ||
find $1/cmsis/GD/ -maxdepth 2 -type d | xargs -I {} bash -c 'rename_to_lower "{}"' \; | ||
rm $1/cmsis/*.h | ||
rm -r $1/cmsis/gd/*/source/ARM | ||
rm -r $1/cmsis/gd/*/source/IAR | ||
|
||
cp -rv $libbak/Firmware/*_standard_peripheral $1/standard_peripheral | ||
find $1/standard_peripheral -maxdepth 1 -type d | xargs -I {} bash -c 'rename_to_lower "{}"' \; | ||
cp -v $libbak/Template/*_libopt.h $1/standard_peripheral/include/ | ||
rm -rv $libbak | ||
} | ||
|
||
function change_file_format() { | ||
find $1 type f -print0 | xargs -0 dos2unix -k | ||
} | ||
|
||
function patch_cocci() { | ||
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | ||
# pushd $script_dir | ||
for cocci in $script_dir/patches/*.cocci; do | ||
find $1 -name "*.h" -or -name "*.c" | xargs -P0 -n1 echo $script_dir/eval_patch.sh $cocci | ||
done | ||
# popd | ||
} |