diff options
Diffstat (limited to 'bitbake/bin/toaster')
| -rwxr-xr-x | bitbake/bin/toaster | 332 |
1 files changed, 0 insertions, 332 deletions
diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster deleted file mode 100755 index f002c8c159..0000000000 --- a/bitbake/bin/toaster +++ /dev/null | |||
| @@ -1,332 +0,0 @@ | |||
| 1 | #!/bin/echo ERROR: This script needs to be sourced. Please run as . | ||
| 2 | |||
| 3 | # toaster - shell script to start Toaster | ||
| 4 | |||
| 5 | # Copyright (C) 2013-2015 Intel Corp. | ||
| 6 | # | ||
| 7 | # SPDX-License-Identifier: GPL-2.0-or-later | ||
| 8 | # | ||
| 9 | |||
| 10 | HELP=" | ||
| 11 | Usage 1: source toaster start|stop [webport=<address:port>] [noweb] [nobuild] [toasterdir] | ||
| 12 | Optional arguments: | ||
| 13 | [nobuild] Setup the environment for capturing builds with toaster but disable managed builds | ||
| 14 | [noweb] Setup the environment for capturing builds with toaster but don't start the web server | ||
| 15 | [webport] Set the development server (default: localhost:8000) | ||
| 16 | [toasterdir] Set absolute path to be used as TOASTER_DIR (default: BUILDDIR/../) | ||
| 17 | Usage 2: source toaster manage [createsuperuser|lsupdates|migrate|makemigrations|checksettings|collectstatic|...] | ||
| 18 | " | ||
| 19 | |||
| 20 | custom_extention() | ||
| 21 | { | ||
| 22 | custom_extension=$BBBASEDIR/lib/toaster/orm/fixtures/custom_toaster_append.sh | ||
| 23 | if [ -f $custom_extension ] ; then | ||
| 24 | $custom_extension $* | ||
| 25 | fi | ||
| 26 | } | ||
| 27 | |||
| 28 | databaseCheck() | ||
| 29 | { | ||
| 30 | retval=0 | ||
| 31 | # you can always add a superuser later via | ||
| 32 | # ../bitbake/lib/toaster/manage.py createsuperuser --username=<ME> | ||
| 33 | $MANAGE migrate --noinput || retval=1 | ||
| 34 | |||
| 35 | if [ $retval -eq 1 ]; then | ||
| 36 | echo "Failed migrations, halting system start" 1>&2 | ||
| 37 | return $retval | ||
| 38 | fi | ||
| 39 | # Make sure that checksettings can pick up any value for TEMPLATECONF | ||
| 40 | export TEMPLATECONF | ||
| 41 | $MANAGE checksettings --traceback || retval=1 | ||
| 42 | |||
| 43 | if [ $retval -eq 1 ]; then | ||
| 44 | printf "\nError while checking settings; exiting\n" | ||
| 45 | return $retval | ||
| 46 | fi | ||
| 47 | |||
| 48 | return $retval | ||
| 49 | } | ||
| 50 | |||
| 51 | webserverKillAll() | ||
| 52 | { | ||
| 53 | local pidfile | ||
| 54 | if [ -f ${BUILDDIR}/.toastermain.pid ] ; then | ||
| 55 | custom_extention web_stop_postpend | ||
| 56 | else | ||
| 57 | custom_extention noweb_stop_postpend | ||
| 58 | fi | ||
| 59 | for pidfile in ${BUILDDIR}/.toastermain.pid ${BUILDDIR}/.runbuilds.pid; do | ||
| 60 | if [ -f ${pidfile} ]; then | ||
| 61 | pid=`cat ${pidfile}` | ||
| 62 | while kill -0 $pid 2>/dev/null; do | ||
| 63 | kill -SIGTERM $pid 2>/dev/null | ||
| 64 | sleep 1 | ||
| 65 | done | ||
| 66 | rm ${pidfile} | ||
| 67 | fi | ||
| 68 | done | ||
| 69 | } | ||
| 70 | |||
| 71 | webserverStartAll() | ||
| 72 | { | ||
| 73 | # do not start if toastermain points to a valid process | ||
| 74 | if ! cat "${BUILDDIR}/.toastermain.pid" 2>/dev/null | xargs -I{} kill -0 {} ; then | ||
| 75 | retval=1 | ||
| 76 | rm "${BUILDDIR}/.toastermain.pid" | ||
| 77 | fi | ||
| 78 | |||
| 79 | retval=0 | ||
| 80 | |||
| 81 | # check the database | ||
| 82 | databaseCheck || return 1 | ||
| 83 | |||
| 84 | echo "Starting webserver..." | ||
| 85 | |||
| 86 | $MANAGE runserver --noreload "$ADDR_PORT" \ | ||
| 87 | </dev/null >>${TOASTER_LOGS_DIR}/web.log 2>&1 \ | ||
| 88 | & echo $! >${BUILDDIR}/.toastermain.pid | ||
| 89 | |||
| 90 | sleep 1 | ||
| 91 | |||
| 92 | if ! cat "${BUILDDIR}/.toastermain.pid" | xargs -I{} kill -0 {} ; then | ||
| 93 | retval=1 | ||
| 94 | rm "${BUILDDIR}/.toastermain.pid" | ||
| 95 | else | ||
| 96 | echo "Toaster development webserver started at http://$ADDR_PORT" | ||
| 97 | echo -e "\nYou can now run 'bitbake <target>' on the command line and monitor your build in Toaster.\nYou can also use a Toaster project to configure and run a build.\n" | ||
| 98 | custom_extention web_start_postpend $ADDR_PORT | ||
| 99 | fi | ||
| 100 | |||
| 101 | return $retval | ||
| 102 | } | ||
| 103 | |||
| 104 | INSTOPSYSTEM=0 | ||
| 105 | |||
| 106 | # define the stop command | ||
| 107 | stop_system() | ||
| 108 | { | ||
| 109 | # prevent reentry | ||
| 110 | if [ $INSTOPSYSTEM -eq 1 ]; then return; fi | ||
| 111 | INSTOPSYSTEM=1 | ||
| 112 | webserverKillAll | ||
| 113 | # unset exported variables | ||
| 114 | unset TOASTER_DIR | ||
| 115 | unset BITBAKE_UI | ||
| 116 | unset BBBASEDIR | ||
| 117 | trap - SIGHUP | ||
| 118 | #trap - SIGCHLD | ||
| 119 | INSTOPSYSTEM=0 | ||
| 120 | } | ||
| 121 | |||
| 122 | verify_prereq() { | ||
| 123 | # Verify Django version | ||
| 124 | reqfile=$(python3 -c "import os; print(os.path.realpath('$BBBASEDIR/toaster-requirements.txt'))") | ||
| 125 | exp='s/Django\([><=]\+\)\([^,]\+\),\([><=]\+\)\(.\+\)/' | ||
| 126 | # expand version parts to 2 digits to support 1.10.x > 1.8 | ||
| 127 | # (note:helper functions hard to insert in-line) | ||
| 128 | exp=$exp'import sys,django;' | ||
| 129 | exp=$exp'version=["%02d" % int(n) for n in django.get_version().split(".")];' | ||
| 130 | exp=$exp'vmin=["%02d" % int(n) for n in "\2".split(".")];' | ||
| 131 | exp=$exp'vmax=["%02d" % int(n) for n in "\4".split(".")];' | ||
| 132 | exp=$exp'sys.exit(not (version \1 vmin and version \3 vmax))' | ||
| 133 | exp=$exp'/p' | ||
| 134 | if ! sed -n "$exp" $reqfile | python3 - ; then | ||
| 135 | req=`grep ^Django $reqfile` | ||
| 136 | echo "This program needs $req" | ||
| 137 | echo "Please install with pip3 install -r $reqfile" | ||
| 138 | return 2 | ||
| 139 | fi | ||
| 140 | |||
| 141 | return 0 | ||
| 142 | } | ||
| 143 | |||
| 144 | # read command line parameters | ||
| 145 | if [ -n "$BASH_SOURCE" ] ; then | ||
| 146 | TOASTER=${BASH_SOURCE} | ||
| 147 | elif [ -n "$ZSH_NAME" ] ; then | ||
| 148 | TOASTER=${(%):-%x} | ||
| 149 | else | ||
| 150 | TOASTER=$0 | ||
| 151 | fi | ||
| 152 | |||
| 153 | export BBBASEDIR=`dirname $TOASTER`/.. | ||
| 154 | MANAGE="python3 $BBBASEDIR/lib/toaster/manage.py" | ||
| 155 | if [ -z "$OE_ROOT" ]; then | ||
| 156 | OE_ROOT=`dirname $TOASTER`/../.. | ||
| 157 | fi | ||
| 158 | |||
| 159 | # this is the configuraton file we are using for toaster | ||
| 160 | # we are using the same logic that oe-setup-builddir uses | ||
| 161 | # (based on TEMPLATECONF and .templateconf) to determine | ||
| 162 | # which toasterconf.json to use. | ||
| 163 | # note: There are a number of relative path assumptions | ||
| 164 | # in the local layers that currently make using an arbitrary | ||
| 165 | # toasterconf.json difficult. | ||
| 166 | |||
| 167 | . $OE_ROOT/.templateconf | ||
| 168 | if [ -n "$TEMPLATECONF" ]; then | ||
| 169 | if [ ! -d "$TEMPLATECONF" ]; then | ||
| 170 | # Allow TEMPLATECONF=meta-xyz/conf as a shortcut | ||
| 171 | if [ -d "$OE_ROOT/$TEMPLATECONF" ]; then | ||
| 172 | TEMPLATECONF="$OE_ROOT/$TEMPLATECONF" | ||
| 173 | fi | ||
| 174 | fi | ||
| 175 | fi | ||
| 176 | |||
| 177 | unset OE_ROOT | ||
| 178 | |||
| 179 | |||
| 180 | WEBSERVER=1 | ||
| 181 | export TOASTER_BUILDSERVER=1 | ||
| 182 | ADDR_PORT="localhost:8000" | ||
| 183 | TOASTERDIR=`dirname $BUILDDIR` | ||
| 184 | # ${BUILDDIR}/toaster_logs/ became the default location for toaster logs | ||
| 185 | # This is needed for implemented django-log-viewer: https://pypi.org/project/django-log-viewer/ | ||
| 186 | # If the directory does not exist, create it. | ||
| 187 | TOASTER_LOGS_DIR="${BUILDDIR}/toaster_logs/" | ||
| 188 | if [ ! -d $TOASTER_LOGS_DIR ] | ||
| 189 | then | ||
| 190 | mkdir $TOASTER_LOGS_DIR | ||
| 191 | fi | ||
| 192 | unset CMD | ||
| 193 | for param in $*; do | ||
| 194 | case $param in | ||
| 195 | noweb ) | ||
| 196 | WEBSERVER=0 | ||
| 197 | ;; | ||
| 198 | nobuild ) | ||
| 199 | TOASTER_BUILDSERVER=0 | ||
| 200 | ;; | ||
| 201 | start ) | ||
| 202 | CMD=$param | ||
| 203 | ;; | ||
| 204 | stop ) | ||
| 205 | CMD=$param | ||
| 206 | ;; | ||
| 207 | webport=*) | ||
| 208 | ADDR_PORT="${param#*=}" | ||
| 209 | # Split the addr:port string | ||
| 210 | ADDR=`echo $ADDR_PORT | cut -f 1 -d ':'` | ||
| 211 | PORT=`echo $ADDR_PORT | cut -f 2 -d ':'` | ||
| 212 | # If only a port has been speified then set address to localhost. | ||
| 213 | if [ $ADDR = $PORT ] ; then | ||
| 214 | ADDR_PORT="localhost:$PORT" | ||
| 215 | fi | ||
| 216 | ;; | ||
| 217 | toasterdir=*) | ||
| 218 | TOASTERDIR="${param#*=}" | ||
| 219 | ;; | ||
| 220 | manage ) | ||
| 221 | CMD=$param | ||
| 222 | manage_cmd="" | ||
| 223 | ;; | ||
| 224 | --help) | ||
| 225 | echo "$HELP" | ||
| 226 | return 0 | ||
| 227 | ;; | ||
| 228 | *) | ||
| 229 | if [ "manage" == "$CMD" ] ; then | ||
| 230 | manage_cmd="$manage_cmd $param" | ||
| 231 | else | ||
| 232 | echo "$HELP" | ||
| 233 | exit 1 | ||
| 234 | fi | ||
| 235 | ;; | ||
| 236 | |||
| 237 | esac | ||
| 238 | done | ||
| 239 | |||
| 240 | if [ `basename \"$0\"` = `basename \"${TOASTER}\"` ]; then | ||
| 241 | echo "Error: This script needs to be sourced. Please run as . $TOASTER" | ||
| 242 | return 1 | ||
| 243 | fi | ||
| 244 | |||
| 245 | verify_prereq || return 1 | ||
| 246 | |||
| 247 | # We make sure we're running in the current shell and in a good environment | ||
| 248 | if [ -z "$BUILDDIR" ] || ! which bitbake >/dev/null 2>&1 ; then | ||
| 249 | echo "Error: Build environment is not setup or bitbake is not in path." 1>&2 | ||
| 250 | return 2 | ||
| 251 | fi | ||
| 252 | |||
| 253 | # this defines the dir toaster will use for | ||
| 254 | # 1) clones of layers (in _toaster_clones ) | ||
| 255 | # 2) the build dir (in build) | ||
| 256 | # 3) the sqlite db if that is being used. | ||
| 257 | # 4) pid's we need to clean up on exit/shutdown | ||
| 258 | export TOASTER_DIR=$TOASTERDIR | ||
| 259 | export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS TOASTER_DIR" | ||
| 260 | |||
| 261 | # Determine the action. If specified by arguments, fine, if not, toggle it | ||
| 262 | if [ "$CMD" = "start" ] ; then | ||
| 263 | if [ -n "$BBSERVER" ]; then | ||
| 264 | echo " Toaster is already running. Exiting..." | ||
| 265 | return 1 | ||
| 266 | fi | ||
| 267 | elif [ "$CMD" = "" ]; then | ||
| 268 | echo "No command specified" | ||
| 269 | echo "$HELP" | ||
| 270 | return 1 | ||
| 271 | fi | ||
| 272 | |||
| 273 | echo "The system will $CMD." | ||
| 274 | |||
| 275 | # Execute the commands | ||
| 276 | custom_extention toaster_prepend $CMD $ADDR_PORT | ||
| 277 | |||
| 278 | case $CMD in | ||
| 279 | start ) | ||
| 280 | # check if addr:port is not in use | ||
| 281 | if [ "$CMD" == 'start' ]; then | ||
| 282 | if [ $WEBSERVER -gt 0 ]; then | ||
| 283 | $MANAGE checksocket "$ADDR_PORT" || return 1 | ||
| 284 | fi | ||
| 285 | fi | ||
| 286 | |||
| 287 | # Create configuration file | ||
| 288 | conf=${BUILDDIR}/conf/local.conf | ||
| 289 | line='INHERIT+="toaster buildhistory"' | ||
| 290 | grep -q "$line" $conf || echo $line >> $conf | ||
| 291 | |||
| 292 | if [ $WEBSERVER -eq 0 ] ; then | ||
| 293 | # Do not update the database for "noweb" unless | ||
| 294 | # it does not yet exist | ||
| 295 | if [ ! -f "$TOASTER_DIR/toaster.sqlite" ] ; then | ||
| 296 | if ! databaseCheck; then | ||
| 297 | echo "Failed ${CMD}." | ||
| 298 | return 4 | ||
| 299 | fi | ||
| 300 | fi | ||
| 301 | custom_extention noweb_start_postpend $ADDR_PORT | ||
| 302 | fi | ||
| 303 | if [ $WEBSERVER -gt 0 ] && ! webserverStartAll; then | ||
| 304 | echo "Failed ${CMD}." | ||
| 305 | return 4 | ||
| 306 | fi | ||
| 307 | export BITBAKE_UI='toasterui' | ||
| 308 | if [ $TOASTER_BUILDSERVER -eq 1 ] ; then | ||
| 309 | $MANAGE runbuilds \ | ||
| 310 | </dev/null >>${TOASTER_LOGS_DIR}/toaster_runbuilds.log 2>&1 \ | ||
| 311 | & echo $! >${BUILDDIR}/.runbuilds.pid | ||
| 312 | else | ||
| 313 | echo "Toaster build server not started." | ||
| 314 | fi | ||
| 315 | |||
| 316 | # set fail safe stop system on terminal exit | ||
| 317 | trap stop_system SIGHUP | ||
| 318 | echo "Successful ${CMD}." | ||
| 319 | custom_extention toaster_postpend $CMD $ADDR_PORT | ||
| 320 | return 0 | ||
| 321 | ;; | ||
| 322 | stop ) | ||
| 323 | stop_system | ||
| 324 | echo "Successful ${CMD}." | ||
| 325 | ;; | ||
| 326 | manage ) | ||
| 327 | cd $BBBASEDIR/lib/toaster | ||
| 328 | $MANAGE $manage_cmd | ||
| 329 | ;; | ||
| 330 | esac | ||
| 331 | custom_extention toaster_postpend $CMD $ADDR_PORT | ||
| 332 | |||
