forked from GStreamer/cerbero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cerbero-uninstalled
executable file
·114 lines (102 loc) · 3.66 KB
/
cerbero-uninstalled
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
#!/bin/sh
#
# This file is an abomination. It executes as both a shell script and a python
# script, and does the same thing in both cases.
#
# Note that this script uses bash syntax but the shebang is `#!/bin/sh` on
# purpose. This is because the bash code only runs on MSYS and `/bin/sh` is
# bash there. macOS will stop shipping bash at some point (post-Catalina), so
# we should not use `#!/bin/bash` as the shebang. Current code is compatible
# on non-MSYS platforms with: bash, dash, zsh.
#
# This is needed because on Windows, python3 is actually `py -3` since all
# Python installations have `python.exe`. We used to use `python3` in the
# shebang, but then Windows folks couldn't use `./cerbero-uninstalled` and had
# to call `py -3 ./cerbero-uninstalled` or `python ./cerbero-uninstalled`
# depending on their python installation.
#
# Now we automatically use `py -3` or `python3` depending on the system.
#
# For backwards-compatibility, we now support all those variants.
"""":
ARGS=$@
SCRIPTDIR="`dirname $0`"
if [ "$OSTYPE" == "msys" ]; then
if [ -f "/mingw/bin/mingw-get.exe" ]; then
MSYS_VERSION=1
elif [ -f "/usr/bin/pacman" ]; then
MSYS_VERSION=2
if [ "$MSYSTEM" != "UCRT64" ]; then
echo "MSYS2 must use the UCRT64 environment instead of $MSYSTEM. https://www.msys2.org/docs/environments/";
exit 1;
fi
fi
fi
case "$MSYS_VERSION" in
*1) PYTHON="py -3";;
*2) PYTHON="winpty py -3";;
*) PYTHON="python3";;
esac
# Use `msysmnt` to get a list of MSYS mount points that the MinGW shell uses.
# That's our reference point for translating from MSYS paths to Win32 paths.
# We assume that the MSYS mount point directories are only in the filesystem
# root. This will break if people add their own custom mount points beyond what
# MSYS automatically creates, which is highly unlikely.
#
# /d -> d:/
# /c -> c:/
# /d/projects/cerbero -> d:/projects/cerbero/
# /home/USERNAME/cerbero -> C:\\MinGW\\msys\\1.0/home/USERNAME/
# /mingw -> C:\\MinGW/
# /mingw/bin/foobar -> C:\\MinGW\\bin/foobar/
# /tmp/baz -> C:\\Users\\USERNAME\\AppData\\Local\\Temp/baz/
msys_dir_to_win32() {
set -e
local msys_path stripped_path mount_point path mounted_path
# If the path is already a native path, just return that
if [[ $1 == ?':/'* ]] || [[ $1 == ?':\\'* ]]; then
echo $1
return
fi
# Convert /c or /mingw etc to /c/ or /mingw/ etc; gives us a necessary
# anchor to split the path into components
msys_path="$1/"
# Strip leading slash
stripped_path="${msys_path#/}"
# Get the first path component, which may be a mount point
mount_point="/${stripped_path%%/*}"
# Get the path inside the mountp oint
path="/${stripped_path#*/}"
mounted_path="$(msysmnt | sed -n "s|\(.*\) on $mount_point type.*|\1|p")"
# If it's not a mounted path (like /c or /tmp or /mingw), then it's in the
# general MSYS root mount
if [[ -z $mounted_path ]]; then
mounted_path="$(msysmnt | sed -n "s|\(.*\) on / type.*|\1|p")"
path="$1"
fi
echo ${mounted_path}${path}
}
get_scriptdir() {
case "$MSYS_VERSION" in
*1) msys_dir_to_win32 "$SCRIPTDIR";;
*2) cygpath -m -C ANSI "$SCRIPTDIR";;
*) echo $SCRIPTDIR;;
esac
}
$PYTHON -c """
import os
import sys
import shlex
os.environ['CERBERO_UNINSTALLED'] = '1'
# __file__ is not set when we're called with -c
if '__file__' in locals():
curdir = os.path.dirname(__file__)
else:
curdir = '`get_scriptdir`'
sys.path.insert(0, os.path.abspath(curdir))
# Need to set sys.argv since we can't pass args when called with -c
if sys.argv == ['-c']:
sys.argv = ['$0'] + shlex.split('$ARGS')
from cerbero.main import main
main()
#"""