PirateBoxScripts_Webserver/piratebox/piratebox/bin/install_piratebox.sh

179 lines
6.3 KiB
Bash
Raw Normal View History

2012-04-14 16:22:27 +02:00
#!/bin/sh
2014-01-17 16:47:47 +01:00
## PirateBox installer script
## created by Matthias Strubel (c)2011-2014 GPL-3
2012-04-14 16:22:27 +02:00
##
create_content_folder(){
echo "Creating 'content' folder on USB stick and move over stuff"
mkdir -p $WWW_CONTENT
cp -r $PIRATEBOX_FOLDER/www_content/* $WWW_CONTENT
[ ! -L $PIRATEBOX_FOLDER/www/content ] && \
ln -s $WWW_CONTENT $WWW_FOLDER/content
[ ! -e $WWW_FOLDER/favicon.ico ] && \
ln -s $WWW_CONTENT/favicon.ico $WWW_FOLDER
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $WWW_CONTENT -R
chmod u+rw $WWW_CONTENT
return 0
}
2012-04-14 16:22:27 +02:00
# Load configfile
if [ -z $1 ] || [ -z $2 ]; then
echo "Usage install_piratebox my_config <part>"
echo " Parts: "
echo " part2 : sets Permissions and links correctly"
echo " imageboard : configures kareha imageboard with Basic configuration"
echo " should be installed in <Piratebox-Folder>/share/board"
echo " pyForum : Simple PythonForum"
echo " station_cnt : Adds Statio counter to your Box - crontab entry"
echo " flush_dns_reg : Installs crontask to flush dnsmasq regulary"
echo " hostname 'name' : Exchanges the Hostname displayed in browser"
2012-04-14 16:22:27 +02:00
exit 1
fi
if [ ! -f $1 ] ; then
echo "Config-File $1 not found..."
exit 1
fi
#Load config
PIRATEBOX_CONFIG=$1
2012-04-14 16:22:27 +02:00
. $1
if [ $2 = 'pyForum' ] ; then
cp -v $PIRATEBOX_FOLDER/src/forest.py $WWW_FOLDER/cgi-bin
cp -v $PIRATEBOX_FOLDER/src/forest.css $WWW_FOLDER/content/css
2012-04-14 16:22:27 +02:00
mkdir -p $PIRATEBOX_FOLDER/forumspace
chmod a+rw -R $PIRATEBOX_FOLDER/forumspace 2> /dev/null
2012-04-26 21:40:15 +02:00
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $WWW_FOLDER/cgi-bin/forest.py
2016-11-17 06:54:48 +01:00
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $WWW_FOLDER/content/forest.css 2> /dev/null
2012-04-26 21:40:15 +02:00
echo "Copied the files. Recheck your PirateBox now. "
2012-04-14 16:22:27 +02:00
fi
if [ $2 = 'part2' ] ; then
echo "Starting initialize PirateBox Part2.."
2012-04-14 16:22:27 +02:00
#Create directories
2012-05-13 09:55:03 +02:00
# mkdir -p $PIRATEBOX_FOLDER/share/Shared
mkdir -p $UPLOADFOLDER
2012-04-14 16:22:27 +02:00
mkdir -p $PIRATEBOX_FOLDER/share/board
mkdir -p $PIRATEBOX_FOLDER/share/tmp
mkdir -p $PIRATEBOX_FOLDER/tmp
#Distribute the Directory Listing files
if [ "$CUSTOM_DIRLIST_COPY" = "yes" ] ; then
$PIRATEBOX_FOLDER/bin/distribute_files.sh $SHARE_FOLDER/Shared true
fi
#Set permissions
2012-04-14 16:22:27 +02:00
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $PIRATEBOX_FOLDER/share -R
chmod u+rw $PIRATEBOX_FOLDER/share
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $PIRATEBOX_FOLDER/www -R
chmod u+x $PIRATEBOX_FOLDER/www/cgi-bin/*
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $PIRATEBOX_FOLDER/tmp
chown $LIGHTTPD_USER:$LIGHTTPD_GROUP $PIRATEBOX_FOLDER/tmp -R
#Install a small script, that the link on the main page still works
if [ ! -f $PIRATEBOX_FOLDER/share/board/kareha.pl ] ; then
cp $PIRATEBOX_FOLDER/src/kareha.pl $PIRATEBOX_FOLDER/share/board
fi
2014-06-06 10:51:21 +02:00
[ ! -L $PIRATEBOX_FOLDER/www/board ] && ln -s $PIRATEBOX_FOLDER/share/board $PIRATEBOX_FOLDER/www/board
[ ! -L $PIRATEBOX_FOLDER/www/Shared ] && ln -s $UPLOADFOLDER $PIRATEBOX_FOLDER/www/Shared
[ ! -L $PIRATEBOX_FOLDER/www/content ] && \
ln -s $WWW_CONTENT $WWW_FOLDER/content
2012-04-14 16:22:27 +02:00
fi
#Install the image-board
if [ $2 = 'imageboard' ] ; then
2012-05-03 07:33:13 +02:00
if [ -e $PIRATEBOX_FOLDER/share/board/init_done ] ; then
echo "$PIRATEBOX_FOLDER/share/board/init_done file Found in Kareha folder. Won't reinstall board."
2012-05-03 07:33:13 +02:00
exit 0;
fi
2012-05-02 20:25:52 +02:00
cd $PIRATEBOX_FOLDER/tmp
KAREHA_RELEASE=kareha_3.1.4.zip
if [ ! -e $PIRATEBOX_FOLDER/tmp/$KAREHA_RELEASE ] ; then
echo " Wgetting kareha-zip file "
wget http://wakaba.c3.cx/releases/$KAREHA_RELEASE
if [ "$?" != "0" ] ; then
echo "wget kareha failed.. you can place the current file your to $PIRATEBOX_FOLDER/tmp "
fi
2012-04-14 16:22:27 +02:00
fi
if [ -e $PIRATEBOX_FOLDER/tmp/$KAREHA_RELEASE ] ; then
2012-05-02 20:25:52 +02:00
echo "Kareha Zip found..."
else
echo "No Zip found, abort "
exit 255
fi
unzip $KAREHA_RELEASE
2013-06-07 11:38:10 +02:00
mv kareha/* $PIRATEBOX_FOLDER/share/board
2012-05-03 07:33:13 +02:00
rm -rf $PIRATEBOX_FOLDER/tmp/kareha*
2012-05-02 20:25:52 +02:00
2012-05-03 07:19:23 +02:00
cd $PIRATEBOX_FOLDER/share/board
cp -R mode_image/* ./
cp $PIRATEBOX_FOLDER/src/kareha_img_config.pl $PIRATEBOX_FOLDER/share/board/config.pl
cp $PIRATEBOX_FOLDER/src/no_forum.html $PIRATEBOX_FOLDER/share/board/index.htm
2012-05-03 07:19:23 +02:00
chown -R $LIGHTTPD_USER:$LIGHTTPD_GROUP $PIRATEBOX_FOLDER/share/board
2012-04-14 16:22:27 +02:00
#Install filetype thumbnails
2012-05-03 07:19:23 +02:00
mv $PIRATEBOX_FOLDER/share/board/extras/icons $PIRATEBOX_FOLDER/share/board/
echo "Errors in chown occurs if you are using vfat on the USB stick"
2012-05-03 07:33:13 +02:00
echo " . don't Panic!"
2012-05-03 07:19:23 +02:00
echo "Generating index page"
2013-06-07 11:11:14 +02:00
cd /tmp
wget -q http://127.0.0.1/board/kareha.pl
2012-05-03 07:19:23 +02:00
echo "finished!"
echo "Now Edit your kareha settings file to change your ADMIN_PASS and SECRET : "
2012-06-09 09:39:44 +02:00
echo " # vi $PIRATEBOX_FOLDER/www/board/config.pl "
2012-05-03 07:33:13 +02:00
touch $PIRATEBOX_FOLDER/share/board/init_done
2012-04-14 16:22:27 +02:00
fi
if [ $2 = "station_cnt" ] ; then
2012-06-15 18:14:33 +02:00
#we want to append the crontab, not overwrite
2012-06-15 18:57:03 +02:00
crontab -l > $PIRATEBOX_FOLDER/tmp/crontab 2> /dev/null
2012-06-15 18:14:33 +02:00
echo "#--- Crontab for PirateBox-Station-Cnt" >> $PIRATEBOX_FOLDER/tmp/crontab
echo " */2 * * * * $PIRATEBOX_FOLDER/bin/station_cnt.sh > $WWW_FOLDER/station_cnt.txt " >> $PIRATEBOX_FOLDER/tmp/crontab
crontab $PIRATEBOX_FOLDER/tmp/crontab
[ "$?" != "0" ] && echo "an error occured" && exit 254
2012-06-15 18:57:03 +02:00
$PIRATEBOX_FOLDER/bin/station_cnt.sh > $WWW_FOLDER/station_cnt.txt
echo "installed, now every 2 minutes your station count is refreshed"
fi
if [ $2 = "flush_dns_reg" ] ; then
crontab -l > $PIRATEBOX_FOLDER/tmp/crontab 2> /dev/null
echo "#--- Crontab for dnsmasq flush" >> $PIRATEBOX_FOLDER/tmp/crontab
echo " */2 * * * * $PIRATEBOX_FOLDER/bin/flush_dnsmasq.sh > $PIRATEBOX_FOLDER/tmp/dnsmasq_flush.log " >> $PIRATEBOX_FOLDER/tmp/crontab
crontab $PIRATEBOX_FOLDER/tmp/crontab
[ "$?" != "0" ] && echo "an error occured" && exit 254
echo "Installed crontab for flushing dnsmasq requlary"
fi
set_hostname() {
local name=$1 ; shift;
sed "s|#####HOST#####|$name|g" $PIRATEBOX_FOLDER/src/redirect.html.schema > $WWW_FOLDER/index.html
sed "s|HOST=\"$HOST\"|HOST=\"$name\"|" -i $PIRATEBOX_CONFIG
}
if [ $2 = "hostname" ] ; then
echo "Switching hostname to $3"
set_hostname "$3"
echo "..done"
fi
if [ $2 = "content" ] ; then
create_content_folder
fi