Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def install_package(dss, package_name):
- print("Installing package: {}".format(package_name))
- with paramiko.SSHClient() as ssh:
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname=dss.host, username=dss.username, password=dss.password)
- channel = ssh.invoke_shell()
- LogInAsRoot(channel, dss)
- commands = ('opkg update', 'opkg install {}'.format(package_name))
- for command in commands:
- send_command_with_confirmation(channel=channel, command=command, delay=20, print_response=True)
- print("Package {} installed properly".format(package_name))
- def checkIfPackageIsInstalled(dss, package_name):
- print("Checking if package {} is installed".format(package_name))
- with paramiko.SSHClient() as ssh:
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(hostname=dss.host, username=dss.username, password=dss.password)
- channel = ssh.invoke_shell()
- LogInAsRoot(channel, dss)
- command = 'opkg list-installed | grep {}\n'.format(package_name)
- try:
- '''
- exit code 0 - package is installed
- exit code 1 - package not installed
- '''
- send_command_with_confirmation(channel, command)
- except ProblemOccuredWhileExecutingCommand:
- return False
- return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement