mynode/rootfs/standard/usr/bin/mynode-manage-apps

82 lines
2.8 KiB
Plaintext
Raw Normal View History

2022-03-20 02:53:50 +00:00
#!/usr/local/bin/python3
from argparse import ArgumentParser
from application_info import *
2022-03-26 03:42:55 +00:00
import logging
from systemd import journal
2022-03-22 04:36:54 +00:00
import os
2022-03-26 03:42:55 +00:00
log = logging.getLogger('mynode_manage_apps')
log.addHandler(journal.JournaldLogHandler())
log.setLevel(logging.INFO)
set_logger(log)
2022-03-20 02:53:50 +00:00
def main():
# Check running as root
if os.geteuid() != 0:
print("This script needs to be run as root.")
exit(1)
# App name arguments should be in shortname format
# mynode-manage-apps [init, openports, install <all|app_name>, uninstall <app_name>, ...]
2022-03-20 02:53:50 +00:00
parser = ArgumentParser(prog='mynode-manage-apps')
subparsers = parser.add_subparsers(dest='command')
parser_init = subparsers.add_parser('init', help='Initialize Apps')
parser_openports = subparsers.add_parser('openports', help='Open app ports in firewall')
parser_install = subparsers.add_parser('install', help='Install Dynamic Application')
parser_install.add_argument('app', help='App to install', default="all", nargs='*')
2022-04-26 03:26:19 +00:00
parser_uninstall = subparsers.add_parser('reinstall', help='Reinstall Dynamic Application')
parser_uninstall.add_argument('app', help='App to reinstall', nargs='+') # required
parser_uninstall = subparsers.add_parser('uninstall', help='Uninstall Dynamic Application')
parser_uninstall.add_argument('app', help='App to uninstall', nargs='+') # required
parser_upgrade = subparsers.add_parser('upgrade', help='Upgrade Dynamic Application')
parser_upgrade.add_argument('app', help='App to install', default="all", nargs='*')
parser_help = subparsers.add_parser('help', help='Display Help')
2022-03-20 02:53:50 +00:00
args = parser.parse_args()
if args.command == "init":
init_dynamic_apps()
elif args.command == "openports":
open_application_ports()
2022-04-26 03:26:19 +00:00
elif args.command == "install" or \
args.command == "upgrade" or \
args.command == "reinstall":
2022-06-24 03:48:55 +00:00
# If no app name, install all
# Re-install requires app name (from above)
app_names = args.app
if not isinstance(app_names, list):
app_names = [app_names]
for app_name in app_names:
2022-04-26 03:26:19 +00:00
if args.command == "reinstall":
clear_installed_version(app_name)
upgrade_dynamic_apps()
elif args.command == "upgrade":
2022-06-24 03:48:55 +00:00
# If no app name, upgrade all
app_names = args.app
if not isinstance(app_names, list):
app_names = [app_names]
for app_name in app_names:
upgrade_dynamic_apps(app_name)
elif args.command == "uninstall":
2022-06-24 03:48:55 +00:00
# Requires specified application
app_names = args.app
for app_name in app_names:
uninstall_dynamic_app(app_name)
elif args.command == "help":
parser.print_help()
2022-03-20 02:53:50 +00:00
else:
parser.print_help()
2022-03-20 02:53:50 +00:00
if __name__ == '__main__':
main()