summaryrefslogtreecommitdiff
path: root/templates/turris.run
blob: 0e98531877f86e81f1136ea5fe357fa73cf90b65 (plain)
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
#!/bin/sh
# vim: ft=sh
. "$(dirname "$(readlink -f "$0")")/../job.common"
###################################################
num_load="$(nproc)"
num_jobs="$((num_load * 2))"
compile_params="-j$num_jobs -a -l$num_load -f"
make="force-make -j$num_jobs -d$num_jobs -f V=99 -- -l$num_load BUILD_LOG=1"
###################################################
export IS_TTY=1

# Lock for execution
if [ "$1" != "--locked" ]; then
	exec flock --exclusive "$WORKSPACE/execution.lock" "$0" --locked "$@"
fi
shift # Shift --locked

curl "https://repo.turris.cz/$ANIMAL/$BOARD/packages/git-hash" > git-hash
cat git-hash

new_upstream="n"
cmp -s git-hash "$WORKSPACE/openwrt-git-hash" || new_upstream="y"

latest_master="$(echo list \
	| git remote-https https://git.cynerd.cz/openwrt-personal-pkgs \
	| awk '$2 == "refs/heads/master" { print $1 }')"
if [ "$new_upstream" = "n" ] && [ "$latest_master" = "$(cat "$WORKSPACE/personal-git-hash")" ]; then
	echo_info "Latest version of personal packages is already build."
	exit 0
fi

if [ -z "$CLEAN" ] && [ -f "$WORKSPACE/openwrt-git-hash" ] && [ "$new_upstream" = "n" ]; then
	echo_info "Using previous version of SDK"
	tar -xzf "$WORKSPACE/openwrt.tar.gz"
else
	echo_info "Building new version of SDK"
	echo_stage "Get turris-build"
	# TODO once TOS 5.2.0 lands in HBT we can just use HEAD
	git_fetch_t "https://gitlab.labs.nic.cz/turris/turris-build.git" turris-build hbl
	(
		cd turris-build
		./helpers/checkout_repo_branch.sh "$ANIMAL" "$BOARD"
		cat feeds.conf
		patch -Np1 -r - < "$FILES/git-fetch-lock.patch" || true # just ignore if it fails
	)

	echo_stage "Prepare SDK"
	mkdir openwrt
	(
		cd openwrt
		cat > .turris-build.conf <<-EOF
			GIT_MIRROR="$TWORKSPACE/openwrt-git-mirror"
			DL_MIRROR="$TWORKSPACE/openwrt-dl-mirror"
			CCACHE_HOST_DIR="$TWORKSPACE/ccache-host"
			CCACHE_TARGET_DIR="$WORKSPACE/ccache-target"
		EOF
		../turris-build/compile_pkgs -t "$BOARD" -p "$ANIMAL" $compile_params \
			prepare_tools autopkg
		$make package/usign/host/compile
	)
	tar -czf openwrt.tar.gz openwrt
	mv openwrt.tar.gz "$WORKSPACE/openwrt.tar.gz"
	mv git-hash "$WORKSPACE/openwrt-git-hash"
fi
cd openwrt

echo_stage "Get personal repository feed"
echo "src-git personal git@cynerd.cz:openwrt-personal-pkgs" >> feeds.conf
./scripts/feeds update personal
find feeds/personal -type d -exec test -f '{}/Makefile' \; -prune -printf "%P\0" | \
	xargs -0 ./scripts/feeds uninstall # Remove any package provided by personal feed
./scripts/feeds install -p personal -d y -f -a
echo_stage "Compile packages from personal feed"
find package/feeds/personal -mindepth 1 -maxdepth 1 -printf '%P\n' | \
	while read -r package; do
		$make "package/$package/compile" || \
			echo_error "Package build failed: $package"
	done

echo_stage "Generate index and sign"
$make package/index BUILD_KEY=~/keys/openwrt-repo.sec

echo_stage "Deploy"
ssh upload rm -rf "deploy-turris-$ANIMAL-$BOARD"
sftp -b - upload <<EOF
	put -R "./bin/packages/$ARCH/personal" "deploy-turris-$ANIMAL-$BOARD"
EOF
ssh upload /bin/sh -se "$ANIMAL" "$BOARD" <<"EOF"
	mkdir -p "/var/www/repo/turris/$1"
	rm -rf "/var/www/repo/turris/$1/$2"
	mv "deploy-turris-$1-$2" "/var/www/repo/turris/$1/$2"
EOF
echo "$latest_master" > "$WORKSPACE/personal-git-hash"