forked from KenT2/tboplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·177 lines (155 loc) · 5.59 KB
/
setup.sh
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
TBOPLAYER_PATH=$HOME/tboplayer
SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BIN_PATH=$HOME/bin
DESKTOP_PATH=$HOME/Desktop
FAKE_BIN=$BIN_PATH/tboplayer
SUPPORTED_TYPES=('application/ogg' 'video/ogg' 'audio/ogg'
'video/mpeg' 'audio/mpeg' 'video/mp4' 'audio/x-aac'
'video/3gp' 'video/3gpp2' 'video/quicktime' 'video/x-f4v'
'video/flv' 'audio/x-wav' 'video/x-msvideo')
DESKTOP_ENTRIES=($DESKTOP_PATH/tboplayer.desktop
/usr/share/applications/tboplayer.desktop)
MIMEAPPS_FILE=$HOME/.config/mimeapps.list
MIMEAPPS_FILE_SECTION='Added Associations'
# uninstall TBOPlayer
if [ "$1" == "uninstall" ]; then
echo ""
echo "Do you really wish to uninstall TBOPlayer? [Y/N]"
read answer
if [ "$answer" == "Y" ] || [ "$answer" == "y" ]; then
echo ""
echo "* Removing TBOPlayer..."
rm -Rf $TBOPLAYER_PATH
rm -f $FAKE_BIN
rm -f "${DESKTOP_ENTRIES[0]}"
sudo rm -f "${DESKTOP_ENTRIES[1]}"
for TYPE in "${SUPPORTED_TYPES[@]}"; do
crudini --del "$MIMEAPPS_FILE" "$MIMEAPPS_FILE_SECTION" $TYPE >/dev/null 2>&1
done
echo ""
echo "Would you like to remove all of TBOPlayer dependencies too? [Y/N]"
read answer
if [ "$answer" == "Y" ] || [ "$answer" == "y" ]; then
echo ""
echo "* Removing TBOPlayer dependencies..."
yes | pip uninstall pexpect ptyprocess >/dev/null 2>&1
sudo apt-get -y remove python-gobject-2 python-gtk2 python-requests crudini >/dev/null 2>&1
sudo rm -f /usr/local/bin/youtube-dl >/dev/null 2>&1
fi
echo ""
echo "TBOPlayer has been uninstalled."
fi
exit
fi
# install TBOPlayer
$TBOPLAYER_PATH >/dev/null 2>&1
if [ $? -eq 126 ] && [ "$TBOPLAYER_PATH" != "$SCRIPT_PATH" ]; then
rm -Rf $TBOPLAYER_PATH
fi
echo ""
echo "Installing TBOPlayer and its dependencies..."
echo ""
mv $SCRIPT_PATH $TBOPLAYER_PATH
if [ $? -eq 1 ] && [ "$TBOPLAYER_PATH" != "$SCRIPT_PATH" ]; then
echo ""
echo "Installation failed. :("
echo "Please, move this folder to "$HOME" and then run this setup script (setup.sh) again."
exit
fi
$BIN_PATH >/dev/null 2>&1
if [ $? -eq 127 ]; then
mkdir $BIN_PATH
fi
$DESKTOP_PATH >/dev/null 2>&1
if [ $? -eq 127 ]; then
mkdir $DESKTOP_PATH
fi
echo "* Updating distro packages database... This may take some seconds."
sudo apt-get update >/dev/null 2>&1
command -v omxplayer >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "* Installing omxplayer..."
sudo apt-get install -y omxplayer >/dev/null 2>&1
else
echo "* Updating omxplayer..."
sudo apt-get -y --only-upgrade install omxplayer >/dev/null 2>&1
fi
toaptinstall=""
function addToAptInstall {
local command=$1
local package=$2
local python=$3
if [ $python ]; then
python -c "import "$command >/dev/null 2>&1
local cmdres=$?
else
command -v $command >/dev/null 2>&1
local cmdres=$?
fi
if [ $cmdres -eq 1 ]; then
toaptinstall+=$package" "
fi
}
addToAptInstall "requests" "python-requests" true
addToAptInstall "gobject" "python-gobject-2" true
addToAptInstall "gtk" "python-gtk2" true
addToAptInstall "avconv" "libav-tools" false
addToAptInstall "pip" "python-pip" false
addToAptInstall "crudini" "crudini" false
echo "* Installing dependencies: "$toaptinstall
sudo apt-get -y install $toaptinstall 2>&1 >/dev/null
python -c 'import pexpect' >/dev/null 2>&1
PEXPECT_INSTALLED=$?
python -c 'import ptyprocess' >/dev/null 2>&1
PTYPROCESS_INSTALLED=$?
if [ $PEXPECT_INSTALLED -eq 1 ]; then
echo "* Installing pexpect..."
[[ $PTYPROCESS_INSTALLED -eq 1 ]] && ptyprocess='ptyprocess' || ptyprocess=''
yes | pip install --user pexpect $ptyprocess >/dev/null 2>&1
fi
# install youtube-dl it's if not installed
command -v youtube-dl >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "* Installing youtube-dl..."
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O /usr/local/bin/youtube-dl >/dev/null 2>&1
sudo chmod a+rx /usr/local/bin/youtube-dl
else
echo "* Updating youtube-dl..."
sudo youtube-dl -U >/dev/null 2>&1
fi
# install fake tboplayer executable in /home/<user>/bin
command -v tboplayer >/dev/null 2>&1
if [ $? -eq 1 ]; then
echo "* Creating tboplayer's bash executable..."
echo '#!/bin/bash' >> $FAKE_BIN
echo 'python '$TBOPLAYER_PATH'/tboplayer.py' >> $FAKE_BIN
chmod +x $FAKE_BIN
fi
# install tboplayer 'shortcut' in /home/<user>/Desktop
echo "* Creating shortcuts and configuring links..."
DESKTOP_ENTRY="${DESKTOP_ENTRIES[0]}"
$DESKTOP_ENTRY >/dev/null 2>&1
if [ $? -eq 127 ]; then
echo '[Desktop Entry]' >> $DESKTOP_ENTRY
echo 'Name=TBOPlayer' >> $DESKTOP_ENTRY
echo 'Comment=GUI for omxplayer' >> $DESKTOP_ENTRY
echo 'Exec=python '$TBOPLAYER_PATH'/tboplayer.py %F' >> $DESKTOP_ENTRY
echo 'Icon=/usr/share/pixmaps/python.xpm' >> $DESKTOP_ENTRY
echo 'Terminal=false' >> $DESKTOP_ENTRY
echo 'Type=Application' >> $DESKTOP_ENTRY
echo 'Categories=Application;Multimedia;Audio;AudioVideo' >> $DESKTOP_ENTRY
fi
sudo cp $DESKTOP_ENTRY "${DESKTOP_ENTRIES[1]}"
for TYPE in "${SUPPORTED_TYPES[@]}"; do
crudini --set "$MIMEAPPS_FILE" "$MIMEAPPS_FILE_SECTION" $TYPE 'tboplayer.desktop'
done
echo ""
echo "Installation finished."
echo ""
echo "If all went as expected, TBOPlayer is now installed in your system."
echo "To run it, type 'tboplayer', use the shortcut created on your Desktop, or open a file directly by double clicking on it, or using the right-click menu, when using your file manager."
echo "Oh, just keep the tboplayer folder in your "$HOME" directory, alright?"
echo ""
echo "Good bye! ;)"
exit