Example #1
0
def main(args):
    print 'connecting to the Controller...'
    controller = soloutils.connect_controller(await=True)

    controller_version = soloutils.controller_versions(controller)['version']
    if LooseVersion('1.1.15') != LooseVersion(controller_version):
        print 'error: expecting Controller to be EXACTLY EQUAL TO 1.1.15'
        print 'your Controller version: {}'.format(controller_version)
        print 'please flash your Controller with 1.1.15 to run this command.'
        print ''
        print '    solo update solo 1.1.15'
        print '    solo update controller 1.1.15'
        sys.exit(1)

    code = soloutils.command_stream(controller, SCRIPT.format(ssid=args['--name'], password=args['--password']))
    controller.close()

    if code == 0:
        try:
            print 'resetting Solo\'s wifi...'
            print '(if solo is not online, you can hit Ctrl+C safely now.)'
            solo = soloutils.connect_solo(await=True)
            soloutils.command_stream(solo, 'init 2 && init 4')
            solo.close()
        except KeyboardInterrupt:
            pass

        print 'setup complete! you are now connected to the Internet.'
        print "(if you are not connected to the Internet on your PC,"
        print " disconnect and reconnect to Solo\'s network.)"

    sys.exit(code)
Example #2
0
def factory_reset(args):
    if args['both']:
        group = 'Solo and the Controller'
    if args['drone']:
        group = 'Solo'
    if args['controller']:
        group = 'the Controller'

    print('connecting to {}...'.format(group))

    if args['drone'] or args['both']:
        solo = soloutils.connect_solo(await=True)
    if args['controller'] or args['both']:
        controller = soloutils.connect_controller(await=True)

    if args['drone'] or args['both']:
        soloutils.factory_reset(solo)
        print('Solo will restore to factory version once it reboots.')
    if args['controller'] or args['both']:
        newstyle = soloutils.factory_reset(controller)
        print('Controller will restore to factory version once it reboots.')

    dt = datetime.today() + timedelta(minutes=4)
    print('please wait up to four minutes longer for the process to complete (by {}).'.format(dt.strftime('%-I:%M')))

    if args['drone'] or args['both']:
        solo.close()
    if args['controller'] or args['both']:
        controller.close()

    sys.exit(0)
Example #3
0
def run_main(args):
    if not os.path.exists(SCRIPT_FILENAME):
        print 'ERROR: Please run "solo script pack" first to bundle your archive.'
        return 1

    print 'connecting to solo...'
    solo = soloutils.connect_solo(await=True)
    scp = SCPClient(solo.get_transport())

    # Requires pip
    print 'checking pip...'
    if soloutils.install_pip.run(solo, scp) != 0:
        print 'failed installing pip.'
        sys.exit(1)

    push(solo, scp, '--force' in args['<arg>'])

    print 'running script...'
    print ''
    soloutils.command_stream(solo, '''
set -e
cd /log/solo-script
source ./env/bin/activate
exec python /log/solo-script/''' + args['<arg>'][1]  + '''
''')

    scp.close()
    solo.close()
Example #4
0
def main(args):
    print 'NOTE: this process requires simultaneous access to'
    print 'Solo and to the Internet. if you have not yet done so,'
    print 'run `solo wifi` to connect to Solo and to a local'
    print 'wifi connection simultaneously.'
    print ''
    print 'NOTE: also run `solo install-smart` first.'
    print ''

    # prompt for consent
    print 'WARNING: this can break your Solo and require a factory reset!'
    print 'your Solo will turn off after and you will need to power cycle it.'
    y = raw_input('proceed to resize filesystem? [y/N] ')
    if not (y.lower() == 'y' or y.lower() == 'yes'):
        sys.exit(1)

    print ''
    print 'connecting to solo...'
    solo = soloutils.connect_solo(await=True)

    print 'waiting for Internet connectivity...'
    soloutils.await_net()

    print ''
    code = soloutils.command_stream(solo, SCRIPT)

    print ''
    dt = datetime.today() + timedelta(minutes=4)
    print('please wait up to four minutes longer for the resize to complete (at {}).'.format(dt.strftime('%-I:%M')))
    print('(you can manually restart solo if it fails to come online again.)')

    solo.close()
    sys.exit(code)
Example #5
0
def main(args):
    print 'connecting to solo...'
    solo = soloutils.connect_solo(await=True)

    if args['acquire']:
        code = soloutils.command_stream(solo, ACQUIRE)
    elif args['restore']:
        code = soloutils.command_stream(solo, RESTORE)

    solo.close()
    sys.exit(code)
Example #6
0
def main(args):
    print 'connecting to Solo and the Controller...'

    controller = soloutils.connect_controller(await=True)
    solo = soloutils.connect_solo(await=True)

    data = {}
    data['solo'] = soloutils.solo_versions(solo)
    data['pixhawk'] = soloutils.pixhawk_versions(solo)
    data['gimbal'] = soloutils.gimbal_versions(solo)
    data['controller'] = soloutils.controller_versions(controller)

    print json.dumps(data, indent=2, sort_keys=True)
Example #7
0
def main(args):
    print 'connecting to solo...'
    solo = soloutils.connect_solo(await=True)
    scp = SCPClient(solo.get_transport())

    code = run(solo, scp)
    if code == 0:
        print 'pip is ready to use.'

    scp.close()
    solo.close()

    sys.exit(code)
Example #8
0
def flash(target, firmware_file, firmware_md5, args):
    # Connect to controller...
    if target == 'controller':
        errprinter('connecting to Controller...')
        client = soloutils.connect_controller(await=True)
    else:
        errprinter('connecting to Solo...')
        client = soloutils.connect_solo(await=True)

    # Prepare the update.
    # older versions don't have sololink_config and ssh returns 127, so do it manually
    code = soloutils.command_stream(client, 'sololink_config --update-prepare sololink')
    if code != 0:
        soloutils.command_stream(client, 'rm -rf /log/updates && mkdir -p /log/updates')

    # Upload the files.
    errprinter('uploading files...')
    scp = SCPClient(client.get_transport())
    scp.put(firmware_file, posixpath.join('/log/updates/', posixpath.basename(firmware_file)))
    scp.put(firmware_md5, posixpath.join('/log/updates/', posixpath.basename(firmware_md5)))
    scp.close()

    if target == 'controller':
        errprinter("starting update on the Controller...")
    else:
        errprinter("starting update on Solo...")

    if args['--clean']:
        errprinter('marking all user-local changes to be reset...')
        code = soloutils.command_stream(client, 'sololink_config --update-apply sololink --reset')
    else:
        code = soloutils.command_stream(client, 'sololink_config --update-apply sololink')
    # Fallback to earlier versions.
    if code != 0:
        if args['--clean']:
            code = soloutils.command_stream(client, 'touch /log/updates/UPDATE && touch /log/updates/RESETSETTINGS && shutdown -r now')
        else:
            code = soloutils.command_stream(client, 'touch /log/updates/UPDATE && shutdown -r now')
        
    if target == 'controller':
        errprinter('the Controller will update once it reboots!')
    else:
        errprinter('Solo will update once it reboots!')

    dt = datetime.today() + timedelta(minutes=4)
    errprinter('please wait up to four minutes longer for the installation to complete (by {}).'.format(dt.strftime('%-I:%M')))

    # Complete!
    client.close()

    return code
Example #9
0
def main(args):
    print 'connecting to Solo...'
    solo = soloutils.connect_solo(await=True)

    code, stdout, stderr = soloutils.command(solo, 'ls -p /log | grep -v /')
    files = stdout.strip().split()

    scp = SCPClient(solo.get_transport())
    count = 0
    for item in files:
    	print 'file {} of {}...'.format(count, len(files))
    	scp.get('/log/' + item)
    	count += 1

    print 'complete.'
Example #10
0
def main(args):
    print 'connecting to the Controller...'
    controller = soloutils.connect_controller(await=True)

    controller_version = soloutils.controller_versions(controller)['version']
    if LooseVersion('1.2.0') > LooseVersion(controller_version):
        print 'error: expecting version to be >= 1.2.0'
        print 'your Controller version: {}'.format(controller_version)
        print 'please flash your Controller with a newer version to run this command.'
        print ''
        print '    solo update solo latest'
        print '    solo update controller latest'
        sys.exit(1)

    print ''
    if args['--password']:
        print 'connecting to encrypted wifi network.'
        credentials = 'ssid="{ssid}"\npsk="{password}"'.format(ssid=args['--name'], password=args['--password'])
    else:
        print 'connecting to wifi network with NO password.'
        credentials = 'ssid="{ssid}"\nkey_mgmt=NONE'.format(ssid=args['--name'])
    print '(your computer may disconnect from Solo\'s network.)'

    controller = soloutils.connect_controller(await=True)
    code = soloutils.command_blind(controller, SCRIPT.format(credentials=credentials))
    time.sleep(8)
    controller.close()

    print ''
    print 'please manually reconnect to Solo\'s network once it becomes available.'
    print 'it may take up to 30s to a reconnect to succeed.'
    controller = soloutils.connect_controller(await=True, silent=True)
    print ''
    code = soloutils.command_stream(controller, 'cat /log/setupwifi.log')
    controller.close()

    try:
        drone = soloutils.connect_solo(await=False)
        print '(resetting Solo\'s DNS...',
        sys.stdout.flush()
        soloutils.command(drone, 'ifdown wlan0; ifdown -a; ifup -a; ifup wlan0')
        time.sleep(4)
        drone.close()
        print ' done.)'
    except:
        pass

    sys.exit(code)
Example #11
0
def main(args):
    print 'NOTE: this process requires simultaneous access to'
    print 'Solo and to the Internet. if you have not yet done so,'
    print 'run `solo wifi` to connect to Solo and to a local'
    print 'wifi connection simultaneously.'
    print ''

    print 'connecting to solo...'
    solo = soloutils.connect_solo(await=True)

    print 'waiting for Internet connectivity...'
    soloutils.await_net()

    print ''
    code = soloutils.command_stream(solo, SCRIPT)
    solo.close()
    sys.exit(code)
Example #12
0
def main(args):
    rsa = os.path.join(expanduser('~'), '.ssh/id_rsa.pub')
    dsa = os.path.join(expanduser('~'), '.ssh/id_dsa.pub')
    if not (os.path.isfile(rsa) or os.path.isfile(dsa)):
        print 'no $HOME/.ssh/id_rsa.pub or $HOME/.ssh/id_dsa.pub file found.'
        print 'run ssh-keygen and try again.'
        sys.exit(1)

    if os.path.isfile(rsa):
        key = open(rsa).read()
    else:
        key = open(dsa).read()

    controller = soloutils.connect_controller(await=True)
    solo = soloutils.connect_solo(await=True)

    soloutils.command(solo, 'test -d .ssh || mkdir -m 0700 .ssh ; echo $\'' + key + '\' >> ~/.ssh/authorized_keys')
    soloutils.command(controller, 'test -d .ssh || mkdir -m 0700 .ssh ; echo $\'' + key + '\' >> ~/.ssh/authorized_keys')
    
    print 'provisioned.'
Example #13
0
def push_main(args):
    if not os.path.exists(SCRIPT_FILENAME):
        print 'ERROR: Please run "solo script pack" first to bundle your archive.'
        return 1

    print 'connecting to solo...'
    solo = soloutils.connect_solo(await=True)
    scp = SCPClient(solo.get_transport())

    # Requires pip
    print 'checking pip...'
    if soloutils.install_pip.run(solo, scp) != 0:
        print 'failed installing pip.'
        sys.exit(1)

    # TODO check args['<arg>'] for --force

    push(solo, scp, '--force' in args['<arg>'])

    scp.close()
    solo.close()
Example #14
0
def main(args):
    if args['both']:
        group = 'Solo and the Controller'
    if args['solo']:
        group = 'Solo'
    if args['controller']:
        group = 'the Controller'

    # prompt for consent
    print 'you are about to revert all local changes made to {}.'.format(group)
    print 'this process is not reversible.'
    y = raw_input('proceed to revert local changes? [y/N] ')
    if not (y.lower() == 'y' or y.lower() == 'yes'):
        sys.exit(1)

    if not args['current']:
        print 'TODO: only solo revert to "current" works yet.'
        sys.exit(1)

    print 'connecting to {}...'.format(group)

    if args['solo'] or args['both']:
        solo = soloutils.connect_solo(await=True)
    if args['controller'] or args['both']:
        controller = soloutils.connect_controller(await=True)

    if args['solo'] or args['both']:
        soloutils.settings_reset(solo)
        print('Solo will continue reverting once it reboots.')
    if args['controller'] or args['both']:
        newstyle = soloutils.settings_reset(controller)
        print('Controller will continue reverting once it reboots.')

    dt = datetime.today() + timedelta(minutes=4)
    print('please wait up to four minutes longer for the process to complete (at {}).'.format(dt.strftime('%-I:%M')))

    if args['solo'] or args['both']:
        solo.close()
    if args['controller'] or args['both']:
        controller.close()
Example #15
0
def main(args):

    os.makedirs('./drone')
    os.makedirs('./controller')

    print 'connecting to Solo...'
    solo = soloutils.connect_solo(await=True)
    code, stdout, stderr = soloutils.command(solo, 'ls -p /log | grep -v /')
    files = stdout.strip().split()

    os.chdir('./drone')
    scp = SCPClient(solo.get_transport())
    count = 0
    for item in files:
    	print 'file {} of {}...'.format(count, len(files))
    	scp.get('/log/' + item)
    	count += 1
    os.chdir('..')

    solo.close()

    print 'connecting to Controller...'
    controller = soloutils.connect_controller(await=True)
    code, stdout, stderr = soloutils.command(controller, 'ls -p /log | grep -v /')
    files = stdout.strip().split()

    os.chdir('./controller')
    scp = SCPClient(controller.get_transport())
    count = 0
    for item in files:
        print 'file {} of {}...'.format(count, len(files))
        scp.get('/log/' + item)
        count += 1
    os.chdir('..')

    controller.close()

    print 'logs download complete.'
Example #16
0
def flash_px4(firmware_file):
    errprinter('connecting to Solo...')
    client = soloutils.connect_solo(await=True)
    soloutils.command_stream(client, 'rm -rf /firmware/loaded')

    # Upload the files.
    errprinter('uploading files...')
    scp = SCPClient(client.get_transport())
    scp.put(firmware_file, '/firmware')
    scp.close()

    # shutdown solo for firmware reflash
    #code = soloutils.command_stream(client, 'shutdown -r now')
    code = soloutils.command_stream(client, 'loadPixhawk.py')
    #errprinter('Solo will update once it reboots!')
    errprinter('Pixhawk has been updated to new firmware')
    #dt = datetime.today() + timedelta(minutes=4)
    #errprinter('please wait up to four minutes longer for the installation to complete (by {}).'.format(dt.strftime('%-I:%M')))

    # Complete!
    client.close()

    sys.exit(0)
Example #17
0
def main(args):
    if args["both"]:
        group = "Solo and the Controller"
    if args["solo"]:
        group = "Solo"
    if args["controller"]:
        group = "the Controller"

    version = None
    if args["<version>"]:
        version = re.sub(r"^v", "", args["<version>"])
        if not re.match(r"^\d+", version):
            errprinter("error: verion number specified looks invalid.")
            sys.exit(1)

    if not args["--list"]:
        # prompt for consent
        errprinter("you are about to update {}.".format(group))
        errprinter("this preserves all your local changes to Solo, but compatibility")
        errprinter("with newer updates is not guaranteed.")
        y = raw_input("proceed to perform update? [y/N] ")
        if not (y.lower() == "y" or y.lower() == "yes"):
            sys.exit(1)

    if not args["latest"] and not version and not args["--list"]:
        errprinter('TODO: only solo update to "latest" or "<version>" works yet.')
        sys.exit(1)
    if args["both"]:
        errprinter('TODO: only "solo" or "controller" update yet works, not "both".')
        sys.exit(1)

    errprinter("checking Internet connectivity...")
    soloutils.await_net()

    if args["controller"]:
        product = [1, 10]
    else:
        product = [2, 9]

    updates = releases(product)

    if version:
        updates = filter(lambda x: version in re.sub(".tar.gz", "", x.url.split("/")[-1]), updates)
        if len(updates) == 0:
            errprinter("error: no version matching {} were found.".format(version))
            sys.exit(1)

    if args["--list"]:
        for update in updates:
            print(update.version)
        sys.exit(0)

    # download file
    file_loc, md5_loc = fetch(updates[-1])

    errprinter("please power-up the Controller and connect your PC to the Solo wifi network.")

    # Connect to controller...
    if args["controller"]:
        errprinter("connecting to Controller...")
        client = soloutils.connect_controller(await=True)
    else:
        errprinter("connecting to Solo...")
        client = soloutils.connect_solo(await=True)

    # Prepare the update.
    # older versions don't have sololink_config and ssh returns 127, so do it manually
    code = soloutils.command_stream(client, "sololink_config --update-prepare sololink")
    if code != 0:
        soloutils.command_stream(client, "rm -rf /log/updates && mkdir -p /log/updates")

    # Upload the files.
    errprinter("uploading updates...")
    scp = SCPClient(client.get_transport())
    scp.put(file_loc, posixpath.join("/log/updates/", posixpath.basename(file_loc)))
    scp.put(md5_loc, posixpath.join("/log/updates/", posixpath.basename(md5_loc)))
    scp.close()

    if args["controller"]:
        errprinter("starting update on the Controller...")
    else:
        errprinter("starting update on Solo...")
    code = soloutils.command_stream(client, "sololink_config --update-apply sololink")
    if code != 0:
        code = soloutils.command_stream(client, "touch /log/updates/UPDATE && shutdown -r now")
        if args["controller"]:
            errprinter("the Controller will update once it reboots.")
        else:
            errprinter("Solo will update once it reboots.")
    else:
        errprinter("update succeeded!")

    dt = datetime.today() + timedelta(minutes=4)
    errprinter(
        "please wait up to four minutes longer for the installation to complete (at {}).".format(dt.strftime("%-I:%M"))
    )

    # Complete!
    client.close()
    sys.exit(code)