#!/usr/local/bin/python import socket,os def get_ip(): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect(("8.8.8.8", 80)) res = s.getsockname()[0] return res def check_mount(fpath): check_mnt = os.path.ismount(fpath) if check_mnt == True: if fpath == '/Users/maddiekorea/BUNTUPAD': destpath = fpath + "/data" if fpath == '/Users/maddiekorea/IMAC': destpath = fpath + "/Parallels" check_dir = os.path.isdir(destpath) if check_dir == True: res = True else: res = False else: res = False return res def brew_backup(): cmd = "d=`date +%Y-%m-%d`; " cmd = cmd + 'f="/Users/maddiekorea/BUNTUPAD/data/imac/macbookair_brew_list_"$d".txt"; ' cmd = cmd + '/opt/homebrew/bin/brew list > $f; /usr/bin/bzip2 -f $f;' return cmd if __name__ == '__main__': ip = get_ip() print(ip) mount_points = [{'mount_point': '/Users/maddiekorea/BUNTUPAD', 'cmd': '/usr/local/bin/sshfs -o volname=BUNTUPAD,follow_symlinks,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user,auto_xattr,dev,suid,defer_permissions,noappledouble,noapplexattr maddiekorea@192.168.0.10:/home/maddiekorea /Users/maddiekorea/BUNTUPAD', 'umount': '/usr/sbin/diskutil unmount /Users/maddiekorea/BUNTUPAD'}, {'mount_point': '/Users/maddiekorea/IMAC', 'cmd': '/usr/local/bin/sshfs -o volname=IMAC,follow_symlinks,reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,idmap=user,auto_xattr,dev,suid,defer_permissions,noappledouble,noapplexattr maddiekorea@192.168.0.3:/Users/maddiekorea /Users/maddiekorea/IMAC', 'umount': '/usr/sbin/diskutil unmount /Users/maddiekorea/IMAC'}] if ip == '192.168.0.77' : for i in range(len(mount_points)): if check_mount(mount_points[i]['mount_point']) == False: os.system(mount_points[i]['umount']) os.system(mount_points[i]['cmd']) print(mount_points[i]['mount_point'] + " is Mounted.") else: print(mount_points[i]['mount_point'] + " is already Mounted.") #os.system(brew_backup()) #print("brew list back-uped.") else: #print("You're not in Home.") for i in range(len(mount_points)): if check_mount(mount_points[i]['mount_point']) == True: os.system(mount_points[i]['umount']) print(mount_points[i]['cmd'] + " is unMounted.")