forked from AloneMonkey/MonkeyDev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd-uninstall
executable file
·127 lines (100 loc) · 2.87 KB
/
md-uninstall
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
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
export setCmd="set -eo pipefail"
$setCmd
export PATH=/opt/MonkeyDev/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin:$PATH
export scriptName="${0##*/}"
export scriptVer="2.0"
export MonkeyDevPath="/opt/MonkeyDev"
export backupFileExt=".MonkeyDev"
export userName="${SUDO_USER-$USER}"
export userGroup=`id -g $userName`
export userHome=`eval echo ~$userName`
export bashProfileFiles=("$userHome/.zshrc" "$userHome/.bash_profile" "$userHome/.bashrc" "$userHome/.bash_login" "$userHome/.profile")
export tempDirsFile="`mktemp -d -t $scriptName`/tempdirs"
touch "$tempDirsFile"
unset LANG
function cleanup()
{
local exitCode=$?
set +e
trap - $signals
removeTempData
exit $exitCode
}
function panic()
{
local exitCode=$1
set +e
shift
[[ "$@" == "" ]] || echo "$@" >&2
exit $exitCode
}
export signals="0 1 2 3 15"
trap cleanup $signals
function removeTempData()
{
local tempDirs
if [[ -f "$tempDirsFile" ]]; then
tempDirs=(`cat "$tempDirsFile"`)
for td in "${tempDirs[@]}"; do
rm -rf "$td" || true
done
rm -rf "`dirname $tempDirsFile`" || true
fi
}
function copyFile()
{
cp -f "$1" "$2" || \
panic $? "Failed to copy file $1 to $2"
}
#还原文件
function restoreFile()
{
local filePath="$1"
local backedUpFilePath="${filePath}${backupFileExt}"
if [[ -f "$backedUpFilePath" ]]; then
copyFile "$backedUpFilePath" "$filePath"
rm -f "$backedUpFilePath"
fi
}
#获取SDK信息
function getSdkProperty()
{
$setCmd
local sdk="$1"
local propertyName="$2"
propertyValue=`xcodebuild -version -sdk $sdk $propertyName` || \
panic $? "Failed to get $sdk SDK property $propertyName"
[[ $propertyValue != "" ]] || \
panic 1 "Value of $sdk SDK property $propertyName cannot be empty"
# return #
echo "$propertyValue"
}
echo "Uninstalling MonkeyDev base, Xcode templates and framework header files..."
#删除文件夹
rm -rf "$MonkeyDevPath" || \
panic $? "Failed to remove directory: $MonkeyDevPath"
#移除模块符号链接
userDevDir="$userHome/Library/Developer"
userTemplatesDir="$userDevDir/Xcode/Templates"
symlinkPath="$userTemplatesDir/MonkeyDev"
rm -f "$symlinkPath" || \
panic $? "Failed to remove file: $symlinkPath"
#移除profile环境变量
for f in "${bashProfileFiles[@]}"; do
if [[ -f "$f" ]]; then
userBashProfileFile="$f"
break
fi
done
if [[ $userBashProfileFile != "" ]]; then
sed -i "" "s/^export MonkeyDevPath=.*$//g" "$userBashProfileFile"
sed -i "" "s/^export MonkeyDevDeviceIP=.*$//g" "$userBashProfileFile"
sed -i "" "s/^export PATH=.*${MonkeyDevPath//\//\\/}\\/bin:.*$//g" "$userBashProfileFile"
sed -i "" "s/^export PATH=.*\$MonkeyDevPath\\/bin:.*$//g" "$userBashProfileFile"
fi
iosSdkPlatformPath=`getSdkProperty iphoneos PlatformPath`
specificationFile=$(cd $iosSdkPlatformPath/../../.. && pwd)/PlugIns/IDEiOSSupportCore.ideplugin/Contents/Resources/Embedded-Device.xcspec
#还原文件
restoreFile "$specificationFile"
exit 0