231 lines
7.6 KiB
Bash
231 lines
7.6 KiB
Bash
|
#
|
||
|
# By Maxim F. Stewart
|
||
|
# Contact: [maximstewart1@gmail.com]
|
||
|
#
|
||
|
# Copyright 2013 Maxim F. Stewart
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 2 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
#
|
||
|
#-------------------------------------------------------------------------#
|
||
|
#!/bin/bash
|
||
|
#
|
||
|
#
|
||
|
# adds settings to this run if requested
|
||
|
|
||
|
chkr()
|
||
|
{
|
||
|
altSrvrName="nanoweb"
|
||
|
srvrName="Nanoweb"
|
||
|
plugChkr=$(ls /usr/bin/gnome-mplayer)
|
||
|
plugChkr2=$(ls /etc/${altSrvrName}/${altSrvrName}.conf)
|
||
|
plugChkr3=$(ls /usr/bin/php5-cgi)
|
||
|
pluginstld=$(echo /usr/bin/gnome-mplayer)
|
||
|
pluginstld2=$(echo /etc/${altSrvrName}/${altSrvrName}.conf)
|
||
|
pluginstld3=$(echo /usr/bin/php5-cgi)
|
||
|
if [[ ${plugChkr} == ${pluginstld} && \
|
||
|
${plugChkr2} == ${pluginstld2} && \
|
||
|
${plugChkr3} == ${pluginstld3} && \
|
||
|
${sttngsChkr} == ${sttngsChkr2} ]]; then
|
||
|
main;
|
||
|
else
|
||
|
Install="Install"
|
||
|
noInstall="Do Not Install"
|
||
|
replyinst=$(zenity --list \
|
||
|
--text "We need to install one or more pre-requsit programs or
|
||
|
settings are missing. The missing program(s) is/are
|
||
|
gecko-mediaplayer, $srvrName, and/or php5-cgi." \
|
||
|
--radiolist --column "Select" \
|
||
|
--column "Options" TRUE "Install" FALSE "Do Not Install" \
|
||
|
--height 220);
|
||
|
if [[ "${replyinst}" == "${Install}" ]]; then
|
||
|
PASSWD="$(zenity --password --title=Authentication)\n"
|
||
|
|
||
|
echo -e $PASSWD | (
|
||
|
echo "# Installing gecko-mediaplayer..." ; sleep 1
|
||
|
sudo apt-get install gecko-mediaplayer -y
|
||
|
|
||
|
echo "25" ; sleep 2
|
||
|
echo "# Installing "${altSrvrName}"..." ; sleep 1
|
||
|
sudo apt-get install "${altSrvrName}" -y
|
||
|
|
||
|
echo "50" ; sleep 2
|
||
|
echo "# Installing php5-cgi..." ; sleep 1
|
||
|
sudo apt-get install php5-cgi -y
|
||
|
|
||
|
echo "75" ; sleep 2
|
||
|
echo "# Killing "${altSrvrName}"..." ; sleep 1
|
||
|
sudo killall $altSrvrName -y
|
||
|
|
||
|
echo "# Finished!" ; sleep 1
|
||
|
echo "100"
|
||
|
) |
|
||
|
zenity --progress \
|
||
|
--title="Plugin install...." \
|
||
|
--text="Prepping..." \
|
||
|
--percentage=0 \
|
||
|
--auto-close \
|
||
|
--auto-kill
|
||
|
main;
|
||
|
elif [[ "${replyinst}" == "${noInstall}" ]]; then
|
||
|
main;
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
main()
|
||
|
{
|
||
|
declare -A movies=([.mkv]= [.mp4]= [.mpg]= [.avi]= [.mov]= [.MOV]= [.flv]= [.wmv]= [.ogv]= [,webm]= [.m4v]=)
|
||
|
ls ./ > ./dirList.txt ;
|
||
|
x=$(cat ./dirList.txt | wc -l) >> /dev/null ;
|
||
|
i="1"
|
||
|
|
||
|
while [ $i -le $x ]; do
|
||
|
line1=$(sed -n "${i}p" ./dirList.txt);
|
||
|
fileNm=$(echo "$line1" | sed 's/.*\///');
|
||
|
fileExtnsn=$(echo "$line1" | sed 's/^.*\././g');
|
||
|
outFile=$(echo ${line1%.*});
|
||
|
|
||
|
if [[ "${movies[$fileExtnsn]-X}" == "${movies[$fileExtnsn]}" ]]; then
|
||
|
if [ -f /home/LazyShare/resources/thumbnails/"${outFile}".jpg ]; then
|
||
|
echo "Not a video or already present...."
|
||
|
else
|
||
|
ffmpegthumbnailer -w -t="00:10:00" -c jpg -i "${fileNm}" -s 310 -o /home/LazyShare/resources/thumbnails/"${outFile}".jpg
|
||
|
fi
|
||
|
fi
|
||
|
i=$[$i++1] ;
|
||
|
done
|
||
|
rm dirList.txt
|
||
|
|
||
|
IFS=$'\n' bgs=($(ls -L /home/LazyShare/resources/backgrounds/))
|
||
|
numdirs=${#bgs[@]}
|
||
|
index=$(( (( RANDOM % $numdirs ) - 2) + 1 ))
|
||
|
|
||
|
if [ -f ./000.jpg ]; then
|
||
|
bg="<div id="\"bg"\"><img src="\"./000.jpg"\"/></div>";
|
||
|
else
|
||
|
bg="<div id="\"bg"\"><img src="\"/resources/backgrounds/${bgs[index]}"\"/></div>";
|
||
|
fi
|
||
|
|
||
|
|
||
|
echo '<!doctype html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>LazyShare</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<link rel="stylesheet" href="/resources/settings-notes/css.css" type="text/css">
|
||
|
<script type="text/javascript" src="http://www.midijs.net/lib/midi.js"></script>
|
||
|
</head>
|
||
|
<body>
|
||
|
'${bg}'
|
||
|
<a href="../">
|
||
|
<img src="/resources/icons/left.png" class="backbutton" alt="Can Not Display Picture" />
|
||
|
</a><br>
|
||
|
<div class="header">
|
||
|
<form action="/resources/settings-notes/upload.php" method="post" enctype="multipart/form-data">
|
||
|
Select a file to upload:
|
||
|
<input type="file" name="fileToUpload" id="fileToUpload"><br>
|
||
|
<input type="submit" value="Upload File" name="submit">
|
||
|
</form>
|
||
|
</div>' > ./index.php
|
||
|
absPth="/home/LazyShare/"
|
||
|
dirScan
|
||
|
}
|
||
|
|
||
|
dirScan()
|
||
|
{
|
||
|
touch /tmp/dirList.txt ;
|
||
|
|
||
|
ls -p | grep "/" > /tmp/dirList.txt ;
|
||
|
sed -i 's/\/$//' /tmp/dirList.txt
|
||
|
|
||
|
d=$(cat /tmp/dirList.txt | wc -l) >> /dev/null ;
|
||
|
i="1"
|
||
|
|
||
|
while [ $i -le $d ]; do
|
||
|
line=$(sed -n "${i}p" /tmp/dirList.txt);
|
||
|
fileNm=$(echo "$line" | sed 's/*\///');
|
||
|
if [[ "${fileNm}" == *"resources"* ]]; then
|
||
|
echo "In root dir; wont add resources as list option..."
|
||
|
else
|
||
|
if [ -f "${absPth}"resources/thumbnails/"${fileNm}".jpg ]; then
|
||
|
echo '
|
||
|
<div class="lnksNdirs"><a href="'${fileNm}'" style="color:#00E8FF;">
|
||
|
<img src="/resources/thumbnails/'${fileNm}'.jpg" /><br>'${fileNm}'</a>
|
||
|
</div>' >> ./index.php ;
|
||
|
else
|
||
|
echo '
|
||
|
<div class="lnksNdirs"><a href="'${fileNm}'" style="color:#00E8FF;">
|
||
|
<img src="/resources/icons/folder.png" /><br>'${fileNm}'</a>
|
||
|
</div>' >> ./index.php ;
|
||
|
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
i=$[$i++1];
|
||
|
done
|
||
|
mainScaner
|
||
|
}
|
||
|
|
||
|
mainScaner()
|
||
|
{
|
||
|
# Associative Arrays set to compare against the file extension
|
||
|
declare -A movies=([.mkv]= [.mp4]= [.mpg]= [.avi]= [.mov]= [.MOV]= [.flv]= [.wmv]= [.ogv]= [.webm]= [.m4v]=)
|
||
|
declare -A music=([.mp2]= [.mp3]= [.ogg]= [.flac]= [.mid]=)
|
||
|
declare -A docs=([.doc]= [.docx]= [.txt]= [.pdf]= [.odt]=)
|
||
|
declare -A pics=([.png]= [.jpg]= [.jpeg]= [.gif]=)
|
||
|
declare -A invis=([.sh]= [index.php]=)
|
||
|
ls ./ > /tmp/list.txt ;
|
||
|
x=$(cat /tmp/list.txt | wc -l) >> /dev/null ;
|
||
|
i="1"
|
||
|
|
||
|
while [ $i -le $x ]; do
|
||
|
line1=$(sed -n "${i}p" /tmp/list.txt) ;
|
||
|
fileNm=$(echo "$line1" | sed 's/.*\///') ;
|
||
|
fileExtnsn=$(echo "$line1" | sed 's/^.*\././g') ;
|
||
|
thbnal=$(echo ${fileNm%.*});
|
||
|
|
||
|
if [[ "${pics[$fileExtnsn]-X}" == "${pics[$fileExtnsn]}" ]]; then
|
||
|
echo '<a href="'${fileNm}'" target="frame"><img src="'${fileNm}'" class="imgsStyl" alt="Load Fail" /></a>' >> ./index.php ;
|
||
|
elif [[ "${music[$fileExtnsn]-X}" == "${music[$fileExtnsn]}" ]]; then
|
||
|
if [[ ${fileExtnsn} == *".mid"* ]]; then
|
||
|
echo '<div class="lnksNdirs">
|
||
|
<a href="#" style="color:#00E8FF;" onClick="MIDIjs.play('\'${fileNm}''\'');">Play '${fileNm}'</a>
|
||
|
</div>' >> ./index.php ;
|
||
|
else
|
||
|
echo '<div class="lnksNdirs">
|
||
|
<a href="'${fileNm}'" target="frame" style="color:#00E8FF;">'${fileNm}'</a></div>' >> ./index.php ;
|
||
|
fi
|
||
|
elif [[ "${movies[$fileExtnsn]-X}" == "${movies[$fileExtnsn]}" ]]; then
|
||
|
if [ -f "${absPth}"resources/thumbnails/"${thbnal}".jpg ]; then
|
||
|
echo '<div class="lnksNdirs">
|
||
|
<a href="'${fileNm}'" target="frame" style="color:#00E8FF;">
|
||
|
<img src="/resources/thumbnails/'${thbnal}'.jpg" /><br>'${fileNm}'</a></div>' >> ./index.php ;
|
||
|
else
|
||
|
echo '<div class="lnksNdirs">
|
||
|
<a href="'${fileNm}'" target="frame" style="color:#00E8FF;">'${fileNm}'</a></div>' >> ./index.php ;
|
||
|
fi
|
||
|
elif [[ "${docs[$fileExtnsn]-X}" == "${docs[$fileExtnsn]}" ]]; then
|
||
|
echo '<a class="lnksNdirs" target="frame" href="'${fileNm}'" style="color:#00E8FF;">'${fileNm}'</a><br>' >> ./index.php ;
|
||
|
elif [[ "${invis[$fileExtnsn]-X}" == "${invis[$fileExtnsn]}" ]]; then
|
||
|
echo "File not added to index.php!!" ;
|
||
|
fi
|
||
|
i=$[$i++1] ;
|
||
|
done
|
||
|
|
||
|
echo '<iframe id="frame" name="frame" frameborder="0" class="iframer"></iframe>
|
||
|
</body>
|
||
|
</html>' >> ./index.php
|
||
|
exit
|
||
|
}
|
||
|
chkr
|