<commit_before>#!/bin/bash
# Copyright (C) 2017 Kubos Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

spinner() {
    local sp i n
    sp='/-\|'
    n=${#sp}
    while sleep 0.15; do
        printf "%s\b" "${sp:i++%n:1}"
    done
}

start=$(date +%s)

this_dir=$(cd "`dirname "$0"`"; pwd)
program=$1
name=$(basename $1)

password=$(cat yotta_config.json | python -c 'import sys,json; x=json.load(sys.stdin); print x["system"]["password"]')

unamestr=`uname`

if [[ "$unamestr" =~ "Linux" ]]; then
    device=`lsusb -d '0403:'`
fi

if [[ "$device" =~ "6001" ]]; then
    echo "Compatible FTDI device found"
    spinner &
    spinner_pid=$!
    disown
else
    echo "No compatible FTDI device found" 1>&2
    exit 0
fi

if [ "$password" == "<PASSWORD>" ]; then
    echo "Using default password"
fi

# Minicom doesn't allow any pass-through arguments, so instead we need to 
# generate a script for it to run.
cat > send.tmp <<-EOF
verbose on
send root
expect {
    "Password:" break
    timeout 1 break
}
send $password
expect {
    "~ #" break
    timeout 5 goto end
}
send "cd /usr/bin"
send "rm $name"
send "rz -bZ"
! sz -b --zmodem $1
send "exit"
end:
! killall minicom -q
EOF

# Run the transfer script
echo "Sending file to board..."
minicom kubos -o -S send.tmp > flash.log

# Check transfer result
if grep -q incomplete flash.log; then<commit_msg>Adding detection and routing for flashing KubOS Linux upgrade packages<commit_after>#!/bin/bash
# Copyright (C) 2017 Kubos Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

spinner() {
    local sp i n
    sp='/-\|'
    n=${#sp}
    while sleep 0.15; do
        printf "%s\b" "${sp:i++%n:1}"
    done
}

start=$(date +%s)

this_dir=$(cd "`dirname "$0"`"; pwd)
program=$1
name=$(basename $1)
is_upgrade=0

password=$(cat yotta_config.json | python -c 'import sys,json; x=json.load(sys.stdin); print x["system"]["password"]')

unamestr=`uname`

if [[ "$unamestr" =~ "Linux" ]]; then
    device=`lsusb -d '0403:'`
fi

if [[ "$device" =~ "6001" ]]; then
    echo "Compatible FTDI device found"
    spinner &
    spinner_pid=$!
    disown
else
    echo "No compatible FTDI device found" 1>&2
    exit 0
fi

if [ "$password" == "<PASSWORD>" ]; then
    echo "Using default password"
fi

if [[ "$name" = *.itb ]]; then
    path="/upgrade"
    is_upgrade=1
else
    path="/home/usr/bin"
fi

# Minicom doesn't allow any pass-through arguments, so instead we need to 
# generate a script for it to run.
cat > send.tmp <<-EOF
verbose on
send root
expect {
    "Password:" break
    timeout 1 break
}
send $password
expect {
    "~ #" break
    timeout 5 goto end
}
send "cd $path"
send "rm $name"
send "rz -bZ"
! sz -b --zmodem $1
if $is_upgrade = 1 send "fw_setenv kubos_updatefile $name"
send "exit"
end:
! killall minicom -q
EOF

# Run the transfer script
echo "Sending $name to $path on board..."
minicom kubos -o -S send.tmp > flash.log

# Check transfer result
if grep -q incomplete flash.log; then
{'fraction_non_alphanumeric': 0.13073047858942066, 'fraction_numerical': 0.015365239294710327, 'mean_word_length': 3.497168742921857, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5212295', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1316, 'n_words': 509}