#! /bin/sh #----------------------------------------------------------------------------- # /var/install/bin/apache2-config-module-trac-plugin # # Creation: 2007-06-20 hb # Last Update: $Id$ # # Copyright (c) 2007-@@YEAR@@ Holger Bruenjes # # 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. #----------------------------------------------------------------------------- # include eislib . /var/install/include/eislib # include config . /etc/config.d/trac ASK="/var/install/bin/ask" #exec 2> /tmp/trac-plugin-trace$$.log #set -x # set echo line, for allways equal echo_line=" ----------------------------" #-------------------------------------------------------------------------- # select project #-------------------------------------------------------------------------- select_project() { clrhome echo mecho "Please select the project," mecho "to activate/deactivate plugins." echo techo --begin '3 3r 2 32' techo --row "" --info No "" --info Project mecho "${echo_line}" idx=1 while [ "${idx}" -le "${TRAC_PROJ_N}" ] do eval project_name='${TRAC_PROJ_'${idx}'_NAME}' techo --row "" "${idx}" "" "${project_name}" idx=$((${idx} + 1)) done mecho "${echo_line}" techo --end echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "Select" "${select_project}" "1-${TRAC_PROJ_N}" "0=Exit" >${_ask_tmpfile} rc=${?} read select_project < ${_ask_tmpfile} rm -f ${_ask_tmpfile} # if ask break, ask returned 255 if [ ${rc} = 255 ] then select_project=0 fi if [ ${select_project:-0} -eq 0 ] then exit 0 fi # set name from select project eval project_name='${TRAC_PROJ_'${select_project}'_NAME}' # check trac in special folder case ${TRAC_SPEC_FOLDER} in no) # set default path for trac projects trac_path=/var/lib/trac ;; *) # set special path for trac projects trac_path=${TRAC_SPEC_FOLDER}/trac ;; esac select_to_work } #----------------------------------------------------------------------------- # select to work #----------------------------------------------------------------------------- select_to_work () { clrhome # entry:action:message:para action_entry="show installed plugins:show_plugins: add plugin:add_plugins: remove plugin:remove_plugins:" echo mecho "Please select the action," mecho "you will do, for project '${project_name}'" echo techo --begin '3 3r 2 32' techo --row "" --info No "" --info Action mecho "${echo_line}" idx=1 echo "${action_entry}" | while read line #entry action message para do _OLD_IFS=${IFS} IFS=: set -- ${line} _OLD_IFS=${IFS} entry="`echo "${1}" | sed 's/^ *//'`" techo row "" "${idx}" "" "${entry}" idx=$((${idx} + 1)) done mecho "${echo_line}" techo end # get number of action_entry to select the max number entry_lines=$(echo "${action_entry}" | wc -l) echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "Select" "" "1-${entry_lines}" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read action_to_do < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then action_to_do=0 fi case ${action_to_do} in '') select_project ;; 0) exit 0 ;; *) # get action line action_line="`echo "${action_entry}" | sed -n "${action_to_do}p" | sed 's/^ *//'`" _OLD_IFS=${IFS} IFS=: # set action line set -- ${action_line} IFS=${_OLD_IFS} action=${2} message="${3}" para="${4}" # ${2} ${3} ${4} ${action} "${message}" "${para}" ;; esac } #----------------------------------------------------------------------------- # remove plugins #----------------------------------------------------------------------------- remove_plugins() { check_plugins clrhome # write user list to tty mecho mecho "Remove plugins from project '${project_name}'" mecho # show available plugins techo --begin '3 50' techo --row "" --info "Available Plugins" mecho "${echo_line}" idx=1 echo "${available_plugins}" | sed 's/-.*$//' | while read av_plugins do if [ -n "${av_plugins}" ] then techo --row "" "${av_plugins}" else techo --row "" "More plugins not available" fi done mecho "${echo_line}" # techo end mecho # show installed plugins techo --begin '3 3r 2 50' techo --row "" --info No "" --info "Installed Plugins" mecho "${echo_line}" idx=1 echo "${proj_plugins}" | sed 's/-.*$//' | while read pv_plugins do if [ -n "${pv_plugins}" ] then techo --row "" "${idx}" "" "${pv_plugins}" idx=$((${idx} + 1)) else techo --begin '3 50' techo --row "" "Plugins not installed" fi done mecho "${echo_line}" techo --end # get number of action_entry to select the max number entry_lines=$(echo "${proj_plugins}" | wc -l) # print ask line, if ${proj_plugins} emty or not if [ -n "${proj_plugins}" ] then echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "Select" "" "1-${entry_lines}" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read action_to_do < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then action_to_do=0 fi else mecho _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "" "" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read action_to_do < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then action_to_do=0 fi fi # select item case ${action_to_do} in '') select_to_work ;; 0) exit 0 ;; *) # get action line action_line="`echo "${proj_plugins}" | sed -n "${action_to_do}p" | sed 's/^ *//'`" # remove plugin rm -f ${proj_plugins_folder}/${action_line} remove_plugins ;; esac } #----------------------------------------------------------------------------- # add plugins #----------------------------------------------------------------------------- add_plugins() { check_plugins clrhome # write user list to tty mecho mecho "Add plugins to project '${project_name}'" mecho # show available plugins techo --begin '3 3r 2 50' techo --row "" --info No "" --info "Available Plugins" mecho "${echo_line}" idx=1 echo "${available_plugins}" | sed 's/-.*$//' | while read av_plugins do if [ -n "${available_plugins}" ] then techo --row "" "${idx}" "" "${av_plugins}" idx=$((${idx} + 1)) else techo --begin '3 50' techo --row "" "More plugins not available" fi done mecho "${echo_line}" # techo end mecho # show installed plugins techo --begin '3 50' techo --row "" --info "Installed Plugins" mecho "${echo_line}" idx=1 echo "${proj_plugins}" | sed 's/-.*$//' | while read pv_plugins do if [ -n "${pv_plugins}" ] then techo --row "" "${pv_plugins}" else techo --row "" "Plugins not installed" fi done mecho "${echo_line}" techo --end # get number of action_entry to select the max number entry_lines=$(echo "${available_plugins}" | wc -l) # print ask line, if ${available_plugins} emty or not if [ -n "${available_plugins}" ] then echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "Select" "" "1-${entry_lines}" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read action_to_do < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then action_to_do=0 fi else echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "" "" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read action_to_do < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then action_to_do=0 fi fi # select item case ${action_to_do} in '') select_to_work ;; 0) exit 0 ;; *) # get action line action_line="`echo "${available_plugins}" | sed -n "${action_to_do}p" | sed 's/^ *//'`" # remove plugin cp -f ${base_plugins_folder}/${action_line} ${proj_plugins_folder}/ add_plugins ;; esac } #----------------------------------------------------------------------------- # show plugins #----------------------------------------------------------------------------- show_plugins() { check_plugins clrhome # write list to tty mecho mecho "Existing plugins for project '${project_name}'" mecho # show available plugins techo --begin '3 50' techo --row "" --info "Available Plugins" mecho "${echo_line}" echo "${available_plugins}" | sed 's/-.*$//' | while read av_plugins do if [ -n "${av_plugins}" ] then techo --row "" "${av_plugins}" else techo --row "" "More plugins not available" fi done mecho "${echo_line}" #techo end mecho # show installed plugins techo --begin '3 50' techo --row "" --info "Installed Plugins" mecho "${echo_line}" echo "${proj_plugins}" | sed 's/-.*$//' | while read pv_plugins do if [ -n "${pv_plugins}" ] then techo --row "" "${pv_plugins}" else techo --row "" "Plugins not installed" fi done mecho "${echo_line}" techo --end echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "" "" "^$=Return" "0=Exit" >${_ask_tmpfile} rc=${?} read user_line < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then user_line=0 fi case ${user_line} in '') select_to_work ;; 0) exit 0 ;; esac } #----------------------------------------------------------------------------- # check plugins #----------------------------------------------------------------------------- check_plugins() { # set plugins folder base_plugins_folder=/var/lib/trac/plugins proj_plugins_folder=${trac_path}/${project_name}/plugins # check base plugins folder exists if [ ! -d ${base_plugins_folder} ] then echo mecho --info "Plugins not installed" echo anykey exit 1 fi # get plugins form base folder base_plugins=$(ls ${base_plugins_folder} | sort) # get plugins form project folder proj_plugins=$(ls ${proj_plugins_folder} | sort) # check for available plugins if [ -n "${base_plugins}" ] then # if base plugins folder not empty if [ -n "${proj_plugins}" ] then echo "${base_plugins}" | while read plugin do if ! echo "${proj_plugins}" | grep -q "${plugin}" then echo "${plugin}" >> available_plugins # if [ -z "${available_plugins}" ] # then # available_plugins=`echo "${plugin}"` # else # available_plugins=`echo "${available_plugins}"; echo "${plugin}"` # fi fi done available_plugins=$(cat available_plugins) rm -f available_plugins else available_plugins=$(echo "${base_plugins}") fi else # if base plugins folder empty echo mecho --info "Plugins not installed" echo anykey exit 1 fi } #----------------------------------------------------------------------------- # main #----------------------------------------------------------------------------- while true do clrhome if [ ${TRAC_PROJ_N:-0} -eq 0 ] then mecho mecho --info "Error: There are no projects defined on this server!" anykey exit 1 fi select_project echo _ask_tmpfile=$(mktemp -t ask.XXXXXXXXXX) ${ASK} "One more action?" "no" >${_ask_tmpfile} rc=${?} read more_action < ${_ask_tmpfile} rm -f ${_ask_tmpfile} if [ ${rc} = 255 ] then more_action=no fi case ${more_action} in no) exit 0 ;; esac done exit 0 #----------------------------------------------------------------------------- # end #-----------------------------------------------------------------------------