-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathnigate.py
118 lines (102 loc) · 3.7 KB
/
nigate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import os
from time import sleep
import getpass
# 双引号转义:https://blog.csdn.net/try_and_do/article/details/80649663
# 强制字符串不转义:https://zhidao.baidu.com/question/2057931750861815427.html
# 苦手 = [
# "#/bin/bash\n", "\n", "close_boring(){\n", "sudo spctl --master-disable\n",
# "}\n",
# "check_install() {\n","if [ ! -x $(command -v swift) ]; then\n",
# "xcode-select --install\n",
# "fi\n",
# "\n","\n",
# "if [ ! -x $(command -v brew) ]; then\n",
# "/bin/bash -c ", "\"$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)\"",
# "\nfi\n",
# "\n","\n",
# "if [ ! -e \"/System/Volumes/Data/opt/homebrew/bin/ntfs-3g\" ]; then"
# "\n",
# "brew tap gromgit/homebrew-fuse && brew install --cask macfuse && brew install ntfs-3g-mac\n",
# "fi\n",
# "}\n",
# "mount_nfs() {\n",
# "newDev=$(mount | grep ntfs | awk -F ' ' '{print $1}')\n",
# "for i in $newDev; do\n",
# "onceCutVal=","${i%/*}","\n",
# "twiceCutVal=","${onceCutVal#*//}","\n",
# "thriceCutVal=","${i##*/}","\n",
# "echo \"新设备: \"${thriceCutVal}\n",
# "echo '---------\\n'","\n",
# # "echo \"新设备 : \"$i\n",
# # "onceCutVal=","${i%/*}","\n",
# # "twiceCutVal=","${onceCutVal#*//}","\n",
# # "thriceCutVal=","${i##*/}","\n",
# "sudo umount $i","\n",
# "sudo -S $(which ntfs-3g) /dev/${twiceCutVal} /Volumes/${twiceCutVal} -olocal -oallow_other -o auto_xattr -ovolname=${thriceCutVal}",
# "\n","echo " "\"新设备: ${thriceCutVal},已可读写!\"",
# "\ndone\n","}\n",
# "close_boring\n",
# "check_install\n",
# "mount_nfs\n"
# ]
苦手 = '''#!/bin/bash
close_boring(){
sudo spctl --master-disable
}
check_install() {
if [ ! -x "$(command -v swift)" ]; then
xcode-select --install
fi
if [ ! -x "$(command -v brew)" ]; then
/bin/bash -c "$(curl -fsSL https://gitee.com/ineo6/homebrew-install/raw/master/install.sh)"
fi
}
mount_ntfs() {
ntfs_lines=$(mount | grep ntfs)
echo $ntfs_lines
while read -r line; do
disk=$(echo "$line" | awk '{split($1, a, "/"); print a[3]}')
volume=$(echo "$line" | awk '{split($3, a, "/"); print a[3]}')
echo "新设备: ${volume}"
echo '---------'
sudo umount /dev/$disk
sudo -S $(which ntfs-3g) /dev/$disk /Volumes/$volume -olocal -oallow_other -o auto_xattr -ovolname=$volume
echo "新设备: ${volume},已可读写!"
done <<< "$ntfs_lines"
}
close_boring
check_install
mount_ntfs
'''
username = getpass.getuser()
def File_plus():
folder_path = "/Users/"+username+"/Public/shell-ntfs.sh"
if not os.path.exists(folder_path):
file = open(folder_path, mode='w')
file.writelines(苦手)
else:
print('\nshell-ntfs.sh 文件已检测\n')
print('开启程序第一次启动,接入优盘时,需要输入电脑开机密码,方可正常使用\n')
print('等待NTFS格式优盘接入')
File_plus()
# 第一个U盘完全挂载,再插入第二个U盘
while True:
sleep(5)
udev = os.popen("mount | grep ntfs | awk -F ' ' '{print $1}'")
udev_result = udev.read()
udev.close()
if udev_result:
print("\n已接入优盘")
os.system("chmod 777 /Users/"+username+"/Public/shell-ntfs.sh")
os.system("/Users/"+username+"/Public/shell-ntfs.sh")
while True:
sleep(5)
udev = os.popen("mount | grep ntfs | awk -F ' ' '{print $1}'")
udev_result = udev.read()
udev .close()
if not udev_result:
print("------------")
break
else:
# print("没有NTFS优盘接入")
continue