#!/usr/bin/env python3
import os
import subprocess
import sys
import platform
if 82 - 82: Iii1i
def run_command ( cmd , timeout = 10 ) :
 try :
  if 87 - 87: Ii % i1i1i1111I . Oo / OooOoo * I1Ii1I1 - I1I
  if isinstance ( cmd , str ) :
   cmd = cmd . split ( )
  ooo0oOoooOOO0 = subprocess . run ( cmd , timeout = timeout , capture_output = True , text = True )
  return ooo0oOoooOOO0
 except Exception as oOo0O00 :
  print ( "Command execution error: {0}" . format ( oOo0O00 ) )
  return None
  if 83 - 83: iIII
def check_macos ( ) :
 return platform . system ( ) == 'Darwin'
 if 82 - 82: IiIIii11Ii % OOoOoo000O00 * Oo0Oo - ii1I1iII1I1I . i1I1IiIIiIi1 % oo0O000ooO
 if 98 - 98: IiiIIiii1 % iIi1ii1I1iI11
def create_launchd_service ( service_name , python_exe , script_name , working_dir ) :
 if 55 - 55: I11II1Ii % iIi
 if 76 - 76: i11 / iI . I11II1Ii . IiIIii11Ii / iIi1ii1I1iI11
 if 28 - 28: i11 / iIi1ii1I1iI11 % iIi1ii1I1iI11 / I1I - Oo
 IIII1i1 = {
 'wg1001' : 'WG1001 Cloud Server' ,
 'wgVw3000' : 'WG Vw3000 Service'
 }
 if 84 - 84: Ii . Oo0Oo - iIII . I1I / IiiIIiii1 % OooOoo
 oOooO0 = '''<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.wgcloud.{0}</string>
    <key>ProgramArguments</key>
    <array>
        <string>{1}</string>
        <string>{2}</string>
    </array>
    <key>WorkingDirectory</key>
    <string>{3}</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/tmp/{4}.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/{5}.error</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>
</dict>
</plist>''' . format ( service_name , python_exe , os . path . join ( working_dir , script_name ) , working_dir , service_name , service_name )
 if 13 - 13: iIi
 iiIII = "/Library/LaunchDaemons/com.wgcloud.{0}.plist" . format ( service_name )
 if 28 - 28: I1Ii1I1 . Iii1i - IiIIii11Ii - IiiIIiii1
 if 37 - 37: iIi * iIi1ii1I1iI11 * I1I / OOoOoo000O00
 if os . path . exists ( iiIII ) :
  run_command ( 'sudo launchctl unload {0}' . format ( iiIII ) )
  run_command ( 'sudo rm {0}' . format ( iiIII ) )
  if 28 - 28: i11
  if 95 - 95: Oo0Oo . Ii . iIi1ii1I1iI11 % I11II1Ii % I1Ii1I1
 try :
  with open ( "/tmp/com.wgcloud.{0}.plist" . format ( service_name ) , "w" ) as ii1i :
   ii1i . write ( oOooO0 )
   if 87 - 87: Oo - i11
   if 32 - 32: Ii % i1i1i1111I % i11 - I11II1Ii % Oo0Oo
  run_command ( 'sudo mv /tmp/com.wgcloud.{0}.plist {1}' . format ( service_name , iiIII ) )
  run_command ( 'sudo chmod 644 {0}' . format ( iiIII ) )
  run_command ( 'sudo chown root:wheel {0}' . format ( iiIII ) )
  if 34 - 34: Oo0Oo * iIII
  print ( "Created {0} service successfully" . format ( IIII1i1 . get ( service_name , service_name ) ) )
  return True
 except Exception as O00O :
  print ( "Failed to create service: {0}" . format ( O00O ) )
  return False
  if 59 - 59: Iii1i . iI - i11
def install_macos_services ( ) :
 if not check_macos ( ) :
  if 13 - 13: iIi
  print ( "This script is only for macOS systems" )
  return False
  if 28 - 28: OooOoo + i1i1i1111I + ii1I1iII1I1I / I1Ii1I1 + IiiIIiii1
 o0O0ooOoo00o = os . path . dirname ( os . path . abspath ( __file__ ) )
 Oo0Oo00O0OO = sys . executable
 if 7 - 7: oo0O000ooO
 print ( "Working directory: {0}" . format ( o0O0ooOoo00o ) )
 print ( "Python interpreter: {0}" . format ( Oo0Oo00O0OO ) )
 if 36 - 36: Iii1i
 if 43 - 43: IiIIii11Ii * I1Ii1I1
 if create_launchd_service ( 'wg1001' , Oo0Oo00O0OO , '1001CloudServer.py' , o0O0ooOoo00o ) :
  run_command ( 'sudo launchctl load -wF /Library/LaunchDaemons/com.wgcloud.wg1001.plist' )
  print ( "Started wg1001 service successfully" )
  if 95 - 95: oo0O000ooO % Iii1i % i1i1i1111I . OooOoo
  if 70 - 70: ii1I1iII1I1I
 if create_launchd_service ( 'wgVw3000' , Oo0Oo00O0OO , 'Vw3000.py' , o0O0ooOoo00o ) :
  run_command ( 'sudo launchctl load -wF /Library/LaunchDaemons/com.wgcloud.wgVw3000.plist' )
  print ( "Started wgVw3000 service successfully" )
  if 75 - 75: oo0O000ooO / Ii / ii1I1iII1I1I + ii1I1iII1I1I . I1I
 return True
 if 88 - 88: Oo * ii1I1iII1I1I
def open_browser_macos ( ) :
 oooOo = 'http://localhost:61085'
 if 23 - 23: oo0O000ooO + iIII * I1Ii1I1 + Oo * Ii - iIi1ii1I1iI11
 run_command ( 'open {0}' . format ( oooOo ) )
 print ( "!!!Access webpage: {0} (Username: abc Password: 123)" . format ( oooOo ) )
 if 29 - 29: ii1I1iII1I1I - OOoOoo000O00
if __name__ == '__main__' :
 if install_macos_services ( ) :
  open_browser_macos ( )
  print ( "\nInstallation completed!" )
  print ( "Service log locations:" )
  print ( "wg1001: /tmp/wg1001.log" )
  print ( "wgVw3000: /tmp/wgVw3000.log" )
# dd678faae9ac167bc83abf78e5cb2f3f0688d3a3
