tazwok diff tazwok @ rev 235

Add functionnality: webserver
author Antoine Bodin <gokhlayeh@slitaz.org>
date Thu Feb 10 15:36:26 2011 +0100 (2011-02-10)
parents a618127f3ce2
children ff1479df1f17
line diff
     1.1 --- a/tazwok	Wed Feb 09 23:19:01 2011 +0100
     1.2 +++ b/tazwok	Thu Feb 10 15:36:26 2011 +0100
     1.3 @@ -92,7 +92,18 @@
     1.4  	else
     1.5  		LOCAL_REPOSITORY=$SLITAZ_DIR/$SLITAZ_VERSION
     1.6  	fi
     1.7 -
     1.8 +	
     1.9 +	if ! [ "$save_dir" ]; then
    1.10 +		if [ -f $LOCAL_REPOSITORY/tazwok.conf ] || [ -f $LOCAL_REPOSITORY/slitaz.conf ]; then
    1.11 +			save_dir=$LOCAL_REPOSITORY
    1.12 +			[ -f $LOCAL_REPOSITORY/slitaz.conf ] && source $LOCAL_REPOSITORY/slitaz.conf
    1.13 +			cd $save_dir
    1.14 +			get_tazwok_config
    1.15 +			unset save_dir
    1.16 +			return
    1.17 +		fi
    1.18 +	fi
    1.19 +	
    1.20  	# The path to the most important files/dir used by Tazwok.
    1.21  	PACKAGES_REPOSITORY=$LOCAL_REPOSITORY/packages
    1.22  	WOK=$LOCAL_REPOSITORY/wok
    1.23 @@ -116,7 +127,7 @@
    1.24  		check_dir $INCOMING_REPOSITORY
    1.25  		check_dir $LOCAL_REPOSITORY/log
    1.26  	fi
    1.27 -	
    1.28 +
    1.29  	# Some files are needed by tazwok in PACKAGES_REPOSITORY. Create
    1.30  	# them if they are missing.
    1.31  	for file in broken blocked commit incoming cooklist; do
    1.32 @@ -2750,6 +2761,91 @@
    1.33  			exit 1
    1.34  		fi
    1.35  	;;
    1.36 +	webserver)
    1.37 +		check_root
    1.38 +		get_tazwok_config
    1.39 +		if [ "$ARG" = on ]; then
    1.40 +			if [ "$WEBSERVER" ] && [ -f "$WEBSERVER/repositories.list" ] && \
    1.41 +				grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
    1.42 +				echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
    1.43 +				exit 1
    1.44 +			fi
    1.45 +			if ! [ -f $LOCAL_REPOSITORY/tazchroot.conf ]; then
    1.46 +				tazwok configure-chroot ${undigest:+--undigest=$undigest} --SLITAZ_VERSION=$SLITAZ_VERSION --SLITAZ_DIR=$SLITAZ_DIR
    1.47 +			fi
    1.48 +			for pkg in php lighttpd; do
    1.49 +				[ -d $INSTALLED/$pkg ] || missing="$missing $pkg"
    1.50 +			done
    1.51 +			if [ "$missing" ]; then
    1.52 +				echo "You need to install those packages to start webserver: $missing." >&2
    1.53 +				exit 1
    1.54 +			fi
    1.55 +			if [ ! -f "$LOCAL_REPOSITORY/tazwok.conf" ]; then
    1.56 +				echo "Copying /etc/slitaz/tazwok.conf to $LOCAL_REPOSITORY/tazwok.conf: webserver is configured repository-by-repository."
    1.57 +				cp /etc/slitaz/tazwok.conf $LOCAL_REPOSITORY
    1.58 +			fi
    1.59 +			if ! [ "$WEBSERVER" ]; then
    1.60 +				echo -n "Where to store php pages (default: /var/www/vhosts/bb)? "
    1.61 +				read WEBSERVER
    1.62 +				[ "$WEBSERVER" ] || WEBSERVER="/var/www/vhosts/bb"
    1.63 +			fi
    1.64 +			if [ -f "$WEBSERVER/repositories.list" ] && \
    1.65 +				grep -q ^"${undigest:-$SLITAZ_VERSION}"$ $WEBSERVER/repositories.list; then
    1.66 +				echo "Webserver is already enabled at $WEBSERVER for ${undigest:-$SLITAZ_VERSION}." >&2
    1.67 +				exit 1
    1.68 +			fi
    1.69 +			mkdir -p $WEBSERVER
    1.70 +			echo "${undigest:-$SLITAZ_VERSION}" >> $WEBSERVER/repositories.list
    1.71 +			for file in index.php log.php; do
    1.72 +				[ -f "$WEBSERVER/$file" ] || ln -s /usr/share/slitaz/web-bb/$file $WEBSERVER
    1.73 +			done
    1.74 +			source $LOCAL_REPOSITORY/tazchroot.conf	
    1.75 +			echo "<?php
    1.76 +
    1.77 +// Web interface configuration
    1.78 +
    1.79 +\$version=\"${undigest:-$SLITAZ_VERSION}\";
    1.80 +\$chroot=\"$chroot_dir\";
    1.81 +\$lockfile=\"\$chroot/proc/1\";
    1.82 +\$db_dir=\"$PACKAGES_REPOSITORY\";
    1.83 +\$log_dir=\"$LOCAL_REPOSITORY/log\";
    1.84 +\$packages=\"$PACKAGES_REPOSITORY\";
    1.85 +\$incoming=\"$INCOMING_REPOSITORY\";
    1.86 +
    1.87 +?>" > $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php
    1.88 +			[ -L "$WEBSERVER/web" ] || ln -s /usr/share/slitaz/web $WEBSERVER
    1.89 +			echo "WEBSERVER=\"$WEBSERVER\"" >> $LOCAL_REPOSITORY/tazwok.conf
    1.90 +			if [ -L "$WEBSERVER/conf.php" ]; then
    1.91 +				echo "Do yo want to make ${undigest:-$SLITAZ_VERSION} the default page (y/N) ? "
    1.92 +				read answer
    1.93 +				if [ "$answer" = y ]; then
    1.94 +					rm $WEBSERVER/conf.php
    1.95 +					ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
    1.96 +				fi
    1.97 +			else
    1.98 +				ln -s $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php $WEBSERVER/conf.php
    1.99 +			fi
   1.100 +		elif [ "$ARG" = off ]; then
   1.101 +			if ! [ "$WEBSERVER" ]; then
   1.102 +				echo "No webserver running for ${undigest:-$SLITAZ_VERSION}" >&2
   1.103 +				exit 1
   1.104 +			fi
   1.105 +			sed '/^WEBSERVER/d' -i $LOCAL_REPOSITORY/tazwok.conf
   1.106 +			sed "/^${undigest:-$SLITAZ_VERSION}$/d" -i $WEBSERVER/repositories.list
   1.107 +			rm $WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php	
   1.108 +			if ! [ -s "$WEBSERVER/repositories.list" ]; then
   1.109 +				echo "$WEBSERVER/repositories.list is empty; tazwok doesn't remove the server automatically in case you have important stuff in it. If it's not the case, you can remove it using: rm -r $WEBSERVER"
   1.110 +				rm $WEBSERVER/conf.php	
   1.111 +			elif [ "$(readlink $WEBSERVER/conf.php)" = "$WEBSERVER/conf-${undigest:-$SLITAZ_VERSION}.php" ]; then
   1.112 +				echo "${undigest:-$SLITAZ_VERSION} was the default version to use; switched to : $(sed 1!d $WEBSERVER/repositories.list)"
   1.113 +				rm $WEBSERVER/conf.php
   1.114 +				ln -s $WEBSERVER/conf-$(sed 1!d $WEBSERVER/repositories.list).php $WEBSERVER/conf.php
   1.115 +			fi
   1.116 +		else
   1.117 +			echo "Usage: tazwok webserver on/off" >&2
   1.118 +			exit 1
   1.119 +		fi
   1.120 +	;;
   1.121  	usage|*)
   1.122  		# Print usage also for all unknown commands.
   1.123  		#