Update pycatfile.py
[PyCatFile.git] / mkcatfilebundle
blob5e3354d88823a666521fce83c73e0f151e4dd232
1 #!/bin/env bash
3 if [[ -z "${1}" ]]; then
4  if [[ -z "${PYVERSION}" ]]; then
5   export PYVER="3"
6  else
7   export PYVER="${PYVERSION}"
8  fi
9 else
10  export PYVER="${1}"
13 #export PYTHONPATH="$(which python${PYVER})"
14 export PYTHONPATH="$(command -v python${PYVER})"
16 if [[ -z "${2}" ]]; then
17  infile="catfile.py"
18  outfilebin="${infile%.*}"
19  outfilezip="${infile%.*}.zip"
20 else
21  if [[ -f "./${2}" ]]; then
22   infile="${2}"
23   outfilebin="${infile%.*}"
24   outfilezip="${infile%.*}.zip"
25  else
26   infile="catfile.py"
27   outfilebin="${infile%.*}"
28   outfilezip="${infile%.*}.zip"
29  fi
32 if ! [ -x "$(command -v python${PYVER})" ]; then
33  echo "Error: python${PYVER} is not installed." >&2
34  exit 1
37 if [[ -f "./catfile.py" ]]; then
38  ${PYTHONPATH} ./catfile.py "${infile}"
39  exit 0
42 mkdir -p -v /tmp/pybundle
43 cp -r -v ./${infile} /tmp/pybundle/__main__.py
44 cp -r -v ./pycatfile.py   /tmp/pybundle/pycatfile.py
45 export OLDPATH="$(pwd)"
46 cd ./bundle/python${PYVER}
47 rm -rfv *
48 cd ${OLDPATH}
49 cd /tmp/pybundle
50 zip -v ./${outfilezip} -r .
51 echo '#!/usr/bin/env python'${PYVER} > ./${outfilebin}
52 echo '' >> ./${outfilebin}
53 cat ./${outfilezip} >> ./${outfilebin}
54 chmod -v +x ./${outfilebin}
55 cd ${OLDPATH}
56 mv -v /tmp/pybundle/${outfilebin} ./bundle/python${PYVER}/${outfilebin}
57 rm -rfv /tmp/pybundle
58 cd ./bundle/python${PYVER}
59 if [[ ${infile} = "mkhockeydata.py" ]]; then
60  ${PYTHONPATH} ./${outfilebin} mksymlinks
62 chmod -v +x ./${outfilebin}
63 cd ${OLDPATH}