# This file is part of the src2pkg program: # Copyright 2005-2008 Gilbert Ashley # src2pkg is released under the GNU General Public License Version 2 # Each routine that writes lines to the doinst.sh should add a blank line afterwards, but not before ## make_doinst make_doinst() { if [[ "$FAILED" = "" ]] ; then # If a doinst.sh is present, assume that it is final and copy as-is into the PKG_DIR if [[ -e $CWD/doinst.sh ]] ; then echo $BLUE"Found doinst.sh - "$NORMAL"Inserting in the package directory" cat $CWD/doinst.sh > $PKG_DIR/install/doinst.sh elif [[ -e $CWD/doinst.sh.gz ]] ; then echo $BLUE"Found doinst.sh.gz - "$NORMAL"Decompressing in the package directory" zcat $CWD/doinst.sh.gz > $PKG_DIR/install/doinst.sh else if ! [[ $MAKE_LINKS = "NO" ]] ; then make_doinst_links fi if [[ -e $CWD/doinst.prepend ]] ; then echo $BLUE"Found doinst.prepend - "$NORMAL"Starting a new doinst.sh with its' contents" cat $CWD/doinst.prepend > $PKG_DIR/install/doinst.sh echo "" >> $PKG_DIR/install/doinst.sh fi if [[ -e $CWD/doinst.links ]] ; then echo $BLUE"Adding links to doinst.sh - "$NORMAL"Adding links-creation to the doinst.sh" cat $CWD/doinst.links >> $PKG_DIR/install/doinst.sh rm -f $CWD/doinst.links fi # check to see if any files are installed to PKG_DIR/etc if [[ -d $PKG_DIR/etc ]] ; then for conf in $(find $PKG_DIR/etc -type f) ; do [[ "${conf: -4}" = ".new" ]] && continue mv $conf $conf.new done if [[ $(find $PKG_DIR/etc -type f) != "" ]] ; then if [[ $(grep 'config()' $PKG_DIR/install/doinst.sh 2> /dev/null) = "" ]] ; then echo $BLUE"Found conf files - "$NORMAL"Adding '.new' file routine to doinst.sh" echo '' >> $PKG_DIR/install/doinst.sh echo 'config() {' >> $PKG_DIR/install/doinst.sh echo ' NEW="$1"' >> $PKG_DIR/install/doinst.sh echo ' OLD="$(dirname $NEW)/$(basename $NEW .new)"' >> $PKG_DIR/install/doinst.sh echo ' if [ ! -r $OLD ] ; then' >> $PKG_DIR/install/doinst.sh echo ' mv $NEW $OLD' >> $PKG_DIR/install/doinst.sh echo ' echo ""' >> $PKG_DIR/install/doinst.sh echo ' echo " --> Installed new configuration file $OLD"' >> $PKG_DIR/install/doinst.sh echo ' elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ] ; then' >> $PKG_DIR/install/doinst.sh echo ' rm $NEW' >> $PKG_DIR/install/doinst.sh echo ' else' >> $PKG_DIR/install/doinst.sh echo ' echo ""' >> $PKG_DIR/install/doinst.sh echo ' echo " --> Installed new configuration file $NEW"' >> $PKG_DIR/install/doinst.sh echo ' echo " --> Preserving your old configuration file $OLD"' >> $PKG_DIR/install/doinst.sh echo ' echo ""' >> $PKG_DIR/install/doinst.sh echo ' echo " Please examine your existing configuration file: $OLD"' >> $PKG_DIR/install/doinst.sh echo ' echo " to see if it needs to be updated from: $NEW"' >> $PKG_DIR/install/doinst.sh echo ' echo ""' >> $PKG_DIR/install/doinst.sh echo ' fi' >> $PKG_DIR/install/doinst.sh echo '}' >> $PKG_DIR/install/doinst.sh echo '' >> $PKG_DIR/install/doinst.sh cd $PKG_DIR/etc ; for conf in $(find . -type f) ; do conf=${conf:2} echo "config etc/$conf" >> $PKG_DIR/install/doinst.sh done echo '' >> $PKG_DIR/install/doinst.sh fi fi fi if [[ -e $PKG_DIR/etc/rc.d/rc.$NAME.new ]] ; then echo $BLUE"Found rc.d init file - "$NORMAL"Adding rc.local routine to doinst.sh" add_to_rc_local fi # check if we need to add code to handle info pages if [[ -d $PKG_DIR/usr/info ]] && [[ ! $(grep install-info $PKG_DIR/install/doinst.sh &> /dev/null) ]] ; then echo $BLUE"Found info files - "$NORMAL"Adding install-info command to doinst.sh" INFO_LIST=$(ls -1 $PKG_DIR/usr/info) echo "" >> $PKG_DIR/install/doinst.sh echo "if [ -x /usr/bin/install-info ] ; then" >> $PKG_DIR/install/doinst.sh for page in $(echo $INFO_LIST) ; do echo " /usr/bin/install-info --info-dir=/usr/info /usr/info/$page 2>/dev/null" >> $PKG_DIR/install/doinst.sh done echo "fi" >> $PKG_DIR/install/doinst.sh echo "" >> $PKG_DIR/install/doinst.sh fi # check to see if any *.desktop files are installed. if [[ -d $PKG_DIR/usr/share/applications ]] ; then if [[ $(find $PKG_DIR/usr/share/applications -type f) != "" ]] ; then if [[ "$(grep update-desktop-database $PKG_DIR/install/doinst.sh 2> /dev/null)" = "" ]] ; then echo $BLUE"Found .desktop files - "$NORMAL"Adding '.desktop' file routine to doinst.sh" echo '' >> $PKG_DIR/install/doinst.sh echo '# update the applications menu database' >> $PKG_DIR/install/doinst.sh echo 'if [ -x /usr/bin/update-desktop-database ] ; then' >> $PKG_DIR/install/doinst.sh echo ' /usr/bin/update-desktop-database /usr/share/applications >/dev/null' >> $PKG_DIR/install/doinst.sh echo 'fi' >> $PKG_DIR/install/doinst.sh echo '' >> $PKG_DIR/install/doinst.sh fi fi fi # add the code from doinst.append, if present if [[ -e $CWD/doinst.append ]] ; then echo $BLUE"Found doinst.append - "$NORMAL"Adding its' contents to doinst.sh" cat $CWD/doinst.append >> $PKG_DIR/install/doinst.sh echo "" >> $PKG_DIR/install/doinst.sh fi # if not running trackinstall or src2pkg without auto-scripting enabled copy the new doinst.sh into the CWD if [[ "$EXEC_NAME" = "trackinstall" ]] && [[ ! $AUTO_SCRIPT ]] ; then true elif [ -e $PKG_DIR/install/doinst.sh ] ; then echo $BLUE"Copying new doinst.sh - "$NORMAL"Copying as new.doinst.sh into the current directory" echo "Be sure to check it. For permanent use, edit and/or rename to doinst.sh" cat $PKG_DIR/install/doinst.sh > $CWD/new.doinst.sh fi fi # Remove symbolic links if ! [[ $REMOVE_LINKS = "NO" ]] ; then cd $PKG_DIR ; if [[ $(find . -type l) != "" ]] ; then echo $BLUE"Deleting symbolic links - "$NORMAL"Removing links from the package directory" find . -type l -exec rm -f {} \; fi fi # this will overwrite any slack_required file which was generated by make_description if [[ -f $CWD/$PKG_REQUIRED ]] && [[ ! -f $PKG_DIR/install/$PKG_REQUIRED ]] ; then cat $CWD/$PKG_REQUIRED > $PKG_DIR/install/$PKG_REQUIRED fi if [[ $SHOW_DEPS ]] ; then cd $PKG_DIR ; if [[ "$(find . | xargs file | grep ELF | cut -f 1 -d : | xargs ldd 2> /dev/null | white_out | cut -f1 -d' ')" != "" ]] ; then echo $BLUE"Package dependencies:"$NORMAL find . | xargs file | grep ELF | cut -f 1 -d : | xargs ldd | white_out | cut -f1 -d' ' |grep -v "./" |sort -u fi fi fi } # make_link_script make_install_script() { COUNT=1 LINE="$(sed -n "$COUNT p" $1)" while [ ! "$LINE" = "" ]; do LINKGOESIN="$(echo "$LINE" | cut -f 1 -d " ")" LINKGOESIN="$(dirname $LINKGOESIN)" LINKNAMEIS="$(echo "$LINE" | cut -f 1 -d ' ')" LINKNAMEIS="$(basename "$LINKNAMEIS")" LINKPOINTSTO="$(echo "$LINE" | cut -f 3 -d ' ')" echo "( cd $LINKGOESIN ; rm -rf $LINKNAMEIS )" echo "( cd $LINKGOESIN ; ln -sf $LINKPOINTSTO $LINKNAMEIS )" COUNT=$(expr $COUNT + 1) LINE="$(sed -n "$COUNT p" $1)" done } #search for links and make link creation script if necessary make_doinst_links() { cd $PKG_DIR ; TMP=/tmp echo -n $BLUE"Searching for links in PKG_DIR - "$NORMAL INST=$(mktemp $TMP/src2pkg.XXXXXX) # This requires the ls from coreutils-5.0 (or newer): find . -type l -exec ls -l --time-style=long-iso {} \; | white_out | cut -f 8- -d ' ' | cut -b3- | tee $INST 1> /dev/null if [ ! "$(cat $INST)" = "" ]; then echo $GREEN"Done"$NORMAL make_install_script $INST | tee $CWD/doinst.links 1> /dev/null else echo "None found" fi rm -f $INST } # Add a routine to etc/rc.d/rc.local for an init script in etc/rc.d # really tricky syntax with escapes, double and single quotes # since this function writes a script which writes a script... add_to_rc_local() { if [[ ! $(grep rc.local $PKG_DIR/install/doinst.sh &> /dev/nul) ]] && \ [[ ! $(grep rc.local $CWD/doinst.append &> /dev/null) ]] ; then #echo "" >> $PKG_DIR/install/doinst.sh echo "if [ \"\$(grep rc.$NAME /etc/rc.d/rc.local |grep -v '^#')\" = \"\" ] ; then" >> $PKG_DIR/install/doinst.sh #echo ' echo ""' >> $PKG_DIR/install/doinst.sh echo " echo \" --> Adding an entry to /etc/rc.d/rc.local for /etc/rc.d/rc.$NAME\"" >> $PKG_DIR/install/doinst.sh echo " echo \"\"" >> $PKG_DIR/install/doinst.sh #echo " echo \"\" >> /etc/rc.d/rc.local" >> $PKG_DIR/install/doinst.sh echo " echo \"# Start $NAME service\" >> /etc/rc.d/rc.local" >> $PKG_DIR/install/doinst.sh echo " echo \"if [ -x /etc/rc.d/rc.$NAME ] ; then\" >> /etc/rc.d/rc.local" >> $PKG_DIR/install/doinst.sh echo " echo \" . /etc/rc.d/rc.$NAME start\" >> /etc/rc.d/rc.local" >> $PKG_DIR/install/doinst.sh echo " echo \"fi\" >> /etc/rc.d/rc.local" >> $PKG_DIR/install/doinst.sh echo " echo \"\" >> /etc/rc.d/rc.local" >> $PKG_DIR/install/doinst.sh echo "fi" >> $PKG_DIR/install/doinst.sh echo "" >> $PKG_DIR/install/doinst.sh fi }