189 lines
6.5 KiB
Bash
Executable File
189 lines
6.5 KiB
Bash
Executable File
#!/bin/sh
|
|
## PirateBox installer script
|
|
## created by Matthias Strubel (c)2011-2017 GPL-3
|
|
##
|
|
|
|
PIRATEBOX_CONFIG="/opt/piratebox/conf/piratebox.con"
|
|
|
|
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
|
|
}
|
|
|
|
# Load configfile
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Usage install_piratebox <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"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
if [ ! -f "$PIRATEBOX_CONFIG" ] ; then
|
|
echo "Config-File $PIRATEBOX_CONFIG not found..."
|
|
exit 1
|
|
fi
|
|
|
|
#Load config
|
|
. "$PIRATEBOX_CONFIG"
|
|
|
|
if [ "$1" = 'pyForum' ] ; then
|
|
cp -v "$PIRATEBOX_FOLDER/src/forest.py" "$WWW_FOLDER/cgi-bin"
|
|
cp -v "$PIRATEBOX_FOLDER/src/forest.css" "$WWW_FOLDER/content/css"
|
|
mkdir -p "$PIRATEBOX_FOLDER/forumspace"
|
|
chmod a+rw -R "$PIRATEBOX_FOLDER/forumspace" 2> /dev/null
|
|
chown "$LIGHTTPD_USER":"$LIGHTTPD_GROUP" "$WWW_FOLDER/cgi-bin/forest.py"
|
|
chown "$LIGHTTPD_USER":"$LIGHTTPD_GROUP" "$WWW_FOLDER/content/forest.css"\
|
|
2> /dev/null
|
|
echo "Copied the files. Recheck your PirateBox now. "
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = 'part2' ] ; then
|
|
echo "Starting initialize PirateBox Part2.."
|
|
#Create directories
|
|
mkdir -p "$UPLOADFOLDER"
|
|
mkdir -p "$PIRATEBOX_FOLDER/share/board"
|
|
mkdir -p "$PIRATEBOX_FOLDER/share/tmp"
|
|
mkdir -p "$PIRATEBOX_FOLDER/tmp"
|
|
|
|
#Distribute the Directory Listing files
|
|
"$PIRATEBOX_FOLDER/bin/distribute_files.sh" "$SHARE_FOLDER/Shared" true
|
|
#Set permissions
|
|
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
|
|
|
|
[ ! -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"
|
|
|
|
fi
|
|
|
|
#Install the image-board
|
|
if [ "$1" = 'imageboard' ] ; then
|
|
|
|
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."
|
|
exit 0;
|
|
fi
|
|
|
|
|
|
cd "$PIRATEBOX_FOLDER/tmp" || exit 99
|
|
KAREHA_RELEASE=kareha_3.1.4.zip
|
|
if [ ! -e "$PIRATEBOX_FOLDER/tmp/$KAREHA_RELEASE" ] ; then
|
|
echo " Wgetting kareha-zip file "
|
|
if ! wget "http://wakaba.c3.cx/releases/$KAREHA_RELEASE" ; then
|
|
echo "wget kareha failed.. you can place the current file your to $PIRATEBOX_FOLDER/tmp "
|
|
fi
|
|
fi
|
|
|
|
if [ -e "$PIRATEBOX_FOLDER/tmp/$KAREHA_RELEASE" ] ; then
|
|
echo "Kareha Zip found..."
|
|
else
|
|
echo "No Zip found, abort "
|
|
exit 255
|
|
fi
|
|
|
|
unzip "$KAREHA_RELEASE"
|
|
mv kareha/* "$PIRATEBOX_FOLDER/share/board"
|
|
rm -rf "$PIRATEBOX_FOLDER"/tmp/kareha*
|
|
|
|
cd "$PIRATEBOX_FOLDER/share/board" || exit
|
|
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"
|
|
chown -R "$LIGHTTPD_USER":"$LIGHTTPD_GROUP" "$PIRATEBOX_FOLDER/share/board"
|
|
#Install filetype thumbnails
|
|
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"
|
|
echo " . don't Panic!"
|
|
echo "Generating index page"
|
|
cd /tmp || exit 1
|
|
wget -q http://127.0.0.1/board/kareha.pl
|
|
echo "finished!"
|
|
echo "Now Edit your kareha settings file to change your ADMIN_PASS and SECRET : "
|
|
echo " # vi $PIRATEBOX_FOLDER/www/board/config.pl "
|
|
|
|
touch "$PIRATEBOX_FOLDER/share/board/init_done"
|
|
fi
|
|
|
|
if [ "$1" = "station_cnt" ] ; then
|
|
#we want to append the crontab, not overwrite
|
|
crontab -l > "$PIRATEBOX_FOLDER/tmp/crontab" 2> /dev/null
|
|
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"
|
|
if ! crontab "$PIRATEBOX_FOLDER/tmp/crontab" ; then
|
|
echo "an error occured" && exit 254
|
|
fi
|
|
"$PIRATEBOX_FOLDER/bin/station_cnt.sh" > "$WWW_FOLDER/station_cnt.txt"
|
|
echo "installed, now every 2 minutes your station count is refreshed"
|
|
fi
|
|
|
|
if [ "$1" = "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"
|
|
if crontab "$PIRATEBOX_FOLDER"/tmp/crontab ; then
|
|
echo "Installed crontab for flushing dnsmasq requlary"
|
|
else
|
|
echo "an error occured" && exit 254
|
|
fi
|
|
fi
|
|
|
|
set_hostname() {
|
|
name=$1 ; shift;
|
|
|
|
sed -e "s|#####HOST#####|$name|g" \
|
|
"$PIRATEBOX_FOLDER"/src/redirect.html.schema > \
|
|
"$WWW_FOLDER"/redirect.html
|
|
sed -e "s|HOST=\"$HOST\"|HOST=\"$name\"|" -i "$PIRATEBOX_CONFIG"
|
|
}
|
|
|
|
if [ "$1" = "hostname" ] ; then
|
|
echo "Switching hostname to $2"
|
|
set_hostname "$2"
|
|
echo "..done"
|
|
fi
|
|
|
|
if [ "$1" = "content" ] ; then
|
|
create_content_folder
|
|
fi
|