| 1 | #!/bin/bash |
| 2 | |
| 3 | BASE_DIR="xburst" |
| 4 | |
| 5 | LOG="${BASE_DIR}/LOG" |
| 6 | |
| 7 | BUILD_LOG="${BASE_DIR}/BUILD_LOG" |
| 8 | |
| 9 | DATE=$(date "+%Y-%m-%d") |
| 10 | TIME=$(date "+%H-%M-%S") |
| 11 | DATE_TIME="${DATE}_${TIME}" |
| 12 | |
| 13 | FEEDS_CONF="data/qi_lb60/conf/feeds.conf" |
| 14 | test -f "feeds.conf" && FEEDS_CONF="feeds.conf" |
| 15 | |
| 16 | if [ "${0}" != "data/qi_lb60/scripts/build" ]; then |
| 17 | echo "Please call me that way: data/qi_lb60/scripts/build" |
| 18 | echo " - out of the main directory" |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | if [ ! -f ".config" ]; then |
| 23 | echo "OpenWrt didn't get configured yet." |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | if [ -f "config" ]; then |
| 28 | echo "file <config> exists." |
| 29 | echo "That means normally, a previous build failed" |
| 30 | echo "Please examine the situation" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | echo "This script will move previous builds to bak/!" |
| 35 | echo "This script will compile base on last commit" |
| 36 | echo " your modifications will backup by git stash" |
| 37 | echo " those modifications will apply again after compile" |
| 38 | echo "This script comes without any kind of warranty!" |
| 39 | echo " " |
| 40 | echo "Are you brave, dude? [NO/yes]" |
| 41 | |
| 42 | read brave |
| 43 | |
| 44 | echo " " |
| 45 | |
| 46 | if [ "${brave}" != "yes" ]; then |
| 47 | exit 1 |
| 48 | fi |
| 49 | |
| 50 | echo "cleaning up toolchain..." |
| 51 | mkdir bak 2>/dev/null |
| 52 | BAK="build_dir staging_dir tmp bin .config.old feeds xburst config" |
| 53 | for bak in $BAK; do |
| 54 | mv "${bak}" "bak/${bak}_${DATE_TIME}" 2> /dev/null && echo "backed up <${bak}>" |
| 55 | done |
| 56 | rm -rf package/feeds/* |
| 57 | |
| 58 | mv .config config |
| 59 | mkdir xburst |
| 60 | |
| 61 | echo "updating git repo..." |
| 62 | git stash |
| 63 | git pull > /dev/null |
| 64 | if [ "$?" != "0" ]; then |
| 65 | echo "ERROR: updating openwrt-xburst failed" |
| 66 | exit 1 |
| 67 | fi |
| 68 | |
| 69 | echo "updating feeds..." |
| 70 | scripts/feeds update -a > /dev/null 2>&1 |
| 71 | if [ "$?" != "0" ]; then |
| 72 | echo "ERROR: updating feeds failed" |
| 73 | exit 1 |
| 74 | fi |
| 75 | echo "installing feeds..." |
| 76 | scripts/feeds install -a > /dev/null 2>&1 |
| 77 | if [ "$?" != "0" ]; then |
| 78 | echo "ERROR: installing feeds failed" |
| 79 | exit 1 |
| 80 | fi |
| 81 | |
| 82 | echo "getting version numbers of used repositories..." |
| 83 | feeds="$(cat "${FEEDS_CONF}" | grep -v -E "^#")" |
| 84 | VERSIONS_FILE="xburst/VERSIONS" |
| 85 | echo "# base :: 'openwrt' [scm-protocol] [source] [branch] [revision]" > ${VERSIONS_FILE} |
| 86 | rev=$(git log | head -n 1 | cut -b8-) |
| 87 | branch=$(git branch | grep "*" | cut -b3-) |
| 88 | echo "openwrt git git://projects.qi-hardware.com/openwrt-xburst.git ${branch} ${rev}" >> ${VERSIONS_FILE} |
| 89 | echo "# feeds :: [feedname] [scm-protocol] [revision]" >> ${VERSIONS_FILE} |
| 90 | IFS=$'\n' |
| 91 | for feed in $feeds; do |
| 92 | IFS=' ' arr=(${feed:4}) |
| 93 | proto=${arr[0]} |
| 94 | dir=${arr[1]} |
| 95 | url=${arr[2]} |
| 96 | if [ "$proto" = "svn" ]; then |
| 97 | cd feeds/${arr[1]} && tmp=($(svn info | grep -E "^Revision")) && cd ../../ |
| 98 | rev=${tmp[1]} |
| 99 | fi |
| 100 | if [ "$proto" = "git" ]; then |
| 101 | cd feeds/${arr[1]} && tmp=($(git log | head -n 1)) && cd ../../ |
| 102 | rev=${tmp[1]} |
| 103 | fi |
| 104 | echo "${dir} ${proto} ${rev}" >> ${VERSIONS_FILE} |
| 105 | done |
| 106 | |
| 107 | mkdir -p files/etc |
| 108 | echo ${DATE} > files/etc/VERSION |
| 109 | |
| 110 | mv config .config |
| 111 | |
| 112 | yes "" | make oldconfig |
| 113 | |
| 114 | echo "starting compiling - this may take several hours..." |
| 115 | |
| 116 | time make V=99 > xburst/BUILD_LOG 2>&1 |
| 117 | |
| 118 | if [ "$?" != "0" ]; then |
| 119 | echo "ERROR: Build failed!" |
| 120 | echo "Please refer to the log file" |
| 121 | exit 1 |
| 122 | fi |
| 123 | |
| 124 | git stash pop |
| 125 | |
| 126 | cp .config xburst/config |
| 127 | cp bin/xburst/* xburst/ 2>/dev/null |
| 128 | mkdir xburst/files |
| 129 | cp -a files/* xburst/files/ |
| 130 | |
| 131 | echo "DONE :)" |
| 132 | |