-
Notifications
You must be signed in to change notification settings - Fork 62
/
build_and_install.sh
executable file
·81 lines (66 loc) · 1.77 KB
/
build_and_install.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
#!/bin/bash
#
# Builds packages and installs it on a target platform
#
# Usage:
#
# ./build_and_install package target [model]
#
# with
# package: a wdpk e.g. entware
# target: the ssh host to install it on (defined in .ssh/config)
#
# It's recommended to setup entware + ssh keys first
# ssh-copy-id root@host
#
# Author: TFL
PACKAGE=$1
usage () {
echo "Usage: $0 package <target> [model]"
}
if [ -z "$1" ]; then
usage
exit 1
fi
if [ "$1" = "-h" ]; then
usage
exit 0
fi
# TODO: add docstring / help
# TODO: check if this docker image exists
# create packages
docker run -it -v $(pwd):/wdpksrc wdpk/wdpk /bin/bash -c "cd wdpk/$PACKAGE; ./build.sh; chown -R 1000:1000 ../../packages/$PACKAGE"
# find latest package
MODEL="$3"
if [ -z "$MODEL" ]; then
MODEL="PR4100"
fi
echo "Select model $MODEL"
BINARY=$(find packages/$PACKAGE -name "*${PACKAGE}_*_${MODEL}.bin" | sort | tail -n1)
echo "Created $BINARY"
TARGET="$2"
[[ -z $TARGET ]] && exit 0
echo
echo "Upload the app $BINARY"
scp $BINARY $TARGET:/shares/Volume_1/.systemfile/upload/app.bin
#cssh='ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
cssh=ssh
echo
echo "Install the app"
ALREADY_INSTALLED=$($cssh $TARGET "del_apkg whatever | grep ${PACKAGE}")
if [ -n "${ALREADY_INSTALLED}" ]; then
$cssh $TARGET "PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/sbin/upload_apkg -rapp.bin -d -f1 -g1 && echo 'SUCCESS!'"
else
echo "Warning: this usually doesn't work!"
$cssh $TARGET "PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin /usr/sbin/upload_apkg -m -papp.bin -t2 && echo 'SUCCESS!'"
fi
TEST=tests/$PACKAGE/test.sh
if [ -e $TEST ]; then
echo
echo "Run test hooks"
export PACKAGE=$PACKAGE
export TARGET=$TARGET
$TEST
else
echo "No test found for $PACKAGE"
fi