Skip to content

Commit

Permalink
Merge pull request #67 from aparcar/snapshots
Browse files Browse the repository at this point in the history
when using snapshots check if outdated
  • Loading branch information
Paul Spooren authored May 30, 2018
2 parents 17d2421 + dd2889c commit b7438ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
43 changes: 39 additions & 4 deletions cooker
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ cook() {
download_ib $target
}

[ "$snapshots" -eq 1 ] && check_outdated "$target" "imagebuilder"

[ -n "$use_remote_pkgs" ] && {
local arch=`get_arch_from_ib $target`
echo "-> Using remote repository for ImageBuilder, architecture: $arch"
Expand Down Expand Up @@ -188,9 +190,11 @@ build_sdk() {

[ ! -d "$sdk" ] && {
echo "-> SDK for target $target not found"
download_sdk $target
download_sdk "$target"
}


[ "$snapshots" -eq 1 ] && check_outdated "$target" "sdk"

echo "-> Building $sdk"

[ -f "$feeds_file" ] || {
Expand Down Expand Up @@ -335,6 +339,30 @@ download_all() {
cat $targets_list | while read t; do download_sdk $t; download_ib $t; done
}

check_outdated() {
echo "-> Check if snapshot is outdated"
local target="$1"
local type="$2"
local url="$base_url/$target"
local output="$release/$target"
local file_hash="$(get_hash_filename $url $type)"
local file="$(echo $file_hash | cut -d'*' -f 2)"

[ "$file_hash" != "$(cat $tmp_dir/${file}_checksum)" ] && {
echo "-> Snapshot $type is outdated"
echo "--> Removing and downloading again"
rm "$tmp_dir/$file"*
[ "$type" == "sdk" ] && download_sdk "$target"
[ "$type" == "imagebuilder" ] && download_ib "$target"
}
}

get_hash_filename() {
local url="$1"
local type="$2"
echo "$(wget -q -O- $url/sha256sums | grep ${brand_name}-$type)"
}

download_sdk() {
local target="$1"
[ -z "$target" ] && {
Expand All @@ -346,12 +374,17 @@ download_sdk() {
local output="$release/$target"
[ ! -d "$output" ] && mkdir -p "$output"

local sdk_file="$(wget -q -O- $url | grep ${brand_name}-sdk | grep href | awk -F\> '{print $4}' | awk -F\< '{print $1}')"
local sdk_file_hash="$(get_hash_filename $url sdk)"
local sdk_file="$(echo $sdk_file_hash | cut -d'*' -f 2)"

echo "-> Downloading $url/$sdk_file"
wget -c "$url/$sdk_file" -O "$tmp_dir/$sdk_file" || {
echo "-> Error, cannot download SDK $url/$sdk_file"
exit 1
}

echo "$sdk_file_hash" > "$tmp_dir/${sdk_file}_checksum"

unpack_sdk $tmp_dir/$sdk_file $output
}

Expand Down Expand Up @@ -386,7 +419,9 @@ download_ib() {
local url="$base_url/$target"
local output="$release/$target"
[ ! -d "$output" ] && mkdir -p "$output"
local ib_file="$(wget -q -O- $url | grep ${brand_name}-imagebuilder | grep href | awk -F\> '{print $4}' | awk -F\< '{print $1}')"

local ib_file_hash="$(get_hash_filename $url imagebuilder)"
local ib_file="$(echo $ib_file_hash | cut -d'*' -f 2)"
echo "-> Downloading $url/$ib_file"
wget -c "$url/$ib_file" -O "$tmp_dir/$ib_file" || {
echo "-> Error, cannot download ImageBuilder $url/$ib_file"
Expand Down
1 change: 1 addition & 0 deletions options.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
snapshots=1
release=openwrt
base_url=https://downloads.openwrt.org/snapshots/targets/
communities_git=https://github.com/libremesh/network-profiles.git
Expand Down

0 comments on commit b7438ee

Please sign in to comment.