-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkcatfilebundle
executable file
·60 lines (54 loc) · 1.31 KB
/
mkcatfilebundle
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
#!/bin/env bash
if [[ -z "${1}" ]]; then
if [[ -z "${PYVERSION}" ]]; then
export PYVER="3"
else
export PYVER="${PYVERSION}"
fi
else
export PYVER="${1}"
fi
#export PYTHONPATH="$(which python${PYVER})"
export PYTHONPATH="$(command -v python${PYVER})"
if [[ -z "${2}" ]]; then
infile="catfile.py"
outfilebin="${infile%.*}"
outfilezip="${infile%.*}.zip"
else
if [[ -f "./${2}" ]]; then
infile="${2}"
outfilebin="${infile%.*}"
outfilezip="${infile%.*}.zip"
else
infile="catfile.py"
outfilebin="${infile%.*}"
outfilezip="${infile%.*}.zip"
fi
fi
if ! [ -x "$(command -v python${PYVER})" ]; then
echo "Error: python${PYVER} is not installed." >&2
exit 1
fi
if [[ -f "./catfile.py" ]]; then
${PYTHONPATH} ./catfile.py "${infile}"
exit 0
fi
mkdir -p -v /tmp/pybundle
cp -r -v ./${infile} /tmp/pybundle/__main__.py
cp -r -v ./pycatfile.py /tmp/pybundle/pycatfile.py
export OLDPATH="$(pwd)"
cd ./bundle/python${PYVER}
rm -rfv *
cd ${OLDPATH}
cd /tmp/pybundle
zip -v ./${outfilezip} -r .
echo '#!/usr/bin/env python'${PYVER} > ./${outfilebin}
echo '' >> ./${outfilebin}
cat ./${outfilezip} >> ./${outfilebin}
chmod -v +x ./${outfilebin}
cd ${OLDPATH}
mv -v /tmp/pybundle/${outfilebin} ./bundle/python${PYVER}/${outfilebin}
rm -rfv /tmp/pybundle
cd ./bundle/python${PYVER}
chmod -v +x ./${outfilebin}
cd ${OLDPATH}