11#! /bin/bash
2- help (){
3- echo " Usage: $0 [2/3/-u]
4-
2+ function help(){
3+ if [[ $( uname -s) = " Darwin" ]] || [[ $( uname -s) = " darwin" ]]; then
4+ echo " Usage: $0 [2/3/-u]"
5+ else
6+ echo " Usage: $0 [2/3/-u/--user]"
7+ fi
8+ echo "
59Available options:
6- 2 build using python v. 2.x
7- 3 build using python v. 3.x
8- -u uninstall pyradio
10+ 2 build using python v. 2.x
11+ 3 build using python v. 3.x
12+ -u uninstall pyradio
13+ --user user install (in ~/.local)
914
1015If no option is used, will build using system default
1116
@@ -22,14 +27,73 @@ Checking python availability:"
2227 echo
2328}
2429
25- uninstall (){
26- sudo rm -f ` which pyradio` 2> /dev/null
27- if [ -d /usr/share/doc/pyradio ]; then
28- sudo rm -rf /usr/share/doc/pyradio 2> /dev/null
29- else
30- sudo rm -rf /usr/local/share/doc/pyradio 2> /dev/null
31- fi
32- sudo rm -f /usr/share/man/man1/pyradio.1.gz 2> /dev/null || sudo rm -f /usr/local/share/man/man1/pyradio.1.gz 2> /dev/null
30+ function find_paths(){
31+ local APATH
32+ # Fix for MacOs Catalina python 3
33+ if [[ $( uname -s) = " Darwin" ]] || [[ $( uname -s) = " darwin" ]]; then
34+ echo /usr/local/lib
35+ fi
36+ python devel/site.py 2> /dev/null
37+ python2 devel/site.py 2> /dev/null
38+ python3 devel/site.py 2> /dev/null
39+ APATH=$( python -m site --user-site 2> /dev/null) && echo " $APATH "
40+ APATH=$( python2 -m site --user-site 2> /dev/null) && echo " $APATH "
41+ APATH=$( python3 -m site --user-site 2> /dev/null) && echo " $APATH "
42+ }
43+
44+ function remove_paths(){
45+ echo " Looking for python installed files..."
46+ find_paths | sort -u > /tmp/pyradio-uninstall.$$
47+ while read line; do
48+ [ -d " $line " ] && {
49+ sudo find " $line " -type d -name " pyradio*egg" >> /tmp/pyradio-delete.$$
50+ }
51+ done < /tmp/pyradio-uninstall.$$
52+ while read line; do
53+ [ -d " $line " ] && {
54+ echo -n " ** Removing \" $( basename $line ) \" ... "
55+ sudo rm -rf " $line "
56+ echo done
57+ }
58+ done < /tmp/pyradio-delete.$$
59+ rm -f /tmp/pyradio-uninstall.$$ /tmp/pyradio-delete.$$ 2> /dev/null
60+ }
61+
62+ function uninstall(){
63+ local user
64+ user=$( which pyradio 2> /dev/null) || {
65+ echo " PyRadio is not installed..."
66+ exit
67+ }
68+ sudo echo ' Uninstalling PyRadio'
69+ user=$( which pyradio | grep ' \.local' )
70+ [ -z " $user " ] && {
71+ echo -n ' ** Removing executable ... '
72+ sudo rm -f ` which pyradio` 2> /dev/null
73+ if [ -d /usr/share/doc/pyradio ]; then
74+ sudo rm -rf /usr/share/doc/pyradio 2> /dev/null
75+ else
76+ sudo rm -rf /usr/local/share/doc/pyradio 2> /dev/null
77+ fi
78+ echo done
79+ echo -n ' ** Removing help files ... '
80+ sudo rm -f /usr/share/man/man1/pyradio.1.gz 2> /dev/null || sudo rm -f /usr/local/share/man/man1/pyradio.1.gz 2> /dev/null
81+ echo done
82+ } || {
83+ echo -n ' ** Removing executable ... '
84+ rm -f ` which pyradio` 2> /dev/null
85+ echo done
86+ echo -n ' ** Removing help files ... '
87+ if [ -d ~ /.local/share/doc/pyradio ]; then
88+ rm -rf ~ /.local/share/doc/pyradio 2> /dev/null
89+ else
90+ rm -rf ~ /.local/local/share/doc/pyradio 2> /dev/null
91+ fi
92+ rm -f ~ /.local/share/man/man1/pyradio.1.gz 2> /dev/null
93+ echo done
94+ }
95+ # set -x
96+ remove_paths
3397 echo " PyRadio successfully uninstalled"
3498}
3599
45109 uninstall
46110 exit
47111 ;;
112+ --user)
113+ TO_USER=1
114+ if [[ $( uname -s) = " Darwin" ]] || [[ $( uname -s) = " darwin" ]]; then
115+ echo " Parameter --user not supported on this OS"
116+ exit 1
117+ fi
118+ shift
119+ ;;
48120 2)
49121 TO_PYTHON=2
50122 shift
@@ -88,8 +160,13 @@ for prog in git sed ;do
88160done
89161
90162# delete any files that were left from previous attempt
91- sudo find . -iname " *.pyc" -delete 2> /dev/null
92- sudo find . -iname " *.egg" -delete 2> /dev/null
163+ [ -z " $TO_USER " ] && {
164+ sudo find . -iname " *.pyc" -delete 2> /dev/null
165+ sudo find . -iname " *.egg" -delete 2> /dev/null
166+ } || {
167+ find . -iname " *.pyc" -delete 2> /dev/null
168+ find . -iname " *.egg" -delete 2> /dev/null
169+ }
93170
94171# add git repo info to project
95172descr=$( git describe --long --tags 2> /dev/null || echo not_from_git)
@@ -109,28 +186,56 @@ rm sed.$$ 2>/dev/null
109186
110187# build and install project
111188python" ${TO_PYTHON} " setup.py build && {
112- echo " ***** installing..."
113- sudo python" ${TO_PYTHON} " setup.py install && {
114- gzip -k pyradio.1
115- sudo mv -f pyradio.1.gz /usr/share/man/man1 2> /dev/null || sudo mv -f pyradio.1.gz /usr/local/share/man/man1
116- DOC=/usr/share/doc/pyradio
117- sudo mkdir " $DOC " 2> /dev/null
118- if [ ! -d " $DOC " ]; then
119- # Mac OS SIP protects /usr
120- DOC=/usr/local/share/doc/pyradio
121- mkdir " $DOC "
122- fi
123- for n in README.* build.*
124- do
125- sudo cp " $n " " $DOC "
126- done
127- # copy LICENCE
128- if [ " $DOC " = " /usr/share/doc/pyradio" ]; then
129- sudo mkdir -p /usr/share/licenses/pyradio 2> /dev/null
130- sudo cp LICENCE /usr/share/licenses/pyradio
131- else
132- sudo cp LICENCE " $DOC "
133- fi
189+ [ -z " $TO_USER " ] && {
190+ echo " ***** installing..."
191+ sudo python" ${TO_PYTHON} " setup.py install | tee installed && {
192+ gzip -k pyradio.1
193+ sudo mv -f pyradio.1.gz /usr/share/man/man1 2> /dev/null || sudo mv -f pyradio.1.gz /usr/local/share/man/man1
194+ DOC=/usr/share/doc/pyradio
195+ sudo mkdir " $DOC " 2> /dev/null
196+ if [ ! -d " $DOC " ]; then
197+ # Mac OS SIP protects /usr
198+ DOC=/usr/local/share/doc/pyradio
199+ mkdir " $DOC "
200+ fi
201+ for n in README.* build.*
202+ do
203+ sudo cp " $n " " $DOC "
204+ done
205+ # copy LICENCE
206+ if [ " $DOC " = " /usr/share/doc/pyradio" ]; then
207+ sudo mkdir -p /usr/share/licenses/pyradio 2> /dev/null
208+ sudo cp LICENCE /usr/share/licenses/pyradio
209+ else
210+ sudo cp LICENCE " $DOC "
211+ fi
212+ }
213+ } || {
214+ echo " ***** installing for user..."
215+ python" ${TO_PYTHON} " setup.py install --user | tee installed && {
216+ gzip -k pyradio.1
217+ mkdir -p ~ /.local/share/man/man1 2> /dev/null
218+ mv -f pyradio.1.gz ~ /.local/share/man/man1 2> /dev/null || mv -f pyradio.1.gz ~ /.local/local/share/man/man1
219+ DOC=~ /.local/share/doc/pyradio
220+ mkdir -p " $DOC " 2> /dev/null
221+ if [ ! -d " $DOC " ]; then
222+ # Mac OS SIP protects /usr
223+ DOC=~ /.local/local/share/doc/pyradio
224+ mkdir " $DOC "
225+ fi
226+ for n in README.* build.*
227+ do
228+ cp " $n " " $DOC "
229+ done
230+ # copy LICENCE
231+ mkdir -p ~ /.local/share/licenses 2> /dev/null
232+ if [ " $DOC " = " ~/.local/share/doc/pyradio" ]; then
233+ mkdir -p ~ /.local/share/licenses/pyradio 2> /dev/null
234+ cp LICENCE ~ /.local/share/licenses/pyradio
235+ else
236+ cp LICENCE " $DOC "
237+ fi
238+ }
134239 }
135240}
136241
@@ -142,3 +247,4 @@ python"${TO_PYTHON}" setup.py build && {
142247 # git checkout pyradio/radio.py
143248}
144249rm sed.$$ 2> /dev/null
250+
0 commit comments