# # 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 . # #-------------------------------------------------------------------------# #!/bin/bash # # # adds settings to this run if requested chkr() { altSrvrName="nanoweb" srvrName="Nanoweb" absPth="$HOME/LazyShare" plugChkr=`which gnome-mplayer` plugChkr2=`ls /etc/${altSrvrName}/${altSrvrName}.conf` plugChkr3=`which php5-cgi` if [[ ${plugChkr} == "" || \ ${plugChkr2} == "" || \ ${plugChkr3} == "" ]]; then 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 "# Installing gecko-mediaplayer..." ; sleep 1 echo -e $PASSWD | sudo apt-get install gecko-mediaplayer -y echo "# Installing "${altSrvrName}"..." ; sleep 1 echo -e $PASSWD | sudo apt-get install "${altSrvrName}" -y echo "# Installing php5-cgi..." ; sleep 1 echo -e $PASSWD | sudo apt-get install php5-cgi -y echo "# Killing "${altSrvrName}"..." ; sleep 1 echo -e $PASSWD | sudo killall $altSrvrName -y echo "# Finished!" ; sleep 1 main; elif [[ "${replyinst}" == "${noInstall}" ]]; then main; fi main; else main; fi } main() { declare -A movies=([.mkv]= [.mp4]= [.mpg]= [.avi]= [.mov]= [.MOV]= [.flv]= [.wmv]= [.ogv]= [.webm]= [.m4v]=) for i in `ls ./`; do fileNm=$(echo "$i" | sed 's/.*\///'); fileExtnsn=$(echo "$i" | sed 's/^.*\././g'); outFile=$(echo ${i%.*}); if [[ "${movies[$fileExtnsn]-X}" == "${movies[$fileExtnsn]}" ]]; then if [ -f "${absPth}"/resources/thumbnails/"${outFile}".jpg ]; then echo "Not a video or already present...." else ffmpegthumbnailer -t="00:10:00" -c jpg -i "${fileNm}" -s 310 -o "${absPth}"/resources/thumbnails/"${outFile}".jpg fi fi done IFS=$'\n' bgs=($(ls -L "${absPth}"/resources/backgrounds/)) numdirs=${#bgs[@]} index=$(( (( RANDOM % $numdirs ) - 2) + 1 )) if [ -f ./000.jpg ]; then bg="
"; else bg="
"; fi echo ' LazyShare '${bg}' Can Not Display Picture
Select a file to upload:
' > ./index.php dirScan } dirScan() { d=`ls -p | grep "/" | sed 's/\/$//'`; for i in $d; do fileNm=$(echo "$i" | 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 '

'${fileNm}'
' >> ./index.php ; else echo '

'${fileNm}'
' >> ./index.php ; fi fi 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]=) for i in `ls ./`; do fileNm=$(echo "$i" | sed 's/.*\///') ; fileExtnsn=$(echo "$i" | sed 's/^.*\././g') ; thbnal=$(echo ${fileNm%.*}); if [[ "${pics[$fileExtnsn]-X}" == "${pics[$fileExtnsn]}" ]]; then echo 'Load Fail' >> ./index.php ; elif [[ "${music[$fileExtnsn]-X}" == "${music[$fileExtnsn]}" ]]; then if [[ ${fileExtnsn} == *".mid"* ]]; then echo '
Play '${fileNm}'
' >> ./index.php ; else echo '
'${fileNm}'
' >> ./index.php ; fi elif [[ "${movies[$fileExtnsn]-X}" == "${movies[$fileExtnsn]}" ]]; then if [ -f "${absPth}"resources/thumbnails/"${thbnal}".jpg ]; then echo '

'${fileNm}'
' >> ./index.php ; else echo '
'${fileNm}'
' >> ./index.php ; fi elif [[ "${docs[$fileExtnsn]-X}" == "${docs[$fileExtnsn]}" ]]; then echo ''${fileNm}'
' >> ./index.php ; elif [[ "${invis[$fileExtnsn]-X}" == "${invis[$fileExtnsn]}" ]]; then echo "File not added to index.php!!" ; fi done echo ' ' >> ./index.php exit } chkr