CVS: brutus/elaine/lunar+versions/functions README, NONE,
1.1 build.lunar, NONE, 1.1 check.lunar, NONE, 1.1 config.lunar,
NONE, 1.1 connect.lunar, NONE, 1.1 depends.lunar, NONE,
1.1 download.lunar, NONE, 1.1 edit.lunar, NONE, 1.1 init.lunar,
NONE, 1.1 install.lunar, NONE, 1.1 locking.lunar, NONE,
1.1 main.lunar, NONE, 1.1 messages.lunar, NONE, 1.1 misc.lunar,
NONE, 1.1 modules.lunar, NONE, 1.1 moonbase.lunar, NONE,
1.1 optimize.lunar, NONE, 1.1 postbuild.lunar, NONE,
1.1 prune.lunar, NONE, 1.1 queue.lunar, NONE,
1.1 recovery.lunar, NONE, 1.1 sizes.lunar, NONE,
1.1 sources.lunar, NONE, 1.1 temp.lunar, NONE,
1.1 tracking.lunar, NONE, 1.1 uniqid.lunar, NONE,
1.1 updatelog.lunar, NONE, 1.1 useradd.lunar, NONE,
1.1 view.lunar, NONE, 1.1
elaine at lunar-linux.org
elaine at lunar-linux.org
Fri Sep 5 01:15:10 GMT 2003
Update of /var/cvs/lunar/brutus/elaine/lunar+versions/functions
In directory dbguin.lunar-linux.org:/tmp/cvs-serv29650/lunar+versions/functions
Added Files:
README build.lunar check.lunar config.lunar connect.lunar
depends.lunar download.lunar edit.lunar init.lunar
install.lunar locking.lunar main.lunar messages.lunar
misc.lunar modules.lunar moonbase.lunar optimize.lunar
postbuild.lunar prune.lunar queue.lunar recovery.lunar
sizes.lunar sources.lunar temp.lunar tracking.lunar
uniqid.lunar updatelog.lunar useradd.lunar view.lunar
Log Message:
theedge hacked to allow per-module versioning -- still very alpha
--- NEW FILE: README ---
There are some functions in this directory. These functions are called
by subroutines. This place is defined in /etc/lunar/config, via
FUNCTIONS variable.
--- NEW FILE: build.lunar ---
#!/bin/bash
# #
# subroutines - Lunar subroutines #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
save_libraries() {
debug_msg "save_libraries ($@)"
[ "$MODULE" == "glibc" ] && return 0
OLD_VERSION=`installed_version $MODULE`
OLD_LOG=$INSTALL_LOGS/$MODULE-$OLD_VERSION
[ -e "$OLD_LOG" ] || return 0
OLD_LIBS=$SOURCE_DIRECTORY/old.libraries
mkdir -p $OLD_LIBS
SAVED=$OLD_LIBS/$MODULE.saved.libraries
rm -rf $SAVED
grep "/lib/" $OLD_LOG |
while read LINE; do
if [ -f "$LINE" ] &&
file -bL $LINE |
grep -q "shared object"
then
verbose_msg "saving library \"$LINE\""
if [ -h $LINE ]; then
DEST=$( basename $( ls -la "$LINE" |
cut -d '>' -f2 |
cut -c 2-
)
)
ln -sf $DEST $OLD_LIBS/`basename $LINE`
else
cp $LINE $OLD_LIBS
fi
echo $OLD_LIBS/`basename $LINE` >> $SAVED
fi
done
ldconfig $OLD_LIBS
if [ -z "$LD_LIBRARY_PATH" ]
then export LD_LIBRARY_PATH="$OLD_LIBS"
else export LD_LIBRARY_PATH="$OLD_LIBS:$LD_LIBRARY_PATH"
fi
}
release_saved_libraries() {
debug_msg "release_saved_libraries ($@)"
OLD_LIBS=$SOURCE_DIRECTORY/old.libraries
SAVED=$OLD_LIBS/$MODULE.saved.libraries
[ -f $SAVED ] &&
cat $SAVED |
while read FILE; do
verbose_msg "releasing library \"$FILE\""
rm -f "$FILE"
done
ldconfig $OLD_LIBS
}
prepare_install() {
debug_msg "prepare_install ($@)"
if module_installed $MODULE || module_held $MODULE ; then
message "${MESSAGE_COLOR}Preparing to install" \
"${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
while boost_locked; do
sleep 5
done
echo $$ > $BOOST_LOCK
save_libraries
verbose_msg "calling \"lrm --keepconfig --nosustain $MODULE\""
lrm --keepconfig --nosustain $MODULE
true
fi
}
rm_source_dir() {
debug_msg "rm_source_dir ($@)"
[ "$KEEP_SOURCE" == "on" ] && return 0
cd $BUILD_DIRECTORY
DEAD_DIR=$1
DEAD_DIR=${DEAD_DIR:=$SOURCE_DIRECTORY}
verbose_msg "destroying building dir \"$DEAD_DIR\""
if [ "$TMPFS" != "off" ]; then
umount $DEAD_DIR 2> /dev/null
rmdir $DEAD_DIR 2> /dev/null
else
rm -rf $DEAD_DIR 2> /dev/null
fi
rm -f $BOOST_LOCK
}
mk_source_dir() {
debug_msg "mk_source_dir ($@)"
cd $BUILD_DIRECTORY
NEW_DIR=$1
NEW_DIR=${NEW_DIR:=$SOURCE_DIRECTORY}
verbose_msg "creating building dir \"$NEW_DIR\""
if [ "$TMPFS" != "off" ]; then
umount $NEW_DIR 2>/dev/null
rmdir $NEW_DIR 2>/dev/null
mkdir -p $NEW_DIR &&
mount -o size=1g,nr_inodes=1m -t tmpfs tmpfs $NEW_DIR
else
rm -rf $NEW_DIR 2>/dev/null
mkdir -p $NEW_DIR
fi
}
validate_source_dir() {
debug_msg "validate_source_dir ($@)"
verbose_msg "validating \"$SOURCE_DIRECTORY\""
if [ -n "$SOURCE_DIRECTORY" ] &&
[ "$SOURCE_DIRECTORY" != "$BUILD_DIRECTORY" ] &&
echo "$SOURCE_DIRECTORY" | grep -q "$BUILD_DIRECTORY"
then
true
else
message "\$SOURCE_DIRECTORY and \$BUILD_DIRECTORY must not be the same."
message "\$SOURCE_DIRECTORY must not be empty."
message "\$SOURCE_DIRECTORY must be a subdirectory of \$BUILD_DIRECTORY"
false
fi
}
default_pre_build() {
debug_msg "default_pre_build ($@)"
verbose_msg "running \"default_pre_build\""
validate_source_dir $SOURCE_DIRECTORY
if [[ -d $SOURCE_DIRECTORY ]] &&
[[ $KEEP_SOURCE == "on" ]]; then
cd $SOURCE_DIRECTORY &&
make clean
else
mk_source_dir $SOURCE_DIRECTORY &&
unpack $SOURCE
fi
}
default_config() {
debug_msg "default_config ($@)"
verbose_msg "running \"default_config\""
verbose_msg "CFLAGS=\"$CFLAGS\"" &&
verbose_msg "OPTS=\"$OPTS\"" &&
verbose_msg "./configure --build=$BUILD --prefix=/usr --sysconfdir=/etc --localstatedir=/var --infodir=/usr/share/info --mandir=/usr/share/man $OPTS"
./configure --build=$BUILD \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--infodir=/usr/share/info \
--mandir=/usr/share/man \
$OPTS
} > $C_FIFO 2>&1
default_cvs_config() {
debug_msg "default_cvs_config ($@)"
verbose_msg "running \"default_cvs_config\""
verbose_msg "CFLAGS=\"$CFLAGS\"" &&
verbose_msg "OPTS=\"$OPTS\"" &&
verbose_msg "./autogen.sh --build=$BUILD --prefix=/usr --sysconfdir=/etc --localstatedir=/var --infodir=/usr/share/info --mandir=/usr/share/man $OPTS"
./autogen.sh --build=$BUILD \
--prefix=/usr \
--sysconfdir=/etc \
--localstatedir=/var \
--infodir=/usr/share/info \
--mandir=/usr/share/man \
$OPTS
} > $C_FIFO 2>&1
default_make() {
debug_msg "default_make ($@)"
verbose_msg "running \"default_make\""
make &&
prepare_install &&
make install
} > $C_FIFO 2>&1
default_build() {
debug_msg "default_build ($@)"
verbose_msg "running \"default_build\""
default_config &&
default_make
} > $C_FIFO 2>&1
default_cvs_build() {
debug_msg "default_cvs_build ($@)"
verbose_msg "running \"default_cvs_build\""
default_cvs_config &&
default_make
} > $C_FIFO 2>&1
default_post_build() {
debug_msg "default_post_build ($@)"
{
gather_docs
install_pam_confs
install_services
install_xinetd_confs
install_bashmisc
} | tee -a $C_LOG
install_initd
devoke_installwatch
ldconfig
release_saved_libraries
cd /
}
# function : remove_module
# usage : remove_module; but $MODULE must be defined earlier
# purpose : removed a module from the MODULE_STATUS files, no source removal
remove_module() {
debug_msg "remove_module ($@)"
verbose_msg "updating lunar state files after module removal"
lock_file $MODULE_STATUS &&
lock_file $MODULE_STATUS_BACKUP &&
grep -v "^$1:" $MODULE_STATUS_BACKUP > $MODULE_STATUS 2>/dev/null
cat $MODULE_STATUS > $MODULE_STATUS_BACKUP 2>/dev/null
unlock_file $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS
if [ -n "$EXILE" ] ; then
lock_file $MODULE_STATUS &&
lock_file $MODULE_STATUS_BACKUP &&
echo "$1::exiled:0.0" >> $MODULE_STATUS &&
cat $MODULE_STATUS > $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS
lock_file $DEPENDS_STATUS &&
lock_file $DEPENDS_STATUS_BACKUP &&
grep -v ":$1:" $DEPENDS_STATUS_BACKUP > $DEPENDS_STATUS &&
cat $DEPENDS_STATUS > $DEPENDS_STATUS_BACKUP &&
unlock_file $DEPENDS_STATUS &&
unlock_file $DEPENDS_STATUS_BACKUP
fi
}
# function: add_module
# usage : add_module <module_name>
# purpose : adds the 1st parameter as the module name to the MODULE_STATUS files
add_module() {
debug_msg "add_module ($@)"
verbose_msg "updating lunar state files after module installation"
lock_file $MODULE_STATUS &&
lock_file $MODULE_STATUS_BACKUP &&
grep -v "^$1:" $MODULE_STATUS_BACKUP > $MODULE_STATUS 2>/dev/null &&
echo "$1:`date -u +%Y%m%d`:$2:$3:$4" >> $MODULE_STATUS &&
cat $MODULE_STATUS > $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS_BACKUP &&
unlock_file $MODULE_STATUS
}
push_install_queue() {
debug_msg "push_install_queue ($@)"
remove_queue $REMOVE_QUEUE "$1"
remove_queue $INSTALL_QUEUE "$1"
! module_installed "$1" &&
add_queue $INSTALL_QUEUE "$1"
}
push_remove_queue() {
debug_msg "push_remove_queue ($@)"
remove_queue $INSTALL_QUEUE "$1"
remove_queue $REMOVE_QUEUE "$1"
module_installed "$1" &&
add_queue $REMOVE_QUEUE "$1"
}
# function : sort_install_queue
# usage : sort_install_queue
# purpose : sorts the install queue according to the dependencies
sort_install_queue() {
debug_msg "sort_install_queue ($@)"
for MODULE in $@; do
QUEUE="$QUEUE $MODULE"
show_fancy_progress "Processing: $MODULE"
for DEP in $(find_depends $MODULE) ; do
if $(echo "$@" | grep -qw "$DEP") ; then
QUEUE="$DEP $QUEUE"
fi
done
done
echo $QUEUE | tsort
}
# function : purge_modules
# usage : purge_modules
# purpose : purge modules that were removed from moonbase
purge_modules() {
debug_msg "purge_modules ($@)"
verbose_msg "Discovering modules that were removed from moonbase"
for MODULE in $(list_installed | grep -v "^moonbase$") ; do
(
if ! run_details $MODULE &> /dev/null ; then
message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} was removed from ${FILE_COLOR}${MOONBASE}${DEFAULT_COLOR}"
if query "Do you want to remove ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${QUERY_COLOR} ?" y ; then
lrm $MODULE
continue
else
message "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} is kept and can be removed manually later${DEFAULT_COLOR}"
fi
fi
)
done
}
# function : list_expired_modules
# usage : list_expired_modules
# purpose : return a list of modules that need to be updated
list_expired_modules() {
debug_msg "list_expired_modules ($@)"
for LINE in $(cat $MODULE_STATUS | grep -v "^moonbase" | sort) ; do
(
MODULE=$(echo "$LINE" | cut -d: -f1)
IDATE=$(echo "$LINE" | cut -d: -f2)
STATUS=$(echo "$LINE" | cut -d: -f3)
IVERSION=$(echo "$LINE" | cut -d: -f4)
if run_details $MODULE &> /dev/null ; then
if [ "$STATUS" == "installed" ] ; then
if [ "$VERSION" != "$IVERSION" ] || [ -z "$IDATE" ] ||
(( "$UPDATED" > "$IDATE" )) ; then
if [ "$MODULE" != "lunar" ] && [ "$MODULE" != "theedge" ] ; then
echo $MODULE
fi
fi
fi
fi
)
done
}
# function : sort_by_dependency
# usage : LIST=$(sort_by_dependency $LIST)
# purpose : return a LIST sorted by dependency
sort_by_dependency() {
debug_msg "sort_by_dependency ($@)"
LIST=$@
for MODULE in $LIST ; do
unset DEPS
for DEP in $(find_depends $MODULE) ; do
if $(echo $LIST | grep -qw $DEP) ; then
DEPS="$DEPS $DEP"
fi
done
TMP_LIST="$TMP_LIST $DEPS $MODULE"
done
for MODULE in $TMP_LIST ; do
if ! $(echo $QUEUE | grep -qw $MODULE) ; then
QUEUE="$QUEUE $MODULE"
fi
done
echo $QUEUE
}
# function : update_modules
# usage : update_modules
# purpose : update all installed modules that need to be updated
update_modules() {
debug_msg "update_modules ($@)"
export IFS="$STANDARD_IFS"
verbose_msg "Searching for modules to update"
LIST=$(list_expired_modules)
if [ -z "$LIST" ] ; then
verbose_msg "Nothing to update!"
return
fi
verbose_msg "Sorting update queue"
QUEUE=$(sort_by_dependency $LIST)
message "${MESSAGE_COLOR}The following modules will be updated:${DEFAULT_COLOR}"
TMP_QUEUE=$(temp_create "update-queue")
for MODULE in $QUEUE ; do
echo $MODULE >> $TMP_QUEUE
echo $MODULE
done
unset MODULE
if query "Do you wish to edit the update queue ? " n ; then
edit_file $TMP_QUEUE
fi
QUEUE=$(cat $TMP_QUEUE)
temp_destroy $TMP_QUEUE
if [ -n "$QUEUE" ] ; then
lin -c $QUEUE
fi
}
log_list() {
debug_msg "log_list ($@)"
echo `cat $MODULE_STATUS_BACKUP | \
cut -d : -f1,4 --output-delimiter="-"`
}
clean_logs() {
debug_msg "clean_logs ($@)"
LOGS=`log_list`
for FILE in `ls $INSTALL_LOGS`; do
if ! echo -e "$LOGS" | grep -q $FILE; then
message "Removing stale log : $INSTALL_LOGS/$FILE"
rm $INSTALL_LOGS/$FILE
fi
done
for FILE in `ls $COMPILE_LOGS | sed "s/\.bz2//"`; do
if ! echo -e "$LOGS" | grep -q $FILE; then
message "Removing stale log : $COMPILE_LOGS/$FILE.bz2"
rm $COMPILE_LOGS/$FILE.bz2
fi
done
for FILE in `ls $MD5SUM_LOGS`; do
if ! echo -e "$LOGS" | grep -q $FILE; then
message "Removing stale log : $MD5SUM_LOGS/$FILE"
rm $MD5SUM_LOGS/$FILE
fi
done
}
activity_log() {
debug_msg "activity_log ($@)"
DATE=`date -u +%Y%m%d-%T`
COMMAND=$1
MODULE=$2
VERSION=$3
OUTCOME=$4
INFO=$5
lock_file $ACTIVITY_LOG &&
echo "$DATE $COMMAND $MODULE $VERSION $OUTCOME $INFO" >> $ACTIVITY_LOG &&
unlock_file $ACTIVITY_LOG
}
syms_not_owned() {
debug_msg "syms_not_owned ($@)"
cat $1 |
while read ITEM ; do
if [ -h "$ITEM" ] &&
[ -f "$ITEM" ]; then
DEST=$( basename $( ls -la "$ITEM" |
cut -d '>' -f2 |
cut -c 2-
)
)
if ! grep -q "$DEST" "$1"
then echo -n "$ITEM\|"
echo "$ITEM" >> /tmp/$MODULE.rejected.symlinks
fi
fi
done
}
find_pam_aware() {
debug_msg "find_pam_aware ($@)"
cat $MODULE_STATUS_BACKUP |
while read LINE; do
MODULE="`echo $LINE | cut -d : -f1`"
STATUS="`echo $LINE | cut -d : -f3`"
if [ "$STATUS" == "installed" ] ||
[ "$STATUS" == "held" ]; then
SECTION=`find_section $MODULE`
if [ -d "$MOONBASE/$SECTION/$MODULE/pam.d" ] &&
[ "$MODULE" != "Linux-PAM" ]
then echo $MODULE
fi
fi
done
}
--- NEW FILE: check.lunar ---
#!/bin/bash
# #
# check/lunar - checking functions #
# #
############################################################
# cast is part of the sorcery spell management utility #
# Copyright 2001 by Kyle Sallee #
############################################################
# #
# this WAS the cast script of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Parts Copyrighted Jason Johnston 2002 under GPLv2 #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
ldd_check() {
debug_msg "ldd_check ($@)"
if [ "$LDD_CHECK" == "off" ] ; then
return
fi
MODULE=$1
VERSION=`installed_version $MODULE`
I_LOG=$INSTALL_LOGS/$MODULE-$VERSION
LDD_STATUS=0
if [ -e "$I_LOG" ]; then
IFS_OLD="$IFS"
export IFS="
"
LOG=`cat $I_LOG |
grep "/bin/\|/games/\|/lib/\|/sbin/" |
grep -v "/doc/\|/fonts/\|/include/\|/locale/\|/man/\|/modules/\|/var/"`
for FILE in $LOG; do
if [ -f "$FILE" ] &&
[ ! -h "$FILE" ] &&
file -b "$FILE" |
grep -q "ELF" &&
ldd "$FILE" 2>&1 |
grep -q "not found"
then
( export IFS="$IFS_OLD"
message "${FILE_COLOR}${FILE}" \
"${DEFAULT_COLOR}of" \
"${MODULE_COLOR}${MODULE}" \
"${PROBLEM_COLOR}is broken." \
"${DEFAULT_COLOR}"
ldd "$FILE" 2>&1 | grep "not found"
)
LDD_STATUS=1
fi
done
fi
return $LDD_STATUS
}
find_check() {
debug_msg "find_check ($@)"
if [ "$FIND_CHECK" == "off" ] ||
[ "$1" == "xfree86" ] ||
[ "$1" == "xfree86-custom" ]; then
return
fi
MODULE=$1
VERSION=`installed_version $MODULE`
I_LOG=$INSTALL_LOGS/$MODULE-$VERSION
FIND_STATUS=0
if [ -e "$I_LOG" ]; then
IFS_OLD="$IFS"
export IFS="
"
LOG=`cat $I_LOG |
grep "/bin/\|/games/\|/include/\|/lib/\|/sbin/" |
grep -v "/doc/\|/etc/\|/fonts/\|/man/\|/var/"`
for ITEM in $LOG ; do
if [ -e "$ITEM" ]; then
true
else
( export IFS="$IFS_OLD"
message "${FILE_COLOR}${ITEM}" \
"${DEFAULT_COLOR}of" \
"${MODULE_COLOR}${MODULE}" \
"${PROBLEM_COLOR}is missing." \
"${DEFAULT_COLOR}"
)
FIND_STATUS=1
fi
done
else
( export IFS="$IFS_OLD"
message "${MODULE_COLOR}${MODULE} " \
"${PROBLEM_COLOR}is missing an install log." \
"${DEFAULT_COLOR}"
)
FIND_STATUS=1
fi
return $FIND_STATUS
}
sym_check() {
debug_msg "sym_check ($@)"
if [ "$SYM_CHECK" == "off" ]; then
return
fi
MODULE=$1
VERSION=`installed_version $MODULE`
I_LOG=$INSTALL_LOGS/$MODULE-$VERSION
if [ -e "$I_LOG" ]; then
IFS_OLD="$IFS"
export IFS="
"
LOG=`cat $I_LOG`
for ITEM in $LOG ; do
if [ -h "$ITEM" ] &&
[ -f "$ITEM" ]
then
TARGET=$( basename $( ls -la "$ITEM" |
cut -d '>' -f2 |
cut -c 2-
)
)
if ! grep -q "$TARGET" $I_LOG
then ( export IFS="$IFS_OLD"; remove_line )
fi
fi
done
fi
}
md5sum_check() {
debug_msg "md5sum_check ($@)"
if [ "$MD5SUM_CHECK" == "off" ]; then
return
fi
MODULE=$1
VERSION=`installed_version $MODULE`
MD5_LOG="$MD5SUM_LOGS/$MODULE-$VERSION"
MD5SUM_STATUS=0
if [ -e "$MD5_LOG" ]; then
IFS_OLD="$IFS"
export IFS="
"
OUTPUT=`cat $MD5_LOG |
grep "/bin/\|/games/\|/include/\|/lib/\|/sbin/" |
grep -v "/doc/\|/etc/\|/fonts/\|/man/\|/var/" |
md5sum --check 2>/dev/null |
grep -v ": OK" |
cut -d : -f1`
if [ -n "$OUTPUT" ]; then
for FILE in $OUTPUT; do
if [ -f "$FILE" ] &&
[ ! -h "$FILE" ] &&
file -b "$FILE" |
egrep -q "executable|shared object|current ar archive"
then
MD5SUM=`md5sum $FILE`
if ! grep -q "$MD5SUM" $MD5SUM_LOGS/*; then
( export IFS="$IFS_OLD"
message "${FILE_COLOR}${FILE}" \
"${DEFAULT_COLOR}of" \
"${MODULE_COLOR}${MODULE}" \
"${PROBLEM_COLOR}has wrong md5sum." \
"${DEFAULT_COLOR}"
)
MD5SUM_STATUS=1
fi
fi
done
fi
else
( export IFS="$IFS_OLD"
message "${MODULE_COLOR}${MODULE} " \
"${PROBLEM_COLOR}is missing a md5sum log." \
"${DEFAULT_COLOR}"
)
MD5SUM_STATUS=1
fi
return $MD5SUM_STATUS
}
run_checks() {
debug_msg "run_checks ($@)"
sym_check $1
find_check $1 &&
ldd_check $1 &&
md5sum_check $1
}
# rework_module : check depends database for a module
rework_module() {
debug_msg "rework_module ($@)"
# we declare these local to override the systems default ones:
optional_depends() {
debug_msg " optional_depends ($@)"
if module_exiled $1
then add_depends "$MODULE" "$1" "off" "optional" "$2" "$3"
else
if module_installed $1 ||
module_held $1
then add_depends "$MODULE" "$1" "on" "optional" "$2" "$3"
else add_depends "$MODULE" "$1" "off" "optional" "$2" "$3"
fi
fi
}
depends() {
debug_msg " depends ($@)"
if ! module_installed $1 &&
! module_held $1
then
if ! is_depends $1 &&
module_exiled $1
then return 1
else
echo -e "${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}${MESSAGE_COLOR} is missing ${MODULE_COLOR}$1${DEFAULT_COLOR}"
CHANGED_MODULES="$CHANGED_MODULES $1"
fi
fi
add_depends "$MODULE" "$1" "on" "required" "$2" "$3"
}
run_depends() {
debug_msg " run_depends ($@)"
if [ -s "$SCRIPT_DIRECTORY/DEPENDS" ] ; then
show_fancy_progress "Processing: $MODULE"
run_module_file $MODULE DEPENDS
fi
}
# here starts the real work:
MODULE=$1
MOD_SNAME=$(echo $MODULE | sed 's:/:.:g')
# base vars needed to execute DEPENDS
SECTION=$(find_section $MODULE)
SCRIPT_DIRECTORY=$MOONBASE/$SECTION/$MODULE
MODULE_CONFIG=$DEPENDS_CONFIG/$MOD_SNAME
# reroute depends output to our private files:
OLD_DEPENDS_STATUS=$DEPENDS_STATUS
OLD_DEPENDS_STATUS_BACKUP=$DEPENDS_STATUS_BACKUP
DEPENDS_STATUS=$TMP/depends
DEPENDS_STATUS_BACKUP=$TMP/depends.backup
touch $DEPENDS_STATUS
touch $DEPENDS_STATUS_BACKUP
# fetch old depend data:
grep "^$MODULE:" $OLD_DEPENDS_STATUS | sort | uniq > $TMP/depends.old.$MODULE
# fetch new depend data:
run_depends
grep "^$MODULE:" $DEPENDS_STATUS | sort | uniq > $TMP/depends.new.$MODULE
if $(! diff -q $TMP/depends.old.$MODULE $TMP/depends.new.$MODULE &> /dev/null
) ; then
echo -e "${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} has changed depends:${DEFAULT_COLOR}"
CHANGED_MODULES="$CHANGED_MODULES $MODULE"
LIST=$(cat $TMP/depends.old.$MODULE $TMP/depends.new.$MODULE | cut -d: -f2 | sort | uniq )
for DEP in $LIST; do
OLDDEP=$(grep ":$DEP:" $TMP/depends.old.$MODULE)
NEWDEP=$(grep ":$DEP:" $TMP/depends.new.$MODULE)
if [ "$OLDDEP" != "$NEWDEP" ] ; then
# diff style output for debugging:
# echo "- $OLDDEP"
# echo "+ $NEWDEP"
# the tricky part is deciding what is necessary and what not:
OLD_STATUS=$(echo $OLDDEP | cut -d: -f3)
NEW_STATUS=$(echo $NEWDEP | cut -d: -f3)
OLD_REQD=$(echo $OLDDEP | cut -d: -f4)
NEW_REQD=$(echo $NEWDEP | cut -d: -f4)
OLD_ON_OPTS=$(echo $OLDDEP | cut -d: -f5)
NEW_ON_OPTS=$(echo $NEWDEP | cut -d: -f5)
OLD_OFF_OPTS=$(echo $OLDDEP | cut -d: -f6)
NEW_OFF_OPTS=$(echo $NEWDEP | cut -d: -f6)
if [ -z "$NEWDEP" ] ; then
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was removed from the dependency list${DEFAULT_COLOR}"
else
if [ -z "$OLDDEP" ] ; then
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was added to the $NEW_REQD dependency list${DEFAULT_COLOR}"
else
# the dep changed!
if [ "$OLD_STATUS" == "on" -a "$NEW_STATUS" == "on" ]; then
if [ "$OLD_REQD" == "required" -a "$NEW_REQD" == "optional" ]
then
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to optional${DEFAULT_COLOR}"
elif [ "$OLD_REQD" == "optional" -a "$NEW_REQD" == "required" ]
then
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to required${DEFAULT_COLOR}"
else
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} has new compile flags for ${MODULE_COLOR}$DEP${MESSAGE_COLOR}${DEFAULT_COLOR}"
fi
elif [ "$OLD_STATUS" == "off" -a "$NEW_STATUS" == "off" ]; then
if [ "$OLD_REQD" == "required" -a "$NEW_REQD" == "optional" ]
then
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to optional${DEFAULT_COLOR}"
elif [ "$OLD_REQD" == "optional" -a "$NEW_REQD" == "required" ]
then
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was changed to required${DEFAULT_COLOR}"
else
echo -e "${MESSAGE_COLOR}* ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${MESSAGE_COLOR} has new compile flags for ${MODULE_COLOR}$DEP${MESSAGE_COLOR}${DEFAULT_COLOR}"
fi
elif [ "$OLD_STATUS" == "off" -a "$NEW_STATUS" == "on" ]; then
echo -e "${MESSAGE_COLOR}* $NEW_REQD ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was installed${DEFAULT_COLOR}"
elif [ "$OLD_STATUS" == "on" -a "$NEW_STATUS" == "off" ]; then
echo -e "${MESSAGE_COLOR}* $NEW_REQD ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} was removed${DEFAULT_COLOR}"
else
echo -e "${$MESSAGE_COLOR}* ${MODULE_COLOR}$DEP${DEFAULT_COLOR}${MESSAGE_COLOR} ${PROBLEM_COLOR}missed exception $OLD_STATUS $NEW_STATUS${DEFAULT_COLOR}"
fi
fi
fi
fi
done
fi
# clean up
rm -f $DEPENDS_STATUS
rm -f $DEPENDS_STATUS_BACKUP
DEPENDS_STATUS=$OLD_DEPENDS_STATUS
DEPENDS_STATUS_BACKUP=$OLD_DEPENDS_STATUS_BACKUP
}
# rework_list : rework a list of modules and save output
rework_list() {
debug_msg "rework_list ($@)"
for MODULE in $* ; do
module_exiled $MODULE || rework_module $MODULE
done
}
# fix_depends : single pass to fix depends database
fix_depends () {
debug_msg "fix_depends ($@)"
TMP=/tmp/lunar.fix
[ -d $TMP ] || mkdir -p $TMP
CHANGED_MODULES=
# we NEED this
if [ -f "$INSTALL_QUEUE" ] ; then
rm -f $INSTALL_QUEUE
touch $INSTALL_QUEUE
fi
if [ -n "$1" ] ; then
rework_list $*
else
rework_list $(cat $MODULE_STATUS | cut -d: -f1 | sort )
fi
if [ -n "$CHANGED_MODULES" ] ; then
for MODULE in $CHANGED_MODULES ; do
if [ ! -e "$TMP/depends.new.$MODULE" ] ; then
rework_module $MODULE
fi
done
# this ensures the bastard doesn't recheck it:
if [ -z "$NOFIX" ] ; then
mv $DEPENDS_STATUS $TMP/depends
cp $TMP/depends $TMP/depends.filter
for MODULE in $CHANGED_MODULES ; do
grep -v "^$MODULE:" $TMP/depends.filter > $TMP/depends.filter~
mv $TMP/depends.filter~ $TMP/depends.filter
done
mv $TMP/depends.filter $DEPENDS_STATUS
cat $TMP/depends.new.* >> $DEPENDS_STATUS
cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
fi
for MODULE in $CHANGED_MODULES ; do
# special case: when called with --fixdepends, skip recompile!
cp $TMP/depends $TMP/depends.filter
for MODULE in $CHANGED_MODULES ; do
grep -v "^$MODULE:" $TMP/depends.filter > $TMP/depends.filter~
mv $TMP/depends.filter~ $TMP/depends.filter
done
mv $TMP/depends.filter $DEPENDS_STATUS
cat $TMP/depends.new.* >> $DEPENDS_STATUS
cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
done
fi
rm -rf $TMP
}
run_fix() {
debug_msg "run_fix ($@)"
MODULES=$*
if [ -z "$MODULES" ] ; then
MODULES=$(cat $MODULE_STATUS_BACKUP | cut -d: -f1 | sort)
fi
PASSED=":"
verbose_msg "Saving LD_LIBRARY_PATH=\"$LD_LIBRARY_PATH\""
[ -n "$EXPORT_LD_PATH" ] ||
export EXPORT_LD_PATH=$(find /usr/lib -type d ! -empty)
if [ "$LDD_CHECK" == "on" ] ; then
LD_LIBRARY_PATH_OLD="$LD_LIBRARY_PATH"
export_ld $EXPORT_LD_PATH
fi
until [ "$FIXED" == "yes" ] ||
[ "$HOPELESS" == "yes" ]; do
FIXED="yes"
HOPELESS="no"
for MODULE in $MODULES; do
fix_depends $MODULE
# if we were called with --fixdepends then we may skip the rest
if [ -n "$FIXDEPENDS" ] ; then
continue
fi
if module_installed $MODULE &&
[ "$MODULE" != "lunar" ] &&
[ "$MODULE" != "j2sdk" ] &&
module_held $MODULE &&
! echo $PASSED | grep -q ":$MODULE:"; then
if run_checks $MODULE ||
[ -n "$NOFIX" ]
then
PASSED="$PASSED$MODULE:"
else
FIXED="no"
(
run_details $MODULE &&
satisfy_depends &&
unset FIX &&
satisfy_depends
)
if [ "$LDD_CHECK" == "on" ] ; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH_OLD"
export_ld $EXPORT_LD_PATH
fi
if run_checks $MODULE ||
[ -n "$NOFIX" ]
then
PASSED="$PASSED$MODULE:"
if [ "$LDD_CHECK" == "on" ] ; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH_OLD"
export_ld $EXPORT_LD_PATH
fi
else
unset FIX
if ! lin --compile $MODULE; then HOPELESS="yes"
elif ! run_checks $MODULE; then HOPELESS="yes"
fi
export FIX="--fix"
fi
fi
fi
done
done
rm -f /tmp/LD_LIBRARY_PATH_FILE
}
--- NEW FILE: config.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/config #
# includes write_config function #
# #
# 20020713 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function: write_config
# usage : write_config <line to remove> [<line to add>]
# purpose : removes a line from the $LOCAL_CONFIG and adds another (if given)
function write_config() {
[ -z "$1" ] && return 1
TMP_LOCAL_CONFIG="/tmp/lunar.localconfig.$$"
rm -f $TMP_LOCAL_CONFIG 2>/dev/null
LOCAL_CONFIG_BACKUP="/tmp/lunar.localconfigbackup.$$"
rm -f $LOCAL_CONFIG_BACKUP 2>/dev/null
function handle_trap()
{
cp $LOCAL_CONFIG_BACKUP $LOCAL_CONFIG 2>/dev/null
unlock_file $LOCAL_CONFIG
rm -f $TMP_LOCAL_CONFIG 2>/dev/null
rm -f $LOCAL_CONFIG_BACKUP 2>/dev/null
exit 1
}
[ -f "$LOCAL_CONFIG" ] || {
touch $LOCAL_CONFIG &&
chmod 644 $LOCAL_CONFIG &&
chown 0:0 $LOCAL_CONFIG
}
cp $LOCAL_CONFIG $LOCAL_CONFIG_BACKUP 2>/dev/null || return 1
trap "handle_trap" INT QUIT TERM
lock_file $LOCAL_CONFIG
grep -v $1 $LOCAL_CONFIG 2>/dev/null > $TMP_LOCAL_CONFIG
cat $TMP_LOCAL_CONFIG 2>/dev/null > $LOCAL_CONFIG || return 1
[ -n "$2" ] && {
echo $2 >> $LOCAL_CONFIG || return 1
}
unlock_file $LOCAL_CONFIG
rm -f $TMP_LOCAL_CONFIG 2>/dev/null
rm -f $LOCAL_CONFIG_BACKUP 2>/dev/null
trap INT QUIT TERM
}
--- NEW FILE: connect.lunar ---
#!/bin/bash
############################################################
# #
# download.lunar - get sources from the net #
# #
############################################################
# leach is part of the sorcery spell management utility #
# Copyright 2001 by Kyle Sallee #
############################################################
# #
# this WAS the leach script of a source based Linux distro,#
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
# This secondly was lget mostly, and has been moved into #
# a separate lunar functions file handling all the generic #
# downloading functionality for lunar #
# #
############################################################
# #
# Parts Copyrighted Jason Johnston 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
# Parts Copyrighted Auke Kok 2002 under GPLv2 #
# #
############################################################
connect() {
debug_msg "connect ($@)"
if ! ifconfig | grep -q "^eth" &&
! ifconfig | grep -q "^wlan" &&
! ifconfig | grep -q "^ppp" &&
! ifconfig | grep -q "^tun"; then
pon
# Timeout in deciseconds to wait for Interface to come up.
TIMEOUT=30
until ifconfig | grep -q eth ||
ifconfig | grep -q ppp ||
[ $TIMEOUT == 0 ]
do
sleep 10
(( TIMEOUT-- ))
done
disconnect
fi
}
disconnect() {
debug_msg "disconnect ($@)"
if ps -C disconnect > /dev/null
then return
fi
rm -f /tmp/disconnect
cat << EOF > /tmp/disconnect
#!/bin/sh
while ps -A | grep -q "lget"; do sleep 120; done
poff
rm -f /tmp/disconnect
EOF
chmod a+x /tmp/disconnect
/tmp/disconnect &
}
--- NEW FILE: depends.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/depends #
# includes find_depends is_depends in_depends #
# remove_depends add_depends run_depends #
# rework_module rework_list #
# fix_depends satisfy_depends #
# #
# 20020710 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# #
# Merged in more depends routines - sofar - 20030305 #
# #
############################################################
# function : find_depends
# usage : find_depends "module name"
# purpose : recursive dependency finder, no need to be installed
function find_depends() {
debug_msg "function find_depends ($@)"
# as always, use private depends() and optional_depends() functions
depends () {
debug_msg " depends ($@)"
if ! $(echo $FOUND_DEPENDS | grep -qw $1) ; then
export FOUND_DEPENDS="$FOUND_DEPENDS $1"
find_depends $1
echo $1
fi
}
optional_depends() {
debug_msg " optional_depends ($@)"
if ! $(echo $FOUND_DEPENDS | grep -qw $1) ; then
if module_installed $1 ; then
export FOUND_DEPENDS="$FOUND_DEPENDS $1"
find_depends $1
echo $1
fi
fi
}
export FOUND_DEPENDS="$FOUND_DEPENDS $1"
if ! run_details $1 &> /dev/null ; then
exit 1
fi
if [ -e "$MODULE_CONFIG" ] ; then
. "$MODULE_CONFIG"
fi
run_module_file $MODULE DEPENDS
}
is_depends() {
debug_msg "is_depends ($@)"
# Is $1 a previously selected dependency of any module.
return $(cat $DEPENDS_STATUS | cut -d: -f2- | grep -q "^$1:on:")
}
in_depends() {
debug_msg "in_depends ($@)"
# Was $2 presented as a depenency for module $1
return $(grep -q "^$1:$2:" $DEPENDS_STATUS)
}
remove_depends() {
debug_msg "remove_depends ($@)"
lock_file $DEPENDS_STATUS_BACKUP &&
lock_file $DEPENDS_STATUS ||
return 1
if [ -n "$2" ] ; then
if grep -q "^$1:$2:" $DEPENDS_STATUS ; then
grep -v "^$1:$2:" $DEPENDS_STATUS_BACKUP > $DEPENDS_STATUS
verbose_msg "removing depends for \"$1\" on \"$2\""
fi
elif grep -q "^$1:" $DEPENDS_STATUS ; then
grep -v "^$1:" $DEPENDS_STATUS_BACKUP | \
grep -v ":$1:on:optional:" > $DEPENDS_STATUS
verbose_msg "removing all depends for and optional on \"$1\""
fi
cp $DEPENDS_STATUS $DEPENDS_STATUS_BACKUP
unlock_file $DEPENDS_STATUS_BACKUP &&
unlock_file $DEPENDS_STATUS
}
add_depends() {
debug_msg "add_depends ($@)"
if ! grep -q "^$1:$2:$3:$4:$5:$6$" $DEPENDS_STATUS ; then
if grep -q "^$1:$2:" $DEPENDS_STATUS ; then
remove_depends "$1" "$2"
fi
verbose_msg "adding \"$4\" depends for \"$1\" on \"$2\" ($3)"
lock_file $DEPENDS_STATUS_BACKUP &&
lock_file $DEPENDS_STATUS &&
echo "$1:$2:$3:$4:$5:$6" >> $DEPENDS_STATUS &&
cat $DEPENDS_STATUS > $DEPENDS_STATUS_BACKUP &&
unlock_file $DEPENDS_STATUS_BACKUP &&
unlock_file $DEPENDS_STATUS
fi
}
run_depends() {
debug_msg "run_depends ($@)"
# local definitions of depends and optional_depends!
depends() {
debug_msg " depends ($@)"
grep -q "^"$1"\$" $TEMP_PREPAREDDEPS 2>/dev/null && return 0
if ! module_installed $1 && ! module_held $1 ; then
if ! is_depends $1 && module_exiled $1 ; then
message "${MODULE_COLOR}${MODULE}:${PROBLEM_COLOR} ! Error: required dependency ${MODULE_COLOR}${1}${DEFAULT_COLOR}${PROBLEM_COLOR} is exiled and cannot be installed${DEFAULT_COLOR}"
return 1
else
message "${MODULE_COLOR}${MODULE}: ${DEFAULT_COLOR}" \
"Adding required dependency${FILE_COLOR}" \
"$1 ${DEFAULT_COLOR}"
lin --deps $1
echo "$1" >> $TEMP_PREPAREDDEPS
fi
fi
add_depends "$MODULE" "$1" "on" "required" "$2" "$3"
}
optional_depends() {
debug_msg " optional_depends ($@)"
# parameters: $1 = module name
# $2 = configure parameter if module wanted
# $3 = configure parameter if module declined
# $4 = description of why to use this module.
if ! in_depends "$MODULE" "$1" ; then
if module_exiled $1 ; then
verbose_msg "\"$MODULE\" optionally depends on exiled module \"$1\""
add_depends "$MODULE" "$1" "off" "optional" "$2" "$3"
else
if module_installed $1 ; then
DEFAULT="y"
else
DEFAULT="n"
fi
if query "Install optional dependency $1 $4? " $DEFAULT ; then
lin --deps $1
add_depends "$MODULE" "$1" "on" "optional" "$2" "$3"
else
add_depends "$MODULE" "$1" "off" "optional" "$2" "$3"
fi
fi
fi
}
prepare_depends_status
grep -q "^"$MODULE"\$" $TEMP_PREPAREDDEPS 2>/dev/null && return 0
if [ -s "$SCRIPT_DIRECTORY/DEPENDS" ] ; then
message "${CHECK_COLOR}Checking dependencies for" \
"${MODULE_COLOR}${MODULE}" \
"${DEFAULT_COLOR}"
run_module_file $MODULE DEPENDS
fi
}
# function : satisfy_depends
# usage : satisfy_depends (operates on $MODULE variable)
# purpose : re-check module deps based on DEPENDS_CONFIG and DEPENDS_STATUS
# NOTE: this is where a missing dependency gets installed! IOW we really do
# "satisfy" any dependencies here!
satisfy_depends() {
debug_msg "satisfy_depends ($@)"
if [ -n "$DEPS_ONLY" ] ; then
return 0
fi
unset OPTS
if [ -s "$MODULE_CONFIG" ] ; then
. $MODULE_CONFIG
fi
TMP_FILE=$(temp_create "${MODULE}.satify-depends")
grep "^$MODULE:" $DEPENDS_STATUS > $TMP_FILE
while read LINE; do
DEP_MODULE=$(echo $LINE | cut -d: -f2)
DEP_STATUS=$(echo $LINE | cut -d: -f3)
DEP_ON=$(echo $LINE | cut -d: -f5)
DEP_OFF=$(echo $LINE | cut -d: -f6)
if [ -n "$FIX" ] ; then
if DEP_STATUS="on" ; then
lin $FIX $DEP_MODULE
fi
elif [ "$DEP_STATUS" == "off" ] || module_exiled $DEP_MODULE ; then
OPTS="$OPTS $DEP_OFF"
elif [ "$DEP_STATUS" == "on" ] && ! module_installed $DEP_MODULE && \
! module_held $DEP_MODULE ; then
if lin $SILENT $COMPILE $DEP_MODULE ; then
OPTS="$OPTS $DEP_ON"
else
exit 1
fi
else
OPTS="$OPTS $DEP_ON"
fi
done < $TMP_FILE
temp_destroy $TMP_FILE
}
# conflicts... remove conflicting modules
conflicts() {
debug_msg "conflicts ($@)"
if module_installed $1 ; then
lrm $1
fi
true
}
--- NEW FILE: download.lunar ---
#!/bin/bash
############################################################
# #
# download.lunar - get sources from the net #
# #
############################################################
# leach is part of the sorcery spell management utility #
# Copyright 2001 by Kyle Sallee #
############################################################
# #
# this WAS the leach script of a source based Linux distro,#
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
# This secondly was lget mostly, and has been moved into #
# a separate lunar functions file handling all the generic #
# downloading functionality for lunar #
# #
############################################################
# #
# Parts Copyrighted Jason Johnston 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
# Parts Copyrighted Auke Kok 2002 under GPLv2 #
# #
############################################################
get_svn() {
debug_msg "get_svn ($@)"
if ! module_installed subversion ; then
message "${PROBLEM_COLOR}! Cannot fetch SVN sources without \"subversion\" installed${DEFAULT_COLOR}"
exit 1
fi
SVN_URL=$(echo $1 | cut -d: -f1-2)
SVN_DIR=$(echo $1 | cut -d: -f3)
message "${MESSAGE_COLOR}Downloading SVN module for" \
"module ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
mk_source_dir /tmp/$MODULE-$VERSION
cd /tmp/$MODULE-$VERSION
if [ -f "$2" ] ; then
verbose_msg "Extracting local SVN copy"
# unpacking in last component dir of $SVN_DIR
CD=$(pwd -P)
if ! tar xjf $2 ; then
message "${PROBLEM_COLOR}Warning: bad local SVN copy, checking out fresh SVN copy${DEFAULT_COLOR}"
rm_source_dir /tmp/$MODULE-$VERSION
mk_source_dir /tmp/$MODULE-$VERSION
fi
cd $CD
fi
NUM_RETRY=${NUM_RETRY:-5}
if [ "$NUM_RETRY" -eq 0 ]; then
NUM_RETRY=1000
fi
for (( TRY=1 ; $TRY<$NUM_RETRY+1 ; TRY++ )) ; do
if [ -d "${SVN_DIR}/.svn" ] ; then
cd ${SVN_DIR}
verbose_msg "[${TRY}] svn up"
svn up && GOT_SVN="yes"
cd ${CD}
else
verbose_msg "[${TRY}] svn co $SVN_URL $SVN_DIR"
svn co $SVN_URL $SVN_DIR && GOT_SVN="yes"
fi
if [ "$?" == "0" ] ; then
break
fi
sleep 2
done
if [ "$GOT_SVN" == "yes" ] ; then
message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$2${DEFAULT_COLOR}"
# pack in last component dir of $SVN_DIR
tar cjf $2 $SVN_DIR
else
activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not get $1"
fi
cd /tmp
rm_source_dir /tmp/$MODULE-$VERSION
}
get_cvs() {
debug_msg "get_cvs ($@)"
if ! module_installed cvs ; then
message "${PROBLEM_COLOR}! Cannot fetch CVS sources without \"cvs\" installed!${DEFAULT_COLOR}"
exit 1
fi
[ -f ~/.cvspass ] || touch ~/.cvspass
CVSURL=$(echo $1 | sed "s:^cvs\://::")
CVSARGS=$(echo $CVSURL | cut -d@ -f1)
CVSSERVER=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f1)
CVSSPATH=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f2)
CVSMODULE=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f3)
CVSRELEASE=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f4)
CVSOPTIONS=$(echo $CVSURL | cut -d@ -f2 | cut -d: -f5)
if [ ! -z "$CVSRELEASE" ]; then
CVSRELEASE="-r $CVSRELEASE"
fi
CVSROOT="$CVSARGS@$CVSSERVER:$CVSSPATH"
message "${MESSAGE_COLOR}Downloading CVS module" \
"${FILE_COLOR}${CVSMODULE}${DEFAULT_COLOR}${MESSAGE_COLOR}" \
"for module ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
mk_source_dir /tmp/$MODULE-$VERSION
cd /tmp/$MODULE-$VERSION
if [ -f "$2" ] ; then
verbose_msg "Extracting local CVS copy"
# unpacking in last component dir of $CVSMODULE
CD=$(pwd -P)
debug_msg "get_cvs: PWD=$PWD mkdir -p $(dirname $CVSMODULE)"
mkdir -p $(dirname $CVSMODULE)
cd $(dirname $CVSMODULE)
debug_msg "get_cvs: PWD=$PWD tar xjf $2"
if ! tar xjf $2 ; then
message "${PROBLEM_COLOR}Warning: bad local CVS copy, checking out fresh CVS copy${DEFAULT_COLOR}"
rm_source_dir /tmp/$MODULE-$VERSION
mk_source_dir /tmp/$MODULE-$VERSION
cd /tmp/$MODULE-$VERSION
else
cd /tmp/$MODULE-$VERSION/$CVSMODULE
fi
fi
verbose_msg "CVSROOT=\"$CVSROOT\""
NUM_RETRY=${NUM_RETRY:-5}
if [ "$NUM_RETRY" -eq 0 ]; then
NUM_RETRY=1000
fi
for (( TRY=1 ; $TRY<$NUM_RETRY+1 ; TRY++ )) ; do
if [ -d CVS ] ; then
verbose_msg "[${TRY}] cvs -qz3 up -PAd $CVSOPTIONS $CVSRELEASE"
cvs -qz3 up -PAd $CVSOPTIONS $CVSRELEASE && GOT_CVS="yes"
else
verbose_msg "[${TRY}] cvs -qz3 co $CVSOPTIONS $CVSRELEASE $CVSMODULE"
CVSROOT=$CVSROOT cvs -qz3 co $CVSOPTIONS $CVSRELEASE $CVSMODULE && GOT_CVS="yes"
fi
if [ "$?" == "0" ] ; then
break
fi
sleep 2
done
if [ "$GOT_CVS" == "yes" ] ; then
message "${MESSAGE_COLOR}Creating ${FILE_COLOR}${2}${DEFAULT_COLOR}"
# pack in last component dir of $CVSMODULE
cd /tmp/$MODULE-$VERSION/$(dirname $CVSMODULE)
tar cjf $2 $(basename $CVSMODULE)
cd $CD
else
activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not get $CVSMODULE"
fi
cd /tmp
rm_source_dir /tmp/$MODULE-$VERSION
}
erase() {
debug_msg "erase ($@)"
if [ "$PARTIAL" == "off" ]; then
verbose_msg "erase: deleting \"$(guess_filename $1)\""
rm -f $(guess_filename $1)
fi
}
call_wget() {
debug_msg "call_wget ($@)"
[ -n "$http_proxy" ] && export http_proxy=$http_proxy
[ -n "$ftp_proxy" ] && export ftp_proxy=$ftp_proxy
[ -n "$no_proxy" ] && export no_proxy=$no_proxy
debug_msg "call_wget: PWD=$PWD"
verbose_msg "calling \"wget $WGET_CACHE $WGET_RATE $WGET_FTP_CONNECTION $WGET_RETRIES $WGET_PARTIAL $1\""
wget $WGET_CACHE $WGET_RATE $WGET_FTP_CONNECTION $WGET_RETRIES $WGET_PARTIAL $1
}
# fuzzy_wget is a wrapper that tries to call possible mis-finenamed
# source tarballs (ie .tar.gz instead of .tar.bz2)
fuzzy_wget() {
debug_msg "fuzzy_wget ($@)"
# this is what the download will be stored as initially:
TMP_FILE=/tmp/$(basename $2)
if [ "$FTP_ACTIVE" == "off" -o "$FTP_PASSIVE" == "on" ] ; then
WGET_FTP_CONNECTION="--passive-ftp"
fi
if [ "$CONTINUE" == "off" ] ; then
erase $(guess_filename $TMP_FILE)
else
WGET_PARTIAL="--continue"
fi
if [ "$USE_CACHE" == "off" ] ; then
WGET_CACHE="--cache=off"
else
WGET_CACHE="--cache=on"
fi
if [ -n "$DOWNLOAD_RATE" ] ; then
WGET_RATE="--limit-rate=${DOWNLOAD_RATE}"
fi
WGET_NUM_RETRY=${NUM_RETRY:=5}
WGET_RETRIES="--tries=${WGET_NUM_RETRY}"
FUZZY=${FUZZY:=on}
S_FILE=$(basename $2 | sed -e "s/\.tar\.gz$//" -e "s/\.tgz$//" -e "s/\.tar\.bz2$//")
if erase $2 && call_wget $1 ; then
FILE="$(basename $2)"
elif [ "$FUZZY" == "off" ] ; then
activity_log "lget" "$MODULE" "$VERSION" "failed" "broken URL: $1"
return 1
elif erase $2 && call_wget $(dirname $1)/$S_FILE.tar.bz2 ; then
FILE="$S_FILE.tar.bz2"
elif erase $2 && call_wget $(dirname $1)/$S_FILE.tar.gz ; then
FILE="$S_FILE.tar.gz"
elif erase $2 && call_wget $(dirname $1)/$S_FILE.tgz ; then
FILE="$S_FILE.tgz"
else
activity_log "lget" "$MODULE" "$VERSION" "failed" "broken URL: $1"
return 1
fi
TMP_RESULTFILE=$(guess_filename $TMP_FILE)
if testpack $TMP_RESULTFILE ; then
install -m644 $TMP_RESULTFILE $(dirname $2)/$(basename $TMP_RESULTFILE)
rm $(guess_filename $TMP_RESULTFILE)
verbose_msg "download of \"$1\" successfull"
else
rm -f $(guess_filename $TMP_RESULTFILE)
fi
}
# function: get_url
# usage : get_url URL DESTINATION
#
# if left blank, destination defaults to $SOURCE_CACHE/$(filename URL)
# if specified, the remainder will be copied to $DESTINATION
#
get_url() {
(
cd /tmp
debug_msg "get_url ($@)"
if [ -n "$1" ] ; then
if [ "${1:0:6}" == "cvs://" ] ; then
# cvs urls
CVS_THRESHOLD=${CVS_THRESHOLD:-10}
if (( "$CVS_THRESHOLD" > 0 )) ; then
if [ ! -f "$2" ] ; then
get_cvs $1 $2
elif [ "$(find $2 -amin +$CVS_THRESHOLD)" == "$2" ] ; then
get_cvs $1 $2
else
verbose_msg "Skipping cvs update (less than $CVS_THRESHOLD mins old)"
fi
else
get_cvs $1 $2
fi
elif [ "${1:0:6}" == "svn://" ] ; then
# svn urls
SVN_THRESHOLD=${SVN_THRESHOLD:-10}
if (( "SVN_THRESHOLD" > 0 )) ; then
if [ ! -f "$2" ] ; then
get_svn $1 $2
elif [ "$(find $2 -amin +$SVN_THRESHOLD)" == "$2" ] ; then
get_svn $1 $2
else
verbose_msg "Skipping svn update (less than $SVN_THRESHOLD mins old)"
fi
else
get_svn $1 $2
fi
elif [ "$1:0:7}" == "cpan://" ] ; then
# no way, this cannot be tru
#
# and it isn't, but I thought this would be a cute, simple way of
# fetching sources and possibly have 'CPAN' do all the work for us
# thereby not opposing the normal perl module modules (like File-Tail)
#
# TODO play with this
:
elif [ "{$1:0:5}" == "file:" ] ; then
# adding this since wget is a bitch and will not fetch this... sigh
# this will copy file to $2... so you may use it as you like
cp ${1/file:/} $2
else
# ordinary URL's handled by fuzzy_wget
if [ -n "$BASE_URL" ] ; then
URL=$BASE_URL/$(basename $2)
fi
connect &&
if [ -n "$BASE_URL" ] ; then
fuzzy_wget $BASE_URL/$(basename $2) $2
elif ! fuzzy_wget $1 $2 ; then
if [ -n "$LRESORT_URL" ] ; then
fuzzy_wget $LRESORT_URL/$(basename $2) $2
fi
fi
fi
fi
)
}
lget_lock() {
debug_msg "lget_lock ($@)"
echo $$ > /var/lock/lgetting.$1
}
lget_locked() {
debug_msg "lget_locked ($@)"
if [ -f "/var/lock/lgetting.$1" ] &&
ps `cat /var/lock/lgetting.$1` | grep -q "lget" ; then
true
else
false
fi
}
lget_unlock() {
debug_msg "lget_unlock ($@)"
rm -f /var/lock/lgetting.$1 &> /dev/null
}
download_module() {
(
debug_msg "download_module ($@)"
if ! run_details $1 ; then
exit 1
fi
MAX_SOURCES=${MAX_SOURCES:=100}
# loop over all sources
for (( N = 0 ; N < MAX_SOURCES ; N++ )) ; do
# get the URL part
eval SRC=\$$(echo SOURCE$N | sed s/SOURCE0/SOURCE/ )
eval URLS=\${$(echo SOURCE${N}_URL | sed s/SOURCE0/SOURCE/ )[@]}
# continue (to next) if empty once, break if empty tiwce
if [ -z "$SRC" ] ; then
if [ -z "$SECOND" ] ; then
SECOND="yes"
continue
else
break
fi
fi
# silly that this exists:
if [ "$CLEAR_CACHE" == "on" ] ; then
verbose_msg "clearing source cache copy of \"$SRC\""
rm -f `guess_filename $SOURCE_CACHE/$SRC` 2>/dev/null
fi
# add source part if needed
for URL in $URLS ; do
if [ "${URL:((${#URL}-1)):1}" == "/" ] ; then
URL=${URL}${SRC}
fi
# quit if we did get it
if [ -f "$(guess_filename $SOURCE_CACHE/$SRC)" ] ; then
if [ "${URL:0:6}" == "cvs://" ] ; then
verbose_msg "trying to download \"$URL\""
get_url $URL $SOURCE_CACHE/$SRC
elif [ "${URL:0:6}" == "svn://" ] ; then
verbose_msg "trying to download \"$URL\""
get_url $URL $SOURCE_CACHE/$SRC
else
verbose_msg "Skipping download of \"$SRC\" for module \"$MODULE\" (in cache)"
continue 2
fi
else
message "${MESSAGE_COLOR}Downloading source file" \
"${FILE_COLOR}${SRC}${DEFAULT_COLOR}" \
"${MESSAGE_COLOR}for module" \
"${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
verbose_msg "trying to download \"$URL\""
get_url $URL $SOURCE_CACHE/$SRC
fi
done
done
return 0
)
}
testpack () {
debug_msg "testpack ($@)"
FILENAME=$(guess_filename $1) || FILENAME=$(guess_filename $SOURCE_CACHE/$1)
if [ -f "$FILENAME" ] ; then
COMPRESSOR=$(file -b $FILENAME | cut -d ' ' -f1)
case $COMPRESSOR in
bzip2) bzip2 -tf $FILENAME >/dev/null 2>&1 ;;
gzip) gzip -tf $FILENAME >/dev/null 2>&1 ;;
compress*) gzip -tf $FILENAME >/dev/null 2>&1 ;;
Zip) unzip -tq $FILENAME >/dev/null 2>&1 ;;
RPM) rpmunpack <$FILENAME | gzip -t >/dev/null 2>&1 ;;
*) true ;;
esac
fi
}
--- NEW FILE: edit.lunar ---
#!/bin/bash
# #
# edit.lunar - functions to edit files #
# #
####################################################################
# #
# Parts copyright Jason Johnston 2002 under GPLv2 #
# #
# Parts copyright Auke Kok 2002 under GPLv2 #
# #
####################################################################
# function : patch_it
# usage : patch_it patch_file patch_level
# purpose : calls "patch -px < $filename", where filename may be a variety
# of formats
patch_it () {
verbose_msg "patch_it \"$1\" \"$2\"";
if [[ -n `echo $1 | grep .tar` ]] ; then
TARCMD="tar x -O"
else
TARCMD="cat"
fi
if [[ -n `echo $1 | grep .bz2` ]] ; then
GZCMD="bzcat"
elif [[ -n `echo $1 | grep .gz` ]] ; then
GZCMD="zcat"
else
GZCMD="cat"
fi
TMPFILE1=$(temp_create "patch_1")
TMPFILE2=$(temp_create "patch_2")
if $GZCMD $1 > $TMPFILE1 ; then
# uncompress OK
if cat $TMPFILE1 | $TARCMD > $TMPFILE2 ; then
# untar OK
if patch -N -p$2 < $TMPFILE2 ; then
# patch cmd is OK
temp_destroy $TMPFILE1
temp_destroy $TMPFILE2
return 0
fi
fi
fi
message "${PROBLEM_COLOR}! Broken patch file ${DEFAULT_COLOR}${FILE_COLOR}$1${DEFAULT_COLOR}"
temp_destroy $TMPFILE1
temp_destroy $TMPFILE2
return -1
}
# function : sedit
# usage : sedit sed-statement file [file [file] ...]
# purpose : edit [files] with a sed function
sedit () {
SEDIT=$1;
shift;
for FILE in $@;
do
verbose_msg "Editing \"${FILE}\"";
sed -i "$SEDIT" "$FILE";
done
}
# function : edit_file
# usage : edit_file FILENAME
# purpose : to edit a file
edit_file() {
debug_msg "edit_file ($@)"
${EDITOR:-nano} $1
}
--- NEW FILE: init.lunar ---
#!/bin/bash
# #
# init.lunar - Lunar subroutines #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function : enviro_check
# usage : enviro_check
# purpose : check if the shell is proper
enviro_check() {
debug_msg "enviro_check ($@)"
if [ -z "$SHELL" ] || [ "$USER" != "root" ] ; then
message "${PROBLEM_COLOR}WARNING:${DEFAULT_COLOR}${MESSAGE_COLOR}" \
"You are not running a fully initialized root shell, consider"
message "running a proper root shell with 'su -'" \
"${DEFAULT_COLOR}"
fi
}
# function : root_check
# usage : root_check
# purpose : check if the user is root
root_check() {
debug_msg "root_check ($@)"
if [ "$UID" != "0" ] ; then
message "${PROBLEM_COLOR}ERROR:${DEFAULT_COLOR}${MESSAGE_COLOR}" \
"User must have root privileges to run this program" \
"${DEFAULT_COLOR}"
exit 1
fi
}
# function : set_priority
# usage : set_priority
# purpose : force niceness on lunar's processes
set_priority() {
debug_msg "set_priority ($@)"
LUNAR_PRIORITY=${LUNAR_PRIORITY:="+10"}
renice "$LUNAR_PRIORITY" -p $$ 2> /dev/null >/dev/null
}
--- NEW FILE: install.lunar ---
#!/bin/bash
############################################################
# #
# install.lunar - install Lunar modules #
# #
############################################################
# cast is part of the sorcery spell management utility #
# Copyright 2001 by Kyle Sallee #
############################################################
# #
# this WAS the cast script of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Parts Copyrighted Jason Johnston 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
check_blacklist() {
debug_msg "check_blacklist ($@)"
#Copyrighted Jason Johnston 2002 under GPLv2
# This checks the /var/state/lunar/gcc.<platform>
# file to see if it exists. If it does exist then
# we grep it to see the names of the modules that
# DO NOT compile with gcc 3x. If the module is
# on the list, we set the path so that gcc 3x is
# NOT used.
# If you find a module that does not compile with
# gcc 3x please email your findings to
# maintainer at lunar-linux.org.
# Usage check_checklist $MODULES
if [ -z "$PLATFORM" ] ; then
PLATFORM=x86
fi
if [ -f /var/state/lunar/blacklist.$PLATFORM ] ; then
BLKLST=$(grep ^$MODULE$ /var/state/lunar/blacklist.$PLATFORM)
if [ "$BLKLST" == "$MODULE" ] ; then
message "${PROBLEM_COLOR}! Module ${DEFAULT_COLOR}${MODULE_COLOR}$MODULE${DEFAULT_COLOR}${PROBLEM_COLOR} is blacklisted and will not be installed${DEFAULT_COLOR}"
exit 0
fi
else
touch /var/state/lunar/blacklist.$PLATFORM
fi
}
run_conflicts() {
debug_msg "run_conflicts ($@)"
run_module_file $MODULE CONFLICTS
}
# create the dependency files if they do not exist
prepare_depends_status() {
debug_msg "prepare_depends_status ($@)"
[ -f $DEPENDS_STATUS ] || touch $DEPENDS_STATUS
[ -f $DEPENDS_STATUS_BACKUP ] || touch $DEPENDS_STATUS_BACKUP
}
prepare_module_config() {
debug_msg "prepare_module_config ($@)"
if [ ! -x "$MODULE_CONFIG" ] ; then
touch $MODULE_CONFIG
chmod a+x $MODULE_CONFIG
fi
}
# run the CONFIGURE script
run_configure() {
debug_msg "run_configure ($@)"
if [ -n "$RECONFIGURE" ]; then
verbose_msg "Reconfiguring \"$MODULE\""
rm -f $DEPENDS_CONFIG/$MODULE
remove_depends $MODULE
fi
prepare_module_config
if ! use_xinetd ; then
if [ -n "$RECONFIGURE" ] || ! grep -q INITDSCRIPTS $MODULE_CONFIG ; then
use_initd
fi
fi
grep -q "^"$MODULE"\$" $TEMP_PREPAREDDEPS 2>/dev/null && return 0
run_module_file $MODULE CONFIGURE
}
run_pre_build() {
debug_msg "run_pre_build ($@)"
message "${MESSAGE_COLOR}Building ${MODULE_COLOR}$MODULE${DEFAULT_COLOR}"
cd $BUILD_DIRECTORY
if verify_all_sources $MODULE ; then
if [ -s $SCRIPT_DIRECTORY/PRE_BUILD ] ; then
run_module_file $MODULE PRE_BUILD
else
if ! default_pre_build ; then
return 1
fi
fi
else
return 1
fi
}
stop_logging() {
debug_msg "stop_logging ($@)"
message "${MESSAGE_COLOR}Creating" \
"${FILE_COLOR}$COMPILE_LOGS/$MODULE-$VERSION.bz2" \
"${DEFAULT_COLOR}"
bzip2 -9f < $C_LOG > $COMPILE_LOGS/$MODULE-$VERSION.bz2
temp_destroy $C_LOG
temp_destroy $C_FIFO
}
start_logging () {
debug_msg "start_logging ($@)"
MOD_SNAME=$(echo $MODULE | sed 's:/:.:g')
export C_LOG=$(temp_create "${MOD_SNAME}.compile-log")
export C_FIFO=$(temp_create "${MOD_SNAME}.compile-fifo")
# just remaking this as FIFO
rm -f $C_FIFO
mknod $C_FIFO p
echo "Compile log for \"$MODULE\"-\"$VERSION\" Built on \"$(date -u)\"" > $C_LOG
activate_voyeur
}
activate_voyeur() {
debug_msg "activate_voyeur ($@)"
if [ -z "$SILENT" ] ; then
case $VOYEUR in
on) tee -a $C_LOG < $C_FIFO & ;;
*) tee -a $C_LOG < $C_FIFO >/dev/null & ;;
esac
else
tee -a $C_LOG < $C_FIFO >/dev/null &
fi
}
run_build() {
debug_msg "run_build ($@)"
if [ -d "$SOURCE_DIRECTORY" ] ; then
cd $SOURCE_DIRECTORY
fi
verbose_msg "building \"$MODULE\" version \"$VERSION\" in `pwd`"
if [ -x ./configure ] || [ -x ./src/configure ] ; then
if [ -f /var/lib/lunar/localsaconfig ]; then
if [ -f /var/cache/config/$MODULE ] ; then
message "${MESSAGE_COLOR}These are your current -- config options for module ${MODULE_COLOR}$MODULE"
message "${FILE_COLOR}(/var/cache/config/$MODULE)"
cat /var/cache/config/$MODULE
fi
if query "Do you wish to add -- options to ./configure?" n ; then
edit_file /var/cache/config/$MODULE
OPTS="$OPTS $(cat /var/cache/config/$MODULE)"
message "${MESSAGE_COLOR} OPTS= ${MODULE_COLOR}$OPTS"
fi
fi
fi
if [ -s $SCRIPT_DIRECTORY/BUILD ] ; then
run_module_file $MODULE BUILD
else
default_build
fi
}
run_post_build() {
debug_msg "run_post_build ($@)"
if [ -s $SCRIPT_DIRECTORY/POST_BUILD ] ; then
run_module_file $MODULE POST_BUILD
fi
default_post_build
}
run_post_install() {
debug_msg "run_post_install ($@)"
if [ -s $SCRIPT_DIRECTORY/POST_INSTALL ] ; then
run_module_file $MODULE POST_INSTALL
fi
}
export_ld() {
debug_msg "export_ld ($@)"
for DIRECTORY in $*; do
if file -b $DIRECTORY/*.so* |
grep -q "shared object"
then
if [ -z "$LD_LIBRARY_PATH" ]
then export LD_LIBRARY_PATH="$DIRECTORY"
else export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$DIRECTORY"
fi
fi
done
}
show_owner() {
debug_msg "show_owner ($@)"
OWNER=`grep $TARGET $INSTALL_LOGS/* |
cut -d : -f1 |
sed -n 1p`
if [ -n "$OWNER" ]; then echo "`basename $OWNER`"
else echo "nobody"
fi
}
remove_line() {
debug_msg "remove_line ($@)"
F_TMP=$(temp_create "${MODULE}.remove-line")
cp $I_LOG $F_TMP
grep -v $ITEM $F_TMP > $I_LOG
temp_destroy $F_TMP
message "Symbolic link: ${SYMLINK_COLOR}${ITEM}${DEFAULT_COLOR}" \
"is owned by ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
message "Target of symbolic link is ${FILE_COLOR}${TARGET}${DEFAULT_COLOR}"
message "${FILE_COLOR}${TARGET}${DEFAULT_COLOR} is owned by `show_owner`"
message "Removed: ${SYMLINK_COLOR}${ITEM}${DEFAULT_COLOR} from ${I_LOG}"
}
resurrect() {
(
debug_msg "resurrect ($@)"
if [ -s /etc/lunar/local/optimizations ] ; then
. /etc/lunar/local/optimizations
fi
if ! run_details $1 ; then
return 1
fi
run_conflicts &&
satisfy_depends &&
STATUS=installed &&
if module_held $MODULE ; then
VERSION=`installed_version $MODULE`
STATUS=held
lrm --keepconfig $MODULE
fi &&
CACHE_BZ="$INSTALL_CACHE/$MODULE-$VERSION-$BUILD.tar.bz2"
if [ -f "$CACHE_BZ" ] && bzip2 -tf $CACHE_BZ ; then
message "${RESURRECT_COLOR}Resurrecting ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR} ${MESSAGE_COLOR}version ${VERSION_COLOR}${VERSION}${DEFAULT_COLOR}"
bzip2 -cd $CACHE_BZ | tar -Pkx 1>/dev/null 2>&1
add_module $MODULE $STATUS $VERSION &&
verbose_msg "running \"lunar fix $MODULE\"" &&
if run_fix $MODULE ; then
report $INSTALL_LOGS/$MODULE-$VERSION "install log" $MODULE $VERSION &&
sound SUCCESS
activity_log "lin" "$MODULE" "$VERSION" "success" "resurrected"
message "${RESURRECT_COLOR}Resurrected ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR} ${MESSAGE_COLOR}succesfully${DEFAULT_COLOR}"
else
sound FAILURE
activity_log "lin" "$MODULE" "$VERSION" "failed" "resurrect failed"
false
fi
else
sound FAILURE
activity_log "lin" "$MODULE" "$VERSION" "failed" "resurrect failed"
false
fi
)
}
show_download_progress() {
debug_msg "show_download_progress ($@)"
if [ -f "$TEMP_DOWNLOADLOG" ] ; then
if [ -z "$LC_OLD" ] ; then
LC_OLD=0
fi
LC=`cat $TEMP_DOWNLOADLOG 2>/dev/null | wc -l | tr -d ' '`
if [ "$LC" != "$LC_OLD" ] ; then
(( LC_OLD++ ))
sed -n ${LC_OLD},${LC}p $TEMP_DOWNLOADLOG
LC_OLD=$LC
fi
fi
}
show_downloading() {
debug_msg "show_downloading ($@)"
if [ -e "$TEMP_DOWNLOADLOG" ] ; then
verbose_msg "====== download progess:"
while ! lget $MODULE >> $TEMP_DOWNLOADLOG 2>&1 ; do
show_download_progress
sleep 1
done
show_download_progress
verbose_msg "====== end download progress"
fi
}
lin_module() {
(
debug_msg "lin_module ($@)"
# make sure we got all the info
if ! run_details $1 ; then
return 1
fi
# resurrect if we can, but not is -c was issued
if [ "$AUTORESURRECT" == "on" -a -z "$COMPILE" ] ; then
# we also do not resurrect if $MODULE is currently installed!
if ! module_installed $MODULE ; then
if resurrect $MODULE ; then
return 0
fi
fi
fi
# make sure we have the source code
download_module $MODULE
# set the installwatchfile
export INSTALLWATCHFILE=$(temp_create "$MODULE.installwatch")
# lock the module for installation, check for moonbase call
MOD_SNAME=$(echo $MODULE | sed 's:/:.:g')
linING="/var/lock/installing.$MOD_SNAME"
if [ "$MODULE" == "moonbase" ] ; then
if ! current_locked && ! solo_locked ; then
echo $$ > $linING &&
get_moonbase &&
rm -f $linING &&
return
else
exit 1
fi
fi
check_blacklist &&
# here we run CONFLICTS, DEPENDS and CONFIGURE stuff
run_conflicts &&
satisfy_depends &&
show_downloading &&
# now entering the physical BUILD stage
if ! current_locked && ! solo_locked ; then
echo $$ > $linING &&
start_logging &&
if ! run_pre_build ; then
LIN_ERROR="PRE_BUILD"
else
# important stuff here!!!
invoke_installwatch &&
if [ -z "$CFLAGS" ] ; then
optimize
fi &&
if ! run_build ; then
LIN_ERROR="BUILD"
else
if ! run_post_build ; then
LIN_ERROR="POST_BUILD"
fi
fi
fi
devoke_installwatch
stop_logging
if [ -n "$LIN_ERROR" ] ; then
if [ -f "$INSTALLWATCHFILE" ] ; then
temp_destroy $INSTALLWATCHFILE
fi
sound FAILURE
message "${PROBLEM_COLOR}! Problem detected during ${FILE_COLOR}$LIN_ERROR${DEFAULT_COLOR}"
rm -f $linING
report $COMPILE_LOGS/$MODULE-$VERSION.bz2 "compile log" $MODULE $VERSION
activity_log "lin" "$MODULE" "$VERSION" "failed" "Due to build errors during $LIN_ERROR"
return 1
fi
if ! boost ; then
LIN_ERROR="boost"
else
if ! run_post_install ; then
LIN_ERROR="POST_INSTALL"
fi
fi
if [ -f "$INSTALLWATCHFILE" ] ; then
verbose_msg "removing installwatch file"
temp_destroy $INSTALLWATCHFILE
fi
if [ -n "$LIN_ERROR" ] ; then
sound FAILURE
message "${PROBLEM_COLOR}! Problem detected during ${FILE_COLOR}$LIN_ERROR${DEFAULT_COLOR}"
rm -f $linING
report $COMPILE_LOGS/$MODULE-$VERSION.bz2 "compile log" $MODULE $VERSION
activity_log "lin" "$MODULE" "$VERSION" "failed" "Due to build errors during $LIN_ERROR"
return 1
fi
rm_source_dir &&
report $INSTALL_LOGS/$MODULE-$VERSION "install log" $MODULE $VERSION &&
rm -f $linING &&
sound SUCCESS &&
activity_log "lin" "$MODULE" "$VERSION" "success"
if [ "$?" != 0 ] ; then
sound FAILURE
message "${PROBLEM_COLOR}! Problem detected${DEFAULT_COLOR}"
rm -f $linING
report $COMPILE_LOGS/$MODULE-$VERSION.bz2 "compile log" $MODULE $VERSION
activity_log "lin" "$MODULE" "$VERSION" "failed" "Due to build errors during or after $LIN_ERROR"
return 1
fi
fi
)
}
lin_locked() {
debug_msg "lin_locked ($@)"
LOCK_SNAME=$(echo $1 | sed 's:/:.:g')
[ -f /var/lock/installing.$LOCK_SNAME ] &&
ps `cat /var/lock/installing.$LOCK_SNAME` |
grep -q "lin"
}
solo_locked() {
debug_msg "solo_locked ($@)"
for SOLO_MODULE in `cat $SOLO` ; do
if lin_locked $SOLO_MODULE ; then
message "${PROBLEM_COLOR}lining${DEFAULT_COLOR}" \
"of other modules is disabled during a" \
"lin ${MODULE_COLOR}${SOLO_MODULE}" \
"${DEFAULT_COLOR}"
return
fi
done
false
}
current_locked() {
debug_msg "current_locked ($@)"
if lin_locked $MODULE; then
message "${QUERY_COLOR}Detected lin lock file: ${FILE_COLOR}${linING}${MESSAE_COLOR}"
message "${MESSAGE_COLOR}Now waiting for ${MODULE_COLOR}${MODULE}${DEFAULTT_COLOR}${MESSAGE_COLOR} to finish installing or for the lock to clear."
while lin_locked $MODULE; do sleep 2; done
false
else
false
fi
}
build_module_depends() {
(
debug_msg "build_module_depends ($@)"
run_details $1 &&
run_configure &&
run_depends &&
satisfy_depends
)
}
build_depends() {
debug_msg "build_depends ($@)"
for MODULE in $@ ; do
if ! module_installed $MODULE || [ ! -n "$PROBE" ] ; then
if ! module_held $MODULE ; then
build_module_depends $MODULE
else
verbose_msg "Skipping dependency checking of held module \"$MODULE\""
fi
fi
done
}
--- NEW FILE: locking.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/locking #
# includes lock_file and unlock_file functions #
# #
# 20020526 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function: lock_file
# usage : lock_file <absolute file name>
# purpose : locks a file or wait until. Better use as lock_file <file> && || etc
function lock_file() {
debug_msg "lock_file ($@)"
function file_lock() {
#locking is disabled if ln or rm not found!!
[ -x "/bin/ln" ] || return 0
[ -x "/bin/rm" ] || return 0
LOCK_SNAME=$(echo $1 | sed 's:/:.:g')
TEMPFILE="$LOCK_SNAME.$$"
LOCKFILE="$LOCK_SNAME.lock"
echo $$ > $TEMPFILE 2>/dev/null ||
{
message "${PROBLEM_COLOR}You don't have permission to access" \
"$TEMPFILE ${DEFAULT_COLOR}"
exit 1
}
ln $TEMPFILE $LOCKFILE 2>/dev/null &&
{
rm -f $TEMPFILE
return 0
}
[ -f "$LOCKFILE" ] || return 1
STALE_PID=`< $LOCKFILE`
[ "$STALE_PID" -gt "0" ] || return 1
kill -0 $STALE_PID 2>/dev/null &&
{
rm -f $TEMPFILE
return 1
}
rm -f $LOCKFILE 2>/dev/null &&
echo "Removed stale lock file of process $STALE_PID"
ln $TEMPFILE $LOCKFILE 2>/dev/null &&
{
rm -f $TEMPFILE
return 0
}
rm -f $TEMPFILE
return 1
}
while ! file_lock $LOCK_SNAME
do
message "${MESSAGE_COLOR}Waiting to lock the file $1${DEFAULT_COLOR}"
sleep 1
done
return 0
}
# function: unlock_file
# usage : unlock_file <absolute file name>
# purpose : unlocks a file
function unlock_file() {
debug_msg "unlock_file ($@)"
LOCK_SNAME=$(echo $1 | sed 's:/:.:g')
#unlocking is disabled if rm not found!!
[ -x "/bin/rm" ] || return 0
rm -f $LOCK_SNAME.lock 2>/dev/null && return 0
return 1
}
--- NEW FILE: main.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/main.lunar #
# contains all main handling code, aka the long complex #
# functions like renew, update, fix, etc. One day they all #
# will be in here. #
# #
############################################################
# #
# Copyrighted Auke Kok 2003 under GPLv2 #
# #
############################################################
# function : renew
# usage : renew
# purpose : frontend function that includes all renewing code
renew() {
debug_msg "renew ($@)"
message "${MESSAGE_COLOR}Starting update of installed modules${DEFAULT_COLOR}"
purge_modules
export TMP_LIN_SUCCESS=$(temp_create "successfull")
export TMP_LIN_FAIL=$(temp_create "failed")
update_modules
if [ "$AUTOFIX" == "on" ] ; then
message "${MESSAGE_COLOR}Executing AUTOFIX : lin --fix${DEFAULT_COLOR}"
lin --fix
fi
if [ "$AUTOPRUNE" == "on" ] ; then
message "${MESSAGE_COLOR}Executing AUTOPRUNE : lunar prune${DEFAULT_COLOR}"
prune
fi
display_update_log
temp_destroy $TMP_LIN_SUCCESS
temp_destroy $TMP_LIN_FAIL
}
update() {
debug_msg "update ($@)"
if ps -C lin > /dev/null; then
echo "Unable to update lunar concurrently while installing."
sleep 5
return 1
fi
lin moonbase
if (( $(lvu installed $LUNAR_MODULE) < $(lvu version $LUNAR_MODULE) ))
then
lin $LUNAR_MODULE && lunar renew
else
lunar renew
fi
}
rebuild() {
debug_msg "rebuild ($@)"
rm -f $INSTALL_QUEUE
message "To do a non recursive rebuild"
message "all installed modules must be fixed first."
sleep 3
$LIN --fix
for LINE in `cat $MODULE_STATUS_BACKUP`; do
MODULE=`echo "$LINE" | cut -d : -f1`
STATUS=`echo "$LINE" | cut -d : -f3`
if [ "$STATUS" == "installed" ] &&
[ "$MODULE" != "$LUNAR_MODULE" ]; then
echo $MODULE >> $INSTALL_QUEUE
fi
done
message "Sorting the dependencies, that may take some time"
sort_install_queue
unset MODULE
if query "Edit Rebuild/Install Queue?" n
then edit_file $INSTALL_QUEUE
fi
$LIN --compile `cat $INSTALL_QUEUE`
rm -f $INSTALL_QUEUE
}
# function : prune
# usage : prune
# purpose : prune all old logs, source copy's, install caches
prune() {
debug_msg "prune ($@)"
message "${MESSAGE_COLOR}Generating a keep list..." \
"${DEFAULT_COLOR}"
KEEP="/tmp/prune.keep.$$"
trap "rm -f $KEEP 2>/dev/null; exit" INT QUIT TERM
generate_keep_list
message "${MESSAGE_COLOR}Now pruning $SOURCE_CACHE..." \
"${DEFAULT_COLOR}"
ls $SOURCE_CACHE |
while read FILE; do
grep -q "^$FILE$" $KEEP || {
rm $SOURCE_CACHE/$FILE 2>/dev/null
verbose_msg "rm \"$SOURCE_CACHE/$FILE\""
}
done
message "${MESSAGE_COLOR}Now pruning $INSTALL_CACHE..." \
"${DEFAULT_COLOR}"
ls $INSTALL_CACHE |
while read FILE; do
grep -q "^$FILE$" $KEEP || {
rm $INSTALL_CACHE/$FILE 2>/dev/null
verbose_msg "rm \"$INSTALL_CACHE/$FILE\""
}
done
KEEP2="/tmp/prune.instlist.$$"
trap "rm -f $KEEP2 2>/dev/null; exit" INT QUIT TERM
cat $MODULE_STATUS | cut -d: -f1,4 | sed 's/:/-/' > $KEEP2
message "${MESSAGE_COLOR}Now pruning $INSTALL_LOGS..." \
"${DEFAULT_COLOR}"
ls $INSTALL_LOGS |
while read FILE; do
grep -q "^$FILE$" $KEEP2 || {
rm $INSTALL_LOGS/$FILE
verbose_msg "rm \"$INSTALL_LOGS/$FILE\""
}
done
message "${MESSAGE_COLOR}Now pruning $COMPILE_LOGS..." \
"${DEFAULT_COLOR}"
ls $COMPILE_LOGS | sed 's/.bz2$//' |
while read FILE; do
grep -q "^$FILE$" $KEEP2 || {
rm $COMPILE_LOGS/$FILE.bz2
verbose_msg "rm \"$COMPILE_LOGS/$FILE\""
}
done
message "${MESSAGE_COLOR}Now pruning $MD5SUM_LOGS..." \
"${DEFAULT_COLOR}"
ls $MD5SUM_LOGS |
while read FILE; do
grep -q "^$FILE$" $KEEP2 || {
rm $MD5SUM_LOGS/$FILE
verbose_msg "rm \"$MD5SUM_LOGS/$FILE\""
}
done
rm -f $KEEP 2>/dev/null
rm -f $KEEP2 2>/dev/null
trap INT QUIT TERM
}
resurrect_modules() {
debug_msg "resurrect_modules ($@)"
for MODULE in $@ ; do
if run_details $MODULE ; then
resurrect $MODULE
fi
done
}
--- NEW FILE: messages.lunar ---
#!/bin/bash
# #
# messages - lunar message display functions #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# #
# moved to messages.lunar by sofar 2003 #
# #
############################################################
message() {
if [ -z "$SILENT" ] ; then
echo -e "$*"
fi
}
verbose_msg() {
if [ "$VERBOSE" == "on" ] ; then
message "+ $*"
fi
}
debug_msg() {
if [ -n "$LUNAR_DEBUG" ] ; then
echo "++ $@" > /dev/stderr
if [ "$LUNAR_DEBUG" -ge "2" ] ; then
echo "++ $@" >> /tmp/lp_debuglog.$$
if [ -f /tmp/l_debug_var.$$ ] ; then
mv /tmp/l_debug_var.$$ /tmp/l_debug_var.$$.old
fi
set | grep '^[A-Z]' | sed 's/^/VAR /' > /tmp/l_debug_var.$$
diff -U0 /tmp/l_debug_var.$$.old /tmp/l_debug_var.$$ | \
grep -v "^@@" | grep "VAR" | tee -a /tmp/lp_debuglog.$$ > /dev/stderr
fi
fi
}
# function : report FILE [description] MODULE VERSION
report() {
debug_msg "report ($@)"
if [ ! -f "$1" ] ; then
return
fi
if [ "$VIEW_REPORTS" == "on" ] ; then
sound REPORT
if query "View $2 for ${MODULE_COLOR}${3}-${VERSION_COLOR}${4}${DEFAULT_COLOR}${QUERY_COLOR} ?" n ; then
view_file $1
fi
fi
if [ "$MAIL_REPORTS" == "on" ] ; then
TMP_MAIL=$(temp_create "mailreport")
date -u > $TMP_MAIL
echo >> $TMP_MAIL
view_file $1 >> $TMP_MAIL
mail -s "Lunar Report from $HOSTNAME : $2 for $3-$4" \
$ADMIN < $TMP_MAIL 2>/dev/null
temp_destroy $TMP_MAIL
fi
true
}
query() {
debug_msg "query ($@)"
# 2 arguments
# query "what do you want? " DEFAULT
if [ -z "$SILENT" ]; then
# message "Press y for yes, n for no."
if [ -n "$MODULE" ]; then
echo -e -n "${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}: "
echo -e -n "${QUERY_COLOR}$1 [$2] ${DEFAULT_COLOR}"
else
echo -e -n "${QUERY_COLOR}$1 [$2] ${DEFAULT_COLOR}"
fi
read -t $PROMPT_DELAY -n 1 RESPONSE
echo
RESPONSE=${RESPONSE:=$2}
case $RESPONSE in
y|Y) true ;;
*) false ;;
esac
else
echo $2
case $2 in
y|Y) true ;;
*) false ;;
esac
fi
}
color() {
debug_msg "color ($@)"
case $1 in
off) unset MODULE_COLOR
unset VERSION_COLOR
unset QUERY_COLOR
unset LRM_COLOR
unset CHECK_COLOR
unset RESURRECT_COLOR
unset FILE_COLOR
unset SYMLINK_COLOR
unset PROBLEM_COLOR
unset MESSAGE_COLOR
unset DEFAULT_COLOR
COLOR=off
;;
on) COLOR=on
;;
esac
}
sound() {
debug_msg "sound ($@)"
case $SOUND in
on) SOUND_FILE=$SOUND_DIRECTORY/$SOUND_THEME/$1
if [ -e "$SOUND_FILE" ] ; then
( cd / ; play $SOUND_FILE & )
fi
;;
esac
}
# function : show_fancy_progress
# usage : show_fancy_progress <fancy_progress_var_string>
# purpose : display progress ex: show_fancy_progress "Processing: $MODULE"
show_fancy_progress () {
debug_msg "show_fancy_progress ($@)"
echo -en "\r \r$1\r"
}
--- NEW FILE: misc.lunar ---
#!/bin/bash
# #
# misc.lunar - Lunar subroutines #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function : directories
# usage : VARIABLE=`directories < dirlistfile`
# purpose : to determine the directories from a given list
directories() {
debug_msg "directories ($@)"
while read ITEM ; do
if [ -d "$ITEM" ] && [ ! -h "$ITEM" ] ; then
echo "$ITEM"
fi
done
}
# function : files
# usage : VARIABLE=`files < dirlistfile`
# purpose : to determine the ordinary files from a given list
files() {
debug_msg "files ($@)"
while read ITEM ; do
if [ -f "$ITEM" ] && [ ! -h "$ITEM" ] ; then
echo "$ITEM"
fi
done
}
# function : sysmlinks
# usage : VARIABLE=`symlinks < dirlistfile`
# purpose : to determine the symbolic links from a given list
symlinks() {
debug_msg "symlinks ($@)"
while read ITEM ; do
if [ -h "$ITEM" ] ; then
echo "$ITEM"
fi
done
}
# function : dirnames
# usage : VARIABLE=`dirnames < dirlistfile`
# purpose : info about the real locations of symlinks
dirnames() {
debug_msg "dirnames ($@)"
while read FILE ; do
dirname "$FILE"
done
}
# function : exists
# usage : VARIABLE=`exists < dirlistfile`
# purpose : filter out the non-existent files in a list
exists() {
debug_msg "exists ($@)"
while read ITEM ; do
if [ -e "$ITEM" ] ; then
echo $ITEM
fi
done
}
# function : guess_filename
# usage : guess_filename <filename>
# purpose : fuzzy check for the existance of the filename
guess_filename() {
debug_msg "guess_filename ($@)"
FILENAME=$1
BASENAME=${FILENAME/.tar.gz/}
BASENAME=${BASENAME/.tar.bz2/}
BASENAME=${BASENAME/.tgz/}
if [ -f "$FILENAME" ] ; then
debug_msg "guess_filename: $FILENAME"
echo $FILENAME
elif [ "$FUZZY" == "off" ] ; then
return 1
elif [ -f "$BASENAME.tar.gz" ] ; then
debug_msg "guess_filename: $BASENAME.tar.gz"
echo $BASENAME.tar.gz
elif [ -f "$BASENAME.tar.bz2" ] ; then
debug_msg "guess_filename: $BASENAME.tar.bz2"
echo $BASENAME.tar.bz2
elif [ -f "$BASENAME.tgz" ] ; then
debug_msg "guess_filename: $BASENAME.tgz"
echo $BASENAME.tgz
else
return 1
fi
}
# function : filter
# usage : filter $FILE
# purpose : filter stdin with files/dirs/symlinks provided in file $1.
filter() {
debug_msg "filter ($@)"
if [ -f "$1" ] ; then
grep -v $(
for DIR in `directories < $1 2>/dev/null` ; do
echo -n "^$DIR\|"
done
for FILE in `files < $1 2>/dev/null` ; do
echo -n "^$FILE\$\|"
done
for SYM in `symlinks < $1 2>/dev/null` ; do
echo -n "^$SYM\$\|"
done
echo -n "/dev/null"
)
else
cat
fi
}
--- NEW FILE: modules.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/modules #
# includes create_module_index, find_section #
# list_sections, list_modules, list_installed #
# check_module_index, run_details #
# module_installed, module_held, module_exiled #
# hold_modules, unhold_modules #
# 20020528 #
# 20030113 merging more functions in here - sofar #
# 20030417 adding hold routines - sofar #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# Portions Copyrighted Chuck Mead 2002 under GPLv2 #
# Portions Copyrighted Auke Kok 2003 under GPLv2 #
# #
############################################################
# function : list_sections
# usage : list_sections
# purpose : list the moonbase sections, filter out the specific files
list_sections() {
debug_msg "list_sections ($@)"
check_module_index
SECTIONS=$(grep -v ^MOONBASE_MD5 $MODULE_INDEX 2>/dev/null | \
cut -d : -f 2-2 | sort | uniq)
if [ -n "$SECTIONS" ] ; then
echo "$SECTIONS"
return 0
fi
SECTIONS=$(ls $MOONBASE | grep -v -e "ChangeLog" -e "CVS" -e "COPYING" \
-e "LICENSE" -e "README")
if [ -n "$SECTIONS" ] ; then
echo "$SECTIONS"
return 0
fi
return 1
}
# function : list_modules
# usage : list_modules $SECTION
# purpose : list the modules in a section, filter out the specific files
list_modules() {
debug_msg "list_modules ($@)"
if [ -z "$1" ] ; then
message "${PROBLEM_COLOR}list_modules(): no SECTION defined!${DEFAULT_COLOR}"
exit 1
fi
for MODULE in $(( ls $MOONBASE/$1 && ls -d $MOONBASE/$1/*/[0-9]* |
sed "s:$MOONBASE/$1/::" ) 2>/dev/null | \
grep -v -e "ChangeLog" -e "CVS" -e "COPYING" -e "LICENSE" -e "README")
do
echo "$MODULE"
debug_msg "XXXX Module=$MODULE"
done
return 0
}
# function : list_moonbase
# usage : list_moonbase
# purpose : returns the names of all modules in moonbase
list_moonbase() {
debug_msg "list_moonbase ($@)"
for SECTION in $(list_sections) ; do
list_modules $SECTION
done
}
# function : list_installed
# usage : list_installed
# purpose : return a list of installed (or held) modules
list_installed() {
debug_msg "list_installed ($@)"
grep -e ":installed:" -e ":held:" $MODULE_STATUS | cut -d: -f1 | sort
}
# function: create_module_index
# usage : create_module_index
# purpose : created an index file of module:section pair list
create_module_index() {
debug_msg "create_module_index ($@)"
# make sure it exists before trying to see it's writeable
touch $MODULE_INDEX &> /dev/null
# silently fail if we cannot write to $MODULE_INDEX, it is okay
# for this to fail in case we are a mere user using lvu's search
# functionality
if [ ! -w "$MODULE_INDEX" ] ; then
return 0
fi
lock_file $MODULE_INDEX || return 1
rm -f $MODULE_INDEX 2>/dev/null
echo MOONBASE_MD5:`set_moonbase_md5` > $MODULE_INDEX
for SECTION in $(list_sections) ; do
list_modules $SECTION | sed "s/$/:$SECTION/" >> $MODULE_INDEX
done
unlock_file $MODULE_INDEX
}
# function: check_module_index
# usage : check_module_index
# purpose : checks if the index is up-to-date regarding to moonbase
function check_module_index() {
debug_msg "function check_module_index ($@)"
if [ $(get_moonbase_md5) != $(set_moonbase_md5) ] ; then
create_module_index
return 0
else
return 1
fi
}
# function : find_section
# usage : find_section "module name"
# purpose : finds the section of a given module as parameter
# returns : (0) on success, (1) on failure, errors on stdout
find_section() {
debug_msg "find_section ($@)"
ZLOCAL_OVERRIDES=${ZLOCAL_OVERRIDES:=off}
if [ "$ZLOCAL_OVERRIDES" == "on" ] ; then
if [ -d "$MOONBASE/zlocal/$1" ] ; then
echo "zlocal"
return 0
fi
fi
SECTION=$(grep ^$1: $MODULE_INDEX 2>/dev/null | head -n 1 | cut -d: -f2)
if [ -n "$SECTION" ] ; then
if [ -d "$MOONBASE/$SECTION/$1" ] ; then
echo "$SECTION"
return 0
fi
fi
check_module_index
SECTION=$(grep ^$1: $MODULE_INDEX 2>/dev/null | head -n 1 | cut -d: -f2)
if [ -n "$SECTION" ] ; then
if [ -d "$MOONBASE/$SECTION/$1" ] ; then
echo "$SECTION"
return 0
fi
fi
for SECTION in $(list_sections) ; do
if [ -n "$(list_modules $SECTION | grep ^$MODULE$ )" ] ; then
echo "$SECTION"
return 0
fi
done
return 1
}
# function : run_details
# usage : run_details module_name ($MODULE is pre-defined or param)
# purpose : runs the DETAILS file of a module
# returns : (0) on success, (1) on failure, error messages on stdout
run_details() {
debug_msg "run_details ($@)"
# Note: run_details doesn't EXIT the code, but merely drops a warning
# (return 1), which means that the calling code needs to decide
# if this is a problem or not... -sofar
if ! SECTION=$(find_section $1) ; then
message "${PROBLEM_COLOR}Unable to find module ${MODULE_COLOR}${1}${DEFAULT_COLOR}" \
"${PROBLEM_COLOR}in ${FILE_COLOR}$MOONBASE${DEFAULT_COLOR}"
return 1
else
if [ ! -f "$MOONBASE/$SECTION/$1/DETAILS" ] ; then
message "${PROBLEM_COLOR}Module ${MODULE_COLOR}${1}" \
"${DEFAULT_COLOR}${PROBLEM_COLOR}has no ${FILE_COLOR}DETAILS" \
"${DEFAULT_COLOR}${PROBLEM_COLOR}file!${DEFAULT_COLOR}"
return 1
fi
SCRIPT_DIRECTORY=$MOONBASE/$SECTION/$1
run_module_file $1 DETAILS &> /dev/null &&
SOURCE_DIRECTORY=${SOURCE_DIRECTORY:-$BUILD_DIRECTORY/$1-$VERSION}
MOD_SNAME=$(echo $1 | sed 's:/:.:g')
MODULE_CONFIG=${MODULE_CONFIG:-$DEPENDS_CONFIG/$MOD_SNAME}
return 0
fi
}
# function : run_module_file
# usage : run_module_file $MODULE $SCRIPTNAME
# purpose : runs the given script for a pre-defined module
run_module_file() {
debug_msg "run_module_file ($@)"
if [ -z "$SCRIPT_DIRECTORY" ] ; then
if ! run_details $1 &> /dev/null ; then
return 1
fi
fi
if [ -e "$SCRIPT_DIRECTORY/$2" ] ; then
. $SCRIPT_DIRECTORY/$2
fi
}
# function : module_installed
# usage : module_installed $MODULE
# purpose : check if $MODULE is installed (or held)
module_installed() {
$(cat $MODULE_STATUS | cut -d: -f1,3 | grep -q -e "^$1:installed" -e "^$1:held")
}
# function : module_held
# usage : module_held $MODULE
# purpose : check if $MODULE is held
module_held() {
debug_msg "module_held ($@)"
$(cat $MODULE_STATUS | cut -d: -f1,3 | grep -q "^$1:held")
}
# function : module_exiled
# usage : module_exiled $MODULE
# purpose : check if $MODULE is exiled
module_exiled() {
debug_msg "module_exiled ($@)"
$(cat $MODULE_STATUS | cut -d: -f1,3 | grep -q "^$1:exiled")
}
# function : installed_version
# usage : installed_version $MODULE
# purpose : return the installed version of $MODULE
installed_version() {
debug_msg "installed_version ($@)"
grep "^$1:" $MODULE_STATUS | cut -d: -f4
}
# function : hold_modules
# usage : hold_modules $MODULE [$MODULE....]
# purpose : put modules on hold
hold_modules() {
debug_msg "hold_modules ($@)"
if [ -n "$1" ] ; then
lock_file $MODULE_STATUS_BACKUP
lock_file $MODULE_STATUS
for MODULE in "$@" ; do
grep -v "^$MODULE:" $MODULE_STATUS > $MODULE_STATUS_BACKUP
grep "^$MODULE:" $MODULE_STATUS | sed "s:installed:held:" >> $MODULE_STATUS_BACKUP
cp $MODULE_STATUS_BACKUP $MODULE_STATUS
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
fi
}
# function : unhold_modules
# usage : unhold_modules $MODULE [$MODULE....]
# purpose : put modules on hold back to normal
unhold_modules () {
debug_msg "unhold_modules ($@)"
if [ -n "$1" ] ; then
lock_file $MODULE_STATUS_BACKUP
lock_file $MODULE_STATUS
for MODULE in "$@" ; do
grep -v "^$MODULE:" $MODULE_STATUS > $MODULE_STATUS_BACKUP
grep "^$MODULE:" $MODULE_STATUS | sed "s:held:installed:" >> $MODULE_STATUS_BACKUP
cp $MODULE_STATUS_BACKUP $MODULE_STATUS
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
fi
}
# function : exile_modules
# usage : exile_modules $MODULE [$MODULE....]
# purpose : put modules on exile
exile_modules() {
debug_msg "exile_modules ($@)"
if [ -n "$1" ] ; then
lock_file $MODULE_STATUS_BACKUP
lock_file $MODULE_STATUS
for MODULE in "$@" ; do
grep -v "^$MODULE:" $MODULE_STATUS > $MODULE_STATUS_BACKUP
grep "^$MODULE:" $MODULE_STATUS | sed "s:installed:exiled:" >> $MODULE_STATUS_BACKUP
cp $MODULE_STATUS_BACKUP $MODULE_STATUS
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
fi
}
# function : unexile_modules
# usage : unexile_modules $MODULE [$MODULE....]
# purpose : put modules on exile back to normal
unexile_modules () {
debug_msg "unexile_modules ($@)"
if [ -n "$1" ] ; then
lock_file $MODULE_STATUS_BACKUP
lock_file $MODULE_STATUS
for MODULE in "$@" ; do
grep -v "^$MODULE:" $MODULE_STATUS > $MODULE_STATUS_BACKUP
grep "^$MODULE:" $MODULE_STATUS | sed "s:exiled:installed:" >> $MODULE_STATUS_BACKUP
cp $MODULE_STATUS_BACKUP $MODULE_STATUS
done
unlock_file $MODULE_STATUS
unlock_file $MODULE_STATUS_BACKUP
fi
}
module_needs_update () {
debug_msg "module_needs_update ($@)"
if [ -n "$1" ] ; then
:
else
return 1
fi
}
--- NEW FILE: moonbase.lunar ---
#!/bin/bash
# #
# moonbase.lunar - get moonbase from the net #
# #
############################################################
# #
# Copyrighted Auke Kok 2002 under GPLv2 #
# #
############################################################
get_moonbase () {
(
debug_msg "get_moonbase ($@)"
SYSTEM_MOONBASE=/var/lib/lunar/moonbase
# the following overrides run_details:
run_details() {
debug_msg " run_details ($@)"
MODULE=moonbase
VERSION=`date -u +%Y%m%d.%H`
SOURCE=$(basename $MOONBASE_URL)
SOURCE_URL=${MOONBASE_URL[@]}
FUZZY=off
PARTIAL=off
CLEAR_CACHE=on
}
# make sure we set these values up front to be sure
run_details
rm -f /tmp/$SOURCE
if [ ! -d "$SYSTEM_MOONBASE" ] ; then
mkdir -p $SYSTEM_MOONBASE
fi
if [ ! -d "$SYSTEM_MOONBASE/zlocal" ] ; then
mkdir -p $SYSTEM_MOONBASE/zlocal
fi
push_uniq_id
if download_module $MODULE ; then
echo -e "${MESSAGE_COLOR}Preparing to install ${FILE_COLOR}${SOURCE}" \
"${DEFAULT_COLOR}${MESSAGE_COLOR}...${DEFAULT_COLOR}" &&
mv $SYSTEM_MOONBASE/zlocal/ /var/lib/lunar/.zlocal-backup &&
rm -rf $SYSTEM_MOONBASE &&
mkdir $SYSTEM_MOONBASE &&
mv /var/lib/lunar/.zlocal-backup $SYSTEM_MOONBASE/zlocal &&
echo -e "${MESSAGE_COLOR}Extracting ${FILE_COLOR}${SOURCE}" \
"${DEFAULT_COLOR}${MESSAGE_COLOR}...${DEFAULT_COLOR}" &&
bzcat $SOURCE_CACHE/$SOURCE | tar xv -C /var/lib/lunar | \
sed "s:^:/var/lib/lunar/:g" > $INSTALL_LOGS/$MODULE-$VERSION &&
echo $INSTALL_LOGS/$MODULE-$VERSION >> $INSTALL_LOGS/$MODULE-$VERSION &&
OUTCOME=success || OUTCOME=failed
echo -e "${MESSAGE_COLOR}Created ${FILE_COLOR}$INSTALL_LOGS/$MODULE-$VERSION" \
"${DEFAULT_COLOR}${MESSAGE_COLOR}${DEFAULT_COLOR}"
add_module $MODULE installed $VERSION $(du -hs $SYSTEM_MOONBASE | cut -f1)
# get ready to regenerate the module index cache file
TMP_MODULE_INDEX=$(temp_create "module-index")
cp $MODULE_INDEX $TMP_MODULE_INDEX
if [ -f "$MODULE_INDEX" ]; then
rm -f $MODULE_INDEX
fi
create_module_index
echo -e "${MESSAGE_COLOR}Created ${FILE_COLOR}${MODULE_INDEX}" \
"${DEFAULT_COLOR}${MESSAGE_COLOR}${DEFAULT_COLOR}"
display_moonbase_changes
else
OUTCOME=failed
INFO="Could not download a fresh moonbase"
fi
activity_log "lin" "moonbase" "$VERSION" "$OUTCOME" "$INFO"
)
}
# function : set_moonbase_md5
# usage : set_moonbase_md5
# purpose : creates the md5 value of overall moonbase
set_moonbase_md5() {
debug_msg "set_moonbase_md5 ($@)"
MOONBASE_MD5=$(echo $MOONBASE/*/* | md5sum | cut -d "-" -f 1-1)
echo $MOONBASE_MD5
}
# function : get_moonbase_md5
# usage : get_moonbase_md5
# purpose : graps the MOONBASE_MD5 line from the $MODULE_INDEX
get_moonbase_md5() {
debug_msg "get_moonbase_md5 ($@)"
MOONBASE_MD5=$(grep ^MOONBASE_MD5: $MODULE_INDEX | tail -1 2>/dev/null | \
cut -d : -f 2-2)
if [ -z "$MOONBASE_MD5" ] ; then
MOONBASE_MD5="0"
fi
echo "$MOONBASE_MD5"
}
--- NEW FILE: optimize.lunar ---
#!/bin/bash
# All specified optimizations are system wide,
# and apply to any module built using lin.
# All settings in this function may be adjusted
# in each modules BUILD script.
# $PLATFORM = This sets the platform (x86, Sparc, PPC, etc..)
# specific optimizations for the machine
# $BOPT = This sets the base optimizations (the -O level)
# it is applicable to all platforms and cpu types.
# $CPU = This sets the specific cpu and arch type.
# $SPD = This sets options that can increase the speed
# of compiled binaries.
# $XTRA = This specifies what type of extra instructions
# to use for the specified cpu and platform.
# $FPM = This sets the Floating Point Math use
# of SSE instructions.
# $LDF = This sets the system wide linking optimizations.
# Usage : bad_flags "list of flags to remove"
# Example : bad_flags -ffast-math -funroll-loops
bad_flags() {
debug_msg "bad_flags ($@)"
verbose_msg "bad_flags \"$@\""
if [[ "$1" == "ALL" ]]; then
unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
elif [[ "$1" == "compiler" ]]; then
unset CFLAGS CXXFLAGS CPPFLAGS
elif [[ "$1" == "linker" ]]; then
unset LDFLAGS
else
for BAD_FLAG in "$@" ; do
CFLAGS=$(echo $CFLAGS | sed s/$BAD_FLAG//)
CXXFLAGS=$(echo $CXXFLAGS | sed s/$BAD_FLAG//)
CPPFLAGS=$(echo $CPPFLAGS | sed s/$BAD_FLAG//)
LDFLAGS=$(echo $LDFLAGS | sed s/$BAD_FLAG//)
done
fi
}
use_wrappers() {
debug_msg "use_wrappers ($@)"
if [ "$GCCWRAPPERS" == "on" ] ; then
verbose_msg "Enabling gcc wrapper scripts to force optimizations"
export PATH=/var/lib/lunar/compilers:${PATH}
fi
}
optimize_make() {
debug_msg "optimize_make ($@)"
if [ "$PSAFE" == "no" ] ; then
unset MAKES
elif [ "$MAKES" == "1" ] ; then
unset MAKES
fi
if module_installed linux-openmosix; then
alias make="mosrun -h make"
if [[ "$MAKES" > 1 ]] ; then
alias make="mosrun -h make -j$MAKES"
fi
elif [[ $MAKES > 1 ]] ; then
alias make="make -j$MAKES"
fi
verbose_msg "make=\"$(which make)\", MAKES=\"$MAKES\""
}
optimize_base() {
debug_msg "optimize_base ($@)"
if ! [ "$1" ] ; then
BOPT="None"
fi
if [[ $CFLAGS ]]; then
unset CFLAGS CXXFLAGS
fi
case $1 in
None) CFLAGS="-O0"
CXXFLAGS="-O0"
;;
Fast) CFLAGS="-O1"
CXXFLAGS="-O1"
;;
Faster) CFLAGS="-O2"
CXXFLAGS="-O2"
;;
Fastest) CFLAGS="-O3"
CXXFLAGS="-O3"
;;
Small) CFLAGS="-Os"
CXXFLAGS="-Os"
;;
esac
}
optimize_cpu() {
debug_msg "optimize_cpu ($@)"
if ! [[ $1 ]]; then
if [[ $PLATFORM == "Alpha" ]]; then
CPU="ev4"
elif [[ $PLATFORM == "PowerPC" ]]; then
CPU="powerpc"
elif [[ $PLATFORM == "SPARC" ]]; then
CPU="ultrasparc"
else
CPU="I386"
fi
fi
# Begin x86 options
case $1 in
I386) CFLAGS="$CFLAGS -mcpu=i386 -march=i386"
CXXFLAGS="$CXXFLAGS -mcpu=i386 -march=i386"
BUILD="i386-pc-linux-gnu"
;;
I486) CFLAGS="$CFLAGS -mcpu=i486 -march=i486"
CXXFLAGS="$CXXFLAGS -mcpu=i486 -march=i486"
BUILD="i486-pc-linux-gnu"
;;
I586) CFLAGS="$CFLAGS -mcpu=i586 -march=i586"
CXXFLAGS="$CXXFLAGS -mcpu=i586 -march=i586"
BUILD="i586-pc-linux-gnu"
;;
I686) CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
;;
Pentium) CFLAGS="$CFLAGS -mcpu=pentium -march=pentium"
CXXFLAGS="$CXXFLAGS -mcpu=pentium -march=pentium"
BUILD="i586-pc-linux-gnu"
;;
PentiumMMX) CFLAGS="$CFLAGS -mcpu=pentium-mmx -march=pentium-mmx"
CXXFLAGS="$CXXFLAGS -mcpu=pentium-mmx -march=pentium-mmx"
BUILD="i586-pc-linux-gnu"
;;
PentiumPro) CFLAGS="$CFLAGS -mcpu=pentiumpro -march=pentiumpro"
CXXFLAGS="$CXXFLAGS -mcpu=pentiumpro -march=pentiumpro"
BUILD="i686-pc-linux-gnu"
;;
Pentium2) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=pentium2 -march=pentium2"
CXXFLAGS="$CXXFLAGS -mcpu=pentium2 -march=pentium2"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
Pentium3) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=pentium3 -march=pentium3"
CXXFLAGS="$CXXFLAGS -mcpu=pentium3 -march=pentium3"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
Pentium4) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=pentium4 -march=pentium4"
CXXFLAGS="$CXXFLAGS -mcpu=pentium4 -march=pentium4"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
K6) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=k6 -march=k6"
CXXFLAGS="$CXXFLAGS -mcpu=k6 -march=k6"
BUILD="i586-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i586 -march=i586"
CXXFLAGS="$CXXFLAGS -mcpu=k6 -march=k6"
BUILD="i586-pc-linux-gnu"
fi
;;
K62) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=k6-2 -march=k6-2"
CXXFLAGS="$CXXFLAGS -mcpu=k6-2 -march=k6-2"
BUILD="i586-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i586"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i586"
BUILD="i586-pc-linux-gnu"
fi
;;
K63) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=k6-3 -march=k6-3"
CXXFLAGS="$CXXFLAGS -mcpu=k6-3 -march=k6-3"
BUILD="i586-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i586"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i586"
BUILD="i586-pc-linux-gnu"
fi
;;
Athlon) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=athlon -march=athlon"
CXXFLAGS="$CXXFLAGS -mcpu=athlon -march=athlon"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
AthlonTBird) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=athlon-tbird -march=athlon-tbird"
CXXFLAGS="$CXXFLAGS -mcpu=athlon-tbird -march=athlon-tbird"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
Athlon4) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=athlon-4 -march=athlon-4"
CXXFLAGS="$CXXFLAGS -mcpu=athlon-4 -march=athlon-4"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
AthlonXP) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=athlon-xp -march=athlon-xp"
CXXFLAGS="$CXXFLAGS -mcpu=athlon-xp -march=athlon-xp"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
AthlonMP) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mcpu=athlon-mp -march=athlon-mp"
CXXFLAGS="$CXXFLAGS -mcpu=athlon-mp -march=athlon-mp"
BUILD="i686-pc-linux-gnu"
else
CFLAGS="$CFLAGS -mcpu=i686 -march=i686"
CXXFLAGS="$CXXFLAGS -mcpu=i686 -march=i686"
BUILD="i686-pc-linux-gnu"
fi
;;
# Begin PowerPC options
common) CFLAGS="$CFLAGS -mcpu=common"
CXXFLAGS="$CXXFLAGS -mcpu=common"
BUILD="power-linux"
;;
rios) CFLAGS="$CFLAGS -mcpu=rios"
CXXFLAGS="$CXXFLAGS -mcpu=rios"
BUILD="power-linux"
;;
rios1) CFLAGS="$CFLAGS -mcpu=rios1"
CXXFLAGS="$CXXFLAGS -mcpu=rios1"
BUILD="power-linux"
;;
rsc) CFLAGS="$CFLAGS -mcpu=rsc"
CXXFLAGS="$CXXFLAGS -mcpu=rsc"
BUILD="power-linux"
;;
rios2) CFLAGS="$CFLAGS -mcpu=rios2"
CXXFLAGS="$CXXFLAGS -mcpu=rios2"
BUILD="power-linux"
;;
rs64a) CFLAGS="$CFLAGS -mcpu=rs64a"
CXXFLAGS="$CXXFLAGS -mcpu=rs64a"
BUILD="powerpc64-linux"
;;
403) CFLAGS="$CFLAGS -mcpu=403"
CXXFLAGS="$CXXFLAGS -mcpu=403"
BUILD="powerpc-linux"
;;
505) CFLAGS="$CFLAGS -mcpu=505"
CXXFLAGS="$CXXFLAGS -mcpu=505"
BUILD="powerpc-linux"
;;
601) CFLAGS="$CFLAGS -mcpu=601"
CXXFLAGS="$CXXFLAGS -mcpu=601"
BUILD="powerpc-linux"
;;
602) CFLAGS="$CFLAGS -mcpu=602"
CXXFLAGS="$CXXFLAGS -mcpu=602"
BUILD="powerpc-linux"
;;
603) CFLAGS="$CFLAGS -mcpu=603"
CXXFLAGS="$CXXFLAGS -mcpu=603"
BUILD="powerpc-linux"
;;
603e) CFLAGS="$CFLAGS -mcpu=603e"
CXXFLAGS="$CXXFLAGS -mcpu=603e"
BUILD="powerpc-linux"
;;
604) CFLAGS="$CFLAGS -mcpu=604"
CXXFLAGS="$CXXFLAGS -mcpu=604"
BUILD="powerpc-linux"
;;
604e) CFLAGS="$CFLAGS -mcpu=604e"
CXXFLAGS="$CXXFLAGS -mcpu=604e"
BUILD="powerpc-linux"
;;
620) CFLAGS="$CFLAGS -mcpu=620"
CXXFLAGS="$CXXFLAGS -mcpu=620"
BUILD="powerpc64-linux"
;;
630) CFLAGS="$CFLAGS -mcpu=630"
CXXFLAGS="$CXXFLAGS -mcpu=630"
BUILD="powerpc-linux"
;;
740) CFLAGS="$CFLAGS -mcpu=740"
CXXFLAGS="$CXXFLAGS -mcpu=740"
BUILD="powerpc-linux"
;;
7400) CFLAGS="$CFLAGS -mcpu=7400"
CXXFLAGS="$CXXFLAGS -mcpu=7400"
BUILD="powerpc-linux"
;;
7450) CFLAGS="$CFLAGS -mcpu=7450"
CXXFLAGS="$CXXFLAGS -mcpu=7450"
BUILD="powerpc-linux"
;;
750) CFLAGS="$CFLAGS -mcpu=750"
CXXFLAGS="$CXXFLAGS -mcpu=750"
BUILD="powerpc-linux"
;;
801) CFLAGS="$CFLAGS -mcpu=801"
CXXFLAGS="$CXXFLAGS -mcpu=801"
BUILD="powerpc-linux"
;;
821) CFLAGS="$CFLAGS -mcpu=821"
CXXFLAGS="$CXXFLAGS -mcpu=821"
BUILD="powerpc-linux"
;;
823) CFLAGS="$CFLAGS -mcpu=823"
CXXFLAGS="$CXXFLAGS -mcpu=823"
BUILD="powerpc-linux"
;;
860) CFLAGS="$CFLAGS -mcpu=860"
CXXFLAGS="$CXXFLAGS -mcpu=860"
BUILD="powerpc-linux"
;;
power) CFLAGS="$CFLAGS -mcpu=power"
CXXFLAGS="$CXXFLAGS -mcpu=power"
BUILD="power-linux"
;;
power2) CFLAGS="$CFLAGS -mcpu=power2"
CXXFLAGS="$CXXFLAGS -mcpu=power2"
BUILD="power-linux"
;;
PowerPC) CFLAGS="$CFLAGS -mcpu=powerpc"
CXXFLAGS="$CXXFLAGS -mcpu=powerpc"
BUILD="powerpc-linux"
;;
# Begin Alpha options
ev4) CFLAGS="$CFLAGS -mcpu=ev4"
CXXFLAGS="$CXXFLAGS -mcpu=ev4"
BUILD="alpha-linux"
;;
ev45) CFLAGS="$CFLAGS -mcpu=ev4"
CXXFLAGS="$CXXFLAGS -mcpu=ev4"
BUILD="alpha-linux"
;;
ev5) CFLAGS="$CFLAGS -mcpu=ev5"
CXXFLAGS="$CXXFLAGS -mcpu=ev5"
BUILD="alpha-linux"
;;
ev56) CFLAGS="$CFLAGS -mcpu=ev56"
CXXFLAGS="$CXXFLAGS -mcpu=ev56"
BUILD="alpha-linux"
;;
pca56) CFLAGS="$CFLAGS -mcpu=pca56"
CXXFLAGS="$CXXFLAGS -mcpu=pca56"
BUILD="alpha-linux"
;;
ev6) CFLAGS="$CFLAGS -mcpu=ev6"
CXXFLAGS="$CXXFLAGS -mcpu=ev6"
BUILD="alpha-linux"
;;
ev67) CFLAGS="$CFLAGS -mcpu=ev67"
CXXFLAGS="$CXXFLAGS -mcpu=ev67"
BUILD="alpha-linux"
;;
ev68) CFLAGS="$CFLAGS -mcpu=ev67"
CXXFLAGS="$CXXFLAGS -mcpu=ev67"
BUILD="alpha-linux"
;;
# Begin SPARC options
v7) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
cypress) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
v8) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
super-sparc) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
sparclite) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
hypersparc) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
sparclite86x) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
f930) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
f934) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
sparclet) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
tsc701) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
v9) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
ultrasparc) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
BUILD=""
;;
esac
}
optimize_speed() {
debug_msg "optimize_speed ($@)"
for A in ${SPD[@]}; do
case $A in
None) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
;;
Speedy) CFLAGS="$CFLAGS -funroll-loops"
CXXFLAGS="$CXXFLAGS -funroll-loops"
;;
Risky) CFLAGS="$CFLAGS -ffast-math"
CXXFLAGS="$CXXFLAGS -ffast-math"
;;
Pointers) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fomit-frame-pointer"
CXXFLAGS="$CXXFLAGS -fomit-frame-pointer"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Siblings) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -foptimize-sibling-calls"
CXXFLAGS="$CXXFLAGS"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Profiling) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fprofile-arcs"
CXXFLAGS="$CXXFLAGS -fprofile-arcs"
if ! [[ `grep KEEP_SOURCE=on /etc/lunar/local/config` ]]; then
echo "KEEP_SOURCE=yes" >> /etc/lunar/local/config
elif [[ `grep KEEP_SOURCE=off /etc/lunar/local/config` ]]; then
sedit "s/KEEP_SOURCE=off/KEEP_SOURCE=on/" /etc/lunar/local/config
fi
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Branching) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fbranch-probabilities"
CXXFLAGS="$CXXFLAGS -fbranch-probabilities"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Aliasing) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fstrict-aliasing"
CXXFLAGS="$CXXFLAGS -fstrict-aliasing"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Cprop) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fno-cprop-registers"
CXXFLAGS="$CXXFLAGS -fno-cprop-registers"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Float) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -ffloat-store"
CXXFLAGS="$CXXFLAGS -ffloat-store"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Address) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fforce-addr"
CXXFLAGS="$CXXFLAGS -fforce-addr"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Align) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -falign-functions -falign-loops -falign-jumps"
CXXFLAGS="$CXXFLAGS -falign-functions -falign-loops -falign-jumps"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Expensive) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -fexpensive-optimizations"
CXXFLAGS="$CXXFLAGS -fexpensive-optimizations"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Doubles) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -malign-double"
CXXFLAGS="$CXXFLAGS -malign-double"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
Tracer) if [[ $GCCVER == "3" ]] ; then
CFLAGS="$CFLAGS -ftracer"
CXXFLAGS="$CXXFLAGS -ftracer"
else
CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
fi
;;
esac
done
}
optimize_stack() {
debug_msg "optimize_stack ($@)"
if [[ $STACK > 0 ]] ; then
if [ $PLATFORM == "x86" ] ; then
STACK="-mpreferred-stack-boundary=$STACK"
fi
CFLAGS="$CFLAGS $STACK"
CXXFLAGS="$CXXFLAGS $STACK"
CPPFLAGS="$CPPFLAGS $STACK"
fi
}
optimize_extra() {
debug_msg "optimize_extra ($@)"
for A in ${XTRA[@]}; do
case $A in
None) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
;;
MMX) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mmmx"
CXXFLAGS="$CXXFLAGS -mmmx"
fi
;;
SSE) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -msse"
CXXFLAGS="$CXXFLAGS -msse"
fi
;;
SSE2) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -msse2"
CXXFLAGS="$CXXFLAGS -msse2"
fi
;;
dnow) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -m3dnow"
CXXFLAGS="$CXXFLAGS -m3dnow"
fi
;;
Altivec) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -maltivec"
CXXFLAGS="$CXXFLAGS -maltivec"
fi
;;
esac
done
}
# Set how floating point math is done
optimize_fp() {
debug_msg "optimize_fp ($@)"
case $1 in
x387) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mfpmath=387"
CXXFLAGS="$CXXFLAGS -mfpmath=387"
fi
;;
SSE) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mfpmath=sse"
CXXFLAGS="$CXXFLAGS -mfpmath=sse"
fi
;;
Both) if [[ $GCCVER == "3" ]]; then
CFLAGS="$CFLAGS -mfpmath=sse,387"
CXXFLAGS="$CXXFLAGS -mfpmath=sse,387"
fi
;;
None) CFLAGS="$CFLAGS"
CXXFLAGS="$CXXFLAGS"
;;
esac
}
# Set up the Linker optimizations
optimize_ld() {
debug_msg "optimize_ld ($@)"
if [[ $LDFLAGS ]]; then
unset LDFLAGS
fi
for A in ${LDF[@]}; do
case $A in
Strip) LDFLAGS="$LDFLAGS -s"
;;
# The Debug option breaks some modules (eg: tar and gzip, just to mention a
# few), so this option should either be removed, or remain "deactivated"
# untill this has been resolved but the hatch is that we don't know how many
# modules is affected by it... See bug No. 75. Or contact me (Niki Guldbran
# <nikig at vip.cybercity.dk>)
#
# Debug) LDFLAGS="$LDFLAGS -S"
# ;;
Combreloc) LDFLAGS="$LDFLAGS -z combreloc"
;;
esac
done
}
optimize_addon() {
debug_msg "optimize_addon ($@)"
if ! [[ `grep ADDON /etc/lunar/local/optimizations` ]]; then
echo ADDON=( None ) >> /etc/lunar/local/optimizations
ADDON=( None )
fi
for A in ${ADDON[@]}; do
case $A in
DistCC) if module_installed distcc; then
CC_EXT="$CC_EXT distcc"
CXX_EXT="$CXX_EXT distcc"
else
CC_EXT="$CC_EXT"
CXX_EXT="$CXX_EXT"
fi
;;
CCache) if module_installed ccache; then
CC_EXT="ccache $CC_EXT"
CXX_EXT="ccache $CXX_EXT"
else
CC_EXT="$CC_EXT"
CXX_EXT="$CXX_EXT"
fi
;;
GECC) CC_EXT="gecc"
CXX_EXT="gecc"
;;
esac
done
verbose_msg "CC_EXT=\"$CC_EXT\", CXX_EXT=\"$CXX_EXT\""
}
optimize_ccc_warn() {
debug_msg "optimize_ccc_warn ($@)"
for W in ${CCC_WARN[@]}; do
case $W in
Deprecated)
CXXFLAGS="$CXXFLAGS -Wno-deprecated"
CPPFLAGS="$CPPFLAGS -Wno-deprecated"
;;
esac
done
}
optimize() {
debug_msg "optimize ($@)"
# Source in the optimization settings if it exists.
if [ -s /etc/lunar/local/optimizations ] ; then
. /etc/lunar/local/optimizations
else
verbose_msg "initializing optimizations with hard-coded defaults"
echo -e PLATFORM=x86 '\n' \
BUILD=i386-pc-linux-gnu '\n' \
MAKES= '\n' \
COPT= '\n' \
CCOPT= '\n' \
BOPT=-O0 '\n' \
CPU=i386 '\n' \
SPD=( ) '\n' \
STACK= '\n' \
XTRA=( ) '\n' \
FPM= '\n' \
CC_WARN=( ) '\n' \
CCC_WARN=( ) '\n' \
LDF=( ) '\n' \
ADDON=( ) > /etc/lunar/local/optimizations
fi
#lets get the BUILD if it is not defined
[ -z "$BUILD" ] && optimize_cpu $CPU
[ -n "$BUILD" ] && export BUILD ||
echo "Set your optimization preferences via lunar"
unset CFLAGS CXXFLAGS LDFLAGS
case $PLATFORM in
x86) optimize_make $MAKES &&
optimize_base $BOPT &&
optimize_cpu $CPU &&
optimize_speed ${SPD[@]} &&
optimize_extra ${XTRA[@]} &&
optimize_stack &&
optimize_fp $FPM &&
optimize_ccc_warn &&
optimize_ld ${LDF[@]} &&
optimize_addon
;;
Alpha) optimize_make $MAKES &&
optimize_base $BOPT &&
optimize_cpu $CPU &&
optimize_speed ${SPD[@]} &&
optimize_extra ${XTRA[@]} &&
optimize_fp $FPM &&
optimize_ccc_warn &&
optimize_ld ${LDF[@]} &&
optimize_addon
;;
PowerPC) optimize_make $MAKES &&
optimize_base $BOPT &&
optimize_cpu $CPU &&
optimize_speed ${SPD[@]} &&
optimize_extra ${XTRA[@]} &&
optimize_fp $FPM &&
optimize_ccc_warn &&
optimize_ld ${LDF[@]} &&
optimize_addon
;;
SPARC) optimize_make $MAKES &&
optimize_base $BOPT &&
optimize_cpu $CPU &&
optimize_speed ${SPD[@]} &&
optimize_extra ${XTRA[@]} &&
optimize_fp $FPM &&
optimize_ccc_warn &&
optimize_ld ${LDF[@]} &&
optimize_addon
;;
esac
export CC_EXT
export CXX_EXT
export CFLAGS
export COPT
export CCOPT
export CXXFLAGS
export LDFLAGS
use_wrappers
verbose_msg "BUILD=\"$BUILD\""
verbose_msg "GCCVER=\"$GCCVER\""
verbose_msg "CFLAGS=\"$CFLAGS\""
verbose_msg "CXXFLAGS=\"$CXXFLAGS\""
verbose_msg "LDFLAGS=\"$LDFLAGS\""
}
# This is the flow control and error checking for the menus.
optimize_architecture() {
debug_msg "optimize_architecture ($@)"
# Make sure optimizations file exists, if not create it.
if ! [[ -f /etc/lunar/local/optimizations ]]; then
touch /etc/lunar/local/optimizations
fi
# Make sure our menu script exists and source it in, or exit.
if [[ -f /var/lib/lunar/menu/optimize.menu ]]; then
. /var/lib/lunar/menu/optimize.menu
else
exit 0
fi
if [ -f /etc/lunar/local/optimizations ] ; then
. /etc/lunar/local/optimizations
fi
# Flow control for the menus. This will also check for gcc3,
# if it exists it will allow more options.
TITLE="Lunar Optimizations"
help compiler_help &&
compiler_options &&
menu radiolist &&
COMPILER=$RESULT
help cc_help &&
cc_options &&
menu checklist &&
COPT=$RESULT
help ccc_help &&
ccc_options &&
menu checklist &&
CCOPT=$RESULT
help platform_help &&
platform_options &&
menu radiolist &&
PLATFORM=$RESULT
help bopt_help &&
bopt_options &&
menu radiolist &&
BOPT=$RESULT
help cpu_help $PLATFORM &&
cpu_options $PLATFORM &&
menu radiolist &&
CPU=$RESULT
optimize_cpu $CPU &&
BUILD=$BUILD
help spd_help &&
spd_options &&
menu checklist &&
SPD=( $RESULT )
help xtra_help &&
xtra_options &&
menu checklist &&
XTRA=( $RESULT )
help fpm_help &&
fpm_options &&
menu radiolist &&
FPM=$RESULT
help ccc_warn_help &&
ccc_warn &&
menu checklist &&
CCC_WARN=$RESULT
help ldf_help &&
ldf_options &&
menu checklist &&
LDF=( $RESULT )
help addon_help &&
addon_options &&
menu checklist &&
ADDON=( $RESULT )
MAKES=`dialog --title "Make - parallellizing" \
--nocancel \
--stdout \
--inputbox \
"Enter the number of concurrent makes ( >= 1 ). Hint: how many CPU's do you have?" \
0 55 $MAKES`
STACK=`dialog --title "Set stack parameters. (WARNING! Best left empty!)" \
--nocancel \
--stdout \
--inputbox \
"Enter the number to set the stack to, leave empty for default." \
0 55 $STACK`
optimize
}
--- NEW FILE: postbuild.lunar ---
#!/bin/bash
# #
# postbuild.lunar - Lunar install extensions #
# #
############################################################
# #
# parts of these functions come from subroutines and were #
# part of sorcerer GNU/Linux. SGL is no longer #
# available with GPL license. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Parts Copyrighted Kyle Sallee 2001 #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
# Parts Copyrighted Auke Kok 2002 under GPLv2 #
# #
############################################################
gather_docs() {
debug_msg "gather_docs ($@)"
[ "$GARBAGE" == "on" ] || return 0
DOC_DIR=$DOCUMENT_DIRECTORY/$MODULE
mkdir -p $DOC_DIR
if [ -d "$SOURCE_DIRECTORY" ] ; then
( cd $SOURCE_DIRECTORY && for FILE in \
README* INSTALL* FAQ* CHAN* doc* DOC* *doc *sample* \
conf SETUP NEWS Change* manual* Manual* ; do
[ -e $FILE ] && {
verbose_msg "installing docs: \"$DOC_DIR/$FILE\""
cp -ar $FILE $DOC_DIR 2> /dev/null
}
done
)
fi
}
install_pam_confs() {
debug_msg "install_pam_confs ($@)"
if [ -d "$SCRIPT_DIRECTORY/pam.d" ]; then
verbose_msg "handling pam config files"
cd "$SCRIPT_DIRECTORY/pam.d"
[ -d /etc/pam.d ] || mkdir -p /etc/pam.d
for FILE in [!CVS]* ; do
if ! [ -f /etc/pam.d/$FILE ]; then
/usr/bin/install -g 0 -o 0 -m 600 $FILE /etc/pam.d
cp $FILE /etc/pam.d
fi
done
fi
}
install_xinetd_confs() { (
unset IFS
debug_msg "install_xinetd_confs ($@)"
if [ -d "$SCRIPT_DIRECTORY/xinetd.d" ]; then
cd "$SCRIPT_DIRECTORY/xinetd.d"
verbose_msg "handling xinetd config files"
[ -d /etc/xinetd.d ] || mkdir -p /etc/xinetd.d
for SERVICE in $SERVICES; do
for FILE in [!CVS]* ; do
if grep -q "service $SERVICE" $FILE ; then
if [ ! -f /etc/xinetd.d/$FILE ] ; then
/usr/bin/install --backup=numbered -g 0 -o 0 -m 600 $FILE /etc/xinetd.d
fi
fi
done
done
if [ -n "$SERVICES" ]; then
devoke_installwatch
[ ! -x /etc/init.d/xinetd ] || /etc/init.d/xinetd restart
invoke_installwatch
fi
fi
) }
use_xinetd() {
debug_msg "use_xinetd ($@)"
if [ -d $SCRIPT_DIRECTORY/xinetd.d ] &&
! grep -q "SERVICES=" $MODULE_CONFIG
then
ALL_SERVICES=`cat $SCRIPT_DIRECTORY/xinetd.d/[!CVS]* |
grep "service" |
sed "s/service //"`
for SERVICE in $ALL_SERVICES ; do
if query "Invoke $SERVICE via xinetd?" y ; then
SERVICES="$SERVICE $SERVICES"
else
RETURN=1
fi
done
for SERVICE in $SERVICES; do
for FILE in $SCRIPT_DIRECTORY/xinetd.d/[!CVS]* ; do
if grep -q "service $SERVICE" $FILE &&
grep -q "stunnel" $FILE; then
add_depends "$MODULE" "stunnel" "on" "optional"
fi
done
done
if [ -n "$SERVICES" ] ; then
add_depends "$MODULE" "xinetd" "on" "optional"
else
add_depends "$MODULE" "xinetd" "off" "optional"
fi
echo "SERVICES=\"$SERVICES\"" >> $MODULE_CONFIG
if [ "$RETURN" == "1" ] ; then
return 1
else
return 0
fi
else
return 1
fi
}
install_initd() {
debug_msg "install_initd ($@)"
[ -d /etc/init.d ] || mkdir -p /etc/init.d
if [ -d $SCRIPT_DIRECTORY/init.d ] ; then
verbose_msg "handling init.d scripts" | tee -a $C_LOG
cd $SCRIPT_DIRECTORY/init.d
SCRIPTS=[!CVS]*
ALL_INITDSCRIPTS=$(grep -l "# chkconfig: " $SCRIPTS | cut -d/ -f2)
for INITDSCRIPT in $ALL_INITDSCRIPTS; do
if [ ! -f /etc/init.d/$INITDSCRIPT ] ; then
/usr/bin/install -g 0 -o 0 -m 700 $SCRIPT_DIRECTORY/init.d/$INITDSCRIPT /etc/init.d/
fi
done
cd $SCRIPT_DIRECTORY
fi
for INITDSCRIPT in $INITDSCRIPTS; do
ls /etc/rc?.d/???$INITDSCRIPT > /dev/null 2>&1 &&
rm -f /etc/rc?.d/???$INITDSCRIPT
chkconfig --add $INITDSCRIPT
CHKCONFIG=`grep '^# chkconfig:' /etc/init.d/$INITDSCRIPT | cut -d : -f 2-2`
if `echo $CHKCONFIG | grep -q $(/sbin/runlevel | cut -d ' ' -f 2-2) -`
then
devoke_installwatch
( cd / && /etc/init.d/$INITDSCRIPT stop )
( cd / && /etc/init.d/$INITDSCRIPT start )
invoke_installwatch
fi
done
}
use_initd() {
debug_msg "use_initd ($@)"
if [ -d $SCRIPT_DIRECTORY/init.d ] ; then
cd $SCRIPT_DIRECTORY/init.d
SCRIPTS=[!CVS]*
INITDSCRIPTS=$(grep -l "# chkconfig: " $SCRIPTS | cut -d/ -f2)
for INITDSCRIPT in $INITDSCRIPTS; do
if query "Invoke $INITDSCRIPT via init.d automatically at boot ?" y
then
INSTALLED_INIDSCRIPTS=$(echo $INSTALLED_INIDSCRIPTS $INITDSCRIPT)
else
if [ -f /etc/init.d/$INITDSCRIPT ] ;
then
chkconfig --del $INITDSCRIPT
ls /etc/rc?.d/???$INITDSCRIPT > /dev/null 2>&1 &&
rm -f /etc/rc?.d/???$INITDSCRIPT
fi
fi
done
cd $SCRIPT_DIRECTORY
echo "INITDSCRIPTS=\"$INSTALLED_INIDSCRIPTS\"" >> $MODULE_CONFIG
fi
}
install_services() {
debug_msg "install_services ($@)"
if [ -f $SCRIPT_DIRECTORY/services ]; then
export IFS="$ENTER_IFS"
cat $SCRIPT_DIRECTORY/services |
while read LINE; do
grep -q "$LINE" /etc/services ||
echo "$LINE" >> /etc/services
done
fi
}
install_bashmisc () {
debug_msg "install_bashmisc ($@)"
if [ -d $SCRIPT_DIRECTORY/profile.d ] ; then
[ -d /etc/profile.d ] || mkdir -p /etc/profile.d
install -g 0 -o 0 -m 644 $SCRIPT_DIRECTORY/profile.d/*.rc /etc/profile.d
message "\n${MESSAGE_COLOR}Please log out and log in again to make changes in your shell\nenvironment take effect.${DEFAULT_COLOR}\n"
fi
if [ -d $SCRIPT_DIRECTORY/skel ]; then
[ -d /etc/skel ] || mkdir -p /etc/skel
cp $SCRIPT_DIRECTORY/skel/[!CVS]* /etc/skel &> /dev/null
cp $SCRIPT_DIRECTORY/skel/.* /etc/skel &> /dev/null
fi
}
--- NEW FILE: prune.lunar ---
#!/bin/bash
# #
# prune.lunar - Lunar prune code #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function : generate_keep_list
# usage : generate_keep_list
# purpose : generated a list of files which will not be deleted with prune
generate_keep_list() {
debug_msg "generate_keep_list ($@)"
for MODULE in $(list_moonbase | sort); do
show_fancy_progress "Processing: $MODULE"
sources $MODULE >> $KEEP
VERSION=$(installed_version $MODULE)
if [ -z "$VERSION" ] ; then
VERSION=$(run_details $MODULE ; echo $VERSION)
fi
echo $MODULE-$VERSION-$BUILD.tar.bz2 >> $KEEP
done
echo README >> $KEEP
}
--- NEW FILE: queue.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/queue #
# includes add_queue and remove_queue #
# #
# 20020527 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# Definiton:
# a queue is a multielement data structure from which elements
# can be removed only in the same order in which they are inserted;
# that is, it follows a FIFO constraint.
# function: add_queue
# usage : add_queue <file_name> <item_name>
# purpose : adds an item to the end of a queue
add_queue() {
debug_msg "add_queue ($@)"
in_queue() {
debug_msg " in_queue ($@)"
grep -q "^"$2"\$" $1 && return 0 || return 1
}
[ "$#" -ne 2 ] && return 1
[ -f "$1" ] || touch $1 2>/dev/null || return 1
lock_file $1 &&
! in_queue $1 $2 && echo "$2" >> $1
unlock_file $1
}
# function: remove_queue
# usage : remove_queue <file_name> |name|
# purpose : removes an item from a queue OR pops the first element from a queue
remove_queue() {
debug_msg "remove_queue ($@)"
[ -f "$1" ] || return 1
if [ -n "$2" ];
then
TMP_QUEUE="/tmp/lunar_remove_queue.$$"
rm -f $TMP_QUEUE 2>/dev/null
lock_file $1 &&
cat $1 | grep -v "^"$2"\$" > $TMP_QUEUE
cat $TMP_QUEUE > $1
unlock_file $1
rm -f $TMP_QUEUE 2>/dev/null
else
lock_file $1 &&
echo `cat $1 | sed 1!d` &&
cat $1 | sed "1d" > $1 &&
unlock_file $1
fi
}
--- NEW FILE: recovery.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/recovery #
# includes rebuild_status_files, replace_status_file, #
# check_status_files #
# 20020528 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function : rebuild_status_files
# usage : rebuild_status_files
# purpose : rebuild the accidentally deleted status files
rebuild_status_files() {
debug_msg "rebuild_status_files ($@)"
message "${PROBLEM_COLOR} Unable to find MODULE_STATUS files\n" \
"${MODULE_COLOR}$MODULE_STATUS and $MODULE_STATUS_BACKUP" \
"${DEFAULT_COLOR}\n" \
"${PROBLEM_COLOR}This is a serious error!!\n\nInformation about" \
"the modules on hold CAN NOT be recovered.\nHowever, the files" \
"can be re-constructed.\nDo not forget to check your on hold " \
"modules!" \
"${DEFAULT_COLOR}\n"
if ! query \
"Do you want to re-construct the status files from install logs?" y; then
message "${PROBLEM_COLOR}Unable to continue without status files :=("\
"No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
if ! [ -d "$INSTALL_LOGS" ]; then
message "${PROBLEM_COLOR}Unable to continue without install logs :=("\
"No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
message "${MESSAGE_COLOR}Re-creating status files." \
"${DEFAULT_COLOR}" \
"${PROBLEM_COLOR}DO NOT BREAK!!" \
"${DEFAULT_COLOR}"
trap "" 2
LOG_FILES=`ls -rt $INSTALL_LOGS`
for MODULE_NAME in $LOG_FILES; do
let "COUNTS=3"
REAL_NAME=$MODULE_NAME
unset SECTION
while [ "$COUNTS" -gt "0" ]; do
REAL_NAME=`echo $REAL_NAME | cut -d "-" -f -"$COUNTS"`
SECTION=`find_section $REAL_NAME`
if [ -n "$SECTION" ]; then
let "COUNTS++"
VERSION=`echo $MODULE_NAME | cut -d "-" -f "$COUNTS"-`
add_module $REAL_NAME installed $VERSION
OUTTEXT="Processing: $REAL_NAME-$VERSION "
echo -en "$OUTTEXT"
for ((II=1; II<=${#OUTTEXT}; II++)); do echo -en "\b"; done
break;
fi
let "COUNTS--"
done
done
echo " "
cp $MODULE_STATUS $MODULE_STATUS_BACKUP
message "${MESSAGE_COLOR}Success!!" \
"${DEFAULT_COLOR}\n"
trap 2
}
# function : replace_status_file
# usage : replace_status_file
# purpose : cp $MODULE_STATUS_BACKUP $MODULE_STATUS via query
replace_status_file() {
debug_msg "replace_status_file ($@)"
if ! [ -f "$MODULE_STATUS_BACKUP" ]; then rebuild_status_files; return; fi
message "${PROBLEM_COLOR}Unable to find MODULE_STATUS file" \
"${MODULE_COLOR}$MODULE_STATUS" \
"${DEFAULT_COLOR}"
if query "Do you want to use the backup?" y; then
if ! [ -f "$MODULE_STATUS_BACKUP" ]; then rebuild_status_files; fi
if `cp $MODULE_STATUS_BACKUP $MODULE_STATUS`; then
message "${MESSAGE_COLOR}Success!!" \
"${DEFAULT_COLOR}"
else
message "${PROBLEM_COLOR}Unsuccessfull :=( No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
else
message "${PROBLEM_COLOR}Unable to continue without that :=("\
"No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
}
# function : check_status_files
# usage : check_status_files
# purpose : checks the avail of MODULE_STATUS and MODULE_STATUS_BACKUP files
check_status_files() {
debug_msg "check_status_files ($@)"
if ! [ -f "$MODULE_STATUS" ]; then replace_status_file; fi
if ! [ -f "$MODULE_STATUS" ]; then echo "Unknown error!!!"; exit; fi
if ! [ -f "$MODULE_STATUS_BACKUP" ]; then
message "${PROBLEM_COLOR}Unable to find MODULE_STATUS_BACKUP file" \
"${MODULE_COLOR}$MODULE_STATUS_BACKUP" \
"${DEFAULT_COLOR}"
if `cp $MODULE_STATUS $MODULE_STATUS_BACKUP`; then
message "${MESSAGE_COLOR}MODULE_STATUS is succesfully copied" \
"to MODULE_STATUS_BACKUP" \
"${DEFAULT_COLOR}"
else
message "${PROBLEM_COLOR}Unsuccessfull while copying" \
"MODULE_STATUS to MODULE_STATUS_BACKUP :=( " \
"No more operation!!" \
"${DEFAULT_COLOR}"
exit 1
fi
fi
}
--- NEW FILE: sizes.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/sizes #
# includes find_module_size #
# #
# 20020527 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
# function: find_module_size
# usage : find_module_size <module> |version|
# purpose : finds the installed size of module in KB
find_module_size() {
#this functions checks the modules file if there is already size entry
module_size()
{
unset SIZE
[ -e "$MODULE_STATUS" ] &&
SIZE=`grep "^$1\:" $MODULE_STATUS | cut -d ":" -f 5-5`
[ -n "$SIZE" ] && echo ${SIZE} || false
}
[ -z "$1" ] && return
[ -n "$2" ] && VERSION=$2 || VERSION=`installed_version $1`
[ -z "$VERSION" ] &&
message "${PROBLEM_COLOR}$1 is not installed${DEFAULT_COLOR}" &&
return
# yes, there is a size entry
module_size $1 $VERSION && return
# no :( lets dig through logs
[ -e "$INSTALL_LOGS/$1-$VERSION" ] &&
while read LINE
do
[ -f "$LINE" ] &&
SIZE0=`du "$LINE" |
cut -f 1-1` &&
SIZE=$((SIZE0+SIZE))
done <$INSTALL_LOGS/$1-$VERSION &&
echo ${SIZE}KB ||
message "${PROBLEM_COLOR}Install log for $1 is not found${DEFAULT_COLOR}"
}
--- NEW FILE: sources.lunar ---
#!/bin/bash
############################################################
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/sources #
# includes sources, md5_verify_source, verify_sources #
# verify_source #
# #
# 20020604 #
# #
############################################################
# #
# Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
verify_source() {
debug_msg "verify_source ($@)"
VERIFIED="true"
for SOURCE_FILE in $@ ; do
if ! guess_filename $SOURCE_CACHE/$1 >/dev/null ; then
message "${PROBLEM_COLOR}Missing ${FILE_COLOR}${1}${DEFAULT_COLOR}"
message "${PROBLEM_COLOR}Lunar Install aborting.${DEFAULT_COLOR}"
activity_log "lin" "$MODULE" "$VERSION" "failed" "because it was missing source: $1"
return 1
fi
done
}
# function : sources
# usage : sources <module_name> {MD5|VFY|
# purpose : displays the filenames and md5sums or VFY part of sources
# for a given module
sources() {
(
debug_msg "sources ($@)"
MAX_SOURCES=${MAX_SOURCES:=100}
if ! run_details $1 ; then
return 1
fi
for (( CNT=0; CNT<=$MAX_SOURCES; CNT++ )) ; do
TEMP=SOURCE$((CNT))
TEMP=${TEMP/SOURCE0/SOURCE}
eval SRC1=\$${TEMP}
if [ "$2" == "MD5" ] ; then
eval SRC_MD5=\$${TEMP}_MD5
if [ -z "$SRC_MD5" ] ; then
SRC_MD5=0
fi
fi
eval SRC2=\$SOURCE$((CNT+1))
eval SRC3=\$SOURCE$((CNT+2))
if [ -n "$SRC1" ] ; then
echo $SRC1
if [ "$2" == "MD5" ] ; then
echo $SRC_MD5
fi
fi
#if two consequtive empty sources, then break
[ -z "$SRC2" ] && [ -z "$SRC3" ] && {
break
}
done
)
}
# function : md5_verify_source
# usage : md5_verify_source filename md5
# purpose : md5 verifies a filename
md5_verify_source() {
debug_msg "md5_verify_source ($@)"
if [ "$2" != "$(md5sum $SOURCE_CACHE/$1 | cut -d " " -f 1-1)" ] ; then
return 1
fi
}
unpack() {
debug_msg "unpack ($@)"
FILENAME=$(guess_filename $SOURCE_CACHE/$1)
verbose_msg "Unpacking \"$FILENAME\" in \"$(pwd)\""
case $(file -b $FILENAME | cut -d' ' -f1) in
bzip2) tar jxf $FILENAME ;;
gzip) tar zxf $FILENAME ;;
tar) tar xf $FILENAME ;;
compress*) tar zxf $FILENAME ;;
Zip) unzip -q $FILENAME ;;
RPM) rpmunpack < $FILENAME | gzip -d \
| cpio -idm ;;
*) false ;;
esac
if [ "$?" != 0 ] ; then
message "${PROBLEM_COLOR}! Error while unpacking ${FILE_COLOR}$SOURCE_CACHE/$1${DEFAULT_COLOR}${PROBLEM_COLOR}${DEFAULT_COLOR}"
return 1
fi
[ -n "$SOURCE_DIRECTORY" ] &&
[ -d "$SOURCE_DIRECTORY" ]
if [[ $(echo $CFLAGS | grep fbranch-probabilities) ]]; then
chown -R 777 $SOURCE_DIRECTORY 2>&1 >/dev/null
else
chown -R root:root $SOURCE_DIRECTORY 2>&1 >/dev/null
fi
}
# usage : gpg_verify_src $SRC $GPG-SIG-URL $GPG-PUBLIC-KEYS-URL
gpg_verify_source() {
debug_msg "gpg_verify_source($@)"
if [ ! -x /usr/bin/gpg ] ; then
message "${PROBLEM_COLOR}! Cannot verify sources without ${MODULE_COLOR}gpg${DEFAULT_COLOR}${PROBLEM_COLOR} installed${DEFAULT_COLOR}"
return 1
fi
# do we need to download a keyset?
if [ -n "$3" ] ; then
TMP_GPG_KEYS=$(temp_create "gpg-pubkeys")
verbose_msg "Downloading pub keys from \"$3\""
# TODO calling wget is a hack... we should accept file: urls too
if wget $3 -O $TMP_GPG_KEYS -q ; then
GNUPGHOME=/var/state/lunar/ gpg --import $TMP_GPG_KEYS
fi
fi
# try to get the required key
TMP_GPG_SIG=$(temp_create "gpg-signature")
verbose_msg "Downloading signature \"$2\""
# TODO calling wget is a hack... we should accept file: urls too
if wget $2 -O $TMP_GPG_SIG -q ; then
verbose_msg "Verifying signature of \"$SOURCE_CACHE/$1\""
verbose_msg "GNUPGHOME=/var/state/lunar/ gpg --verify $TMP_GPG_SIG $SOURCE_CACHE/$1"
if ! GNUPGHOME=/var/state/lunar/ gpg --verify $TMP_GPG_SIG $SOURCE_CACHE/$1 ; then
verbose_msg "gpg exited with \"$?\""
temp_destroy $TMP_GPG_SIG
temp_destroy $TMP_GPG_KEYS
return 1
fi
temp_destroy $TMP_GPG_SIG
temp_destroy $TMP_GPG_KEYS
else
message "cannot download key!"
temp_destroy $TMP_GPG_SIG
temp_destroy $TMP_GPG_KEYS
return 1
fi
}
# usage: verify_all_sources $MODULE
# check all sources regarding verification method
verify_all_sources() {
(
debug_msg "verify_all_sources ($@)"
MAX_SOURCES=${MAX_SOURCES:=100}
if ! run_details $1 ; then
return 1
fi
for (( C=0 ; C<=$MAX_SOURCES ; C++ )) ; do
TEMP=SOURCE$((C))
TEMP=${TEMP/SOURCE0/SOURCE}
eval SRC1=\$${TEMP}
# it needs to exist prior before we can check it:
if ! verify_source $SRC1 ; then
return 1
fi
eval VFYS=\${${TEMP}_VFY[@]}
# cumulate result:
unset RESULT
if [ -n "$VFYS" ] ; then
# we need to check ALL args for validity... if one fails we should not
# trust the source
for VFY in $VFYS ; do
if [ "${VFY:0:4}" == "md5:" ] ; then
if ! md5_verify_source $SRC1 $(echo $VFY | cut -d: -f2) ; then
message "${PROBLEM_COLOR}!md5sum check failed for ${DEFAULT_COLOR}${FILE_COLOR}$SRC1${DEFAULT_COLOR}"
RESULT=1
fi
elif [ "${VFY:0:4}" == "gpg:" ] ; then
if ! gpg_verify_source $SRC1 $(echo $VFY | cut -d: -f2-3) $(echo $VFY | cut -d: -f4-5) ; then
message "${PROBLEM_COLOR}!gpg signature check failed for ${DEFAULT_COLOR}${FILE_COLOR}$SRC1${DEFAULT_COLOR}"
RESULT=1
fi
fi
# so what if?
if [ "$RESULT" == "1" ] ; then
# remove?
MODULE=$1
message "${MESSAGE_COLOR}You should remove ${DEFAULT_COLOR}${FILE_COLOR}$SRC1${DEFAULT_COLOR}${MESSAGE_COLOR} !${DEFAULT_COLOR}"
if query "Remove \"$SOURCE_CACHE/$SRC1\" ? " y ; then
rm -f $SOURCE_CACHE/$SRC1
fi
fi
done
fi
# our fallthrough as usual:
eval SRC2=\$SOURCE$((C+1));
eval SRC3=\$SOURCE$((C+2));
[ -z "$SRC2" ] && [ -z "$SRC3" ] && break
done
# result?
if [ -n "$RESULT" ] ; then
return 1
fi
# if we removed something we better make sure we break:
if ! verify_source $(sources $1) ; then
return 1
fi
)
}
--- NEW FILE: temp.lunar ---
#!/bin/bash
# #
# temp.lunar - lunar temp code handling #
# #
####################################################################
# #
# Copyright 2003 - Auke Kok under GPLv2 #
# #
####################################################################
# #
# temp.lunar contains uniform temporary file name creation and #
# tracking. All lunar tools MUST use these functions if they wish #
# to perform temporary file operations #
# #
# functions: temp_create, temp_destroy #
# #
####################################################################
temp_create() {
debug_msg "temp_create ($@)"
TMPDIR=${TMPDIR:-/var/tmp}
TMPFILE=$(echo $1 | sed 's:/:.:g')
if TMPFILE=$(mktemp -p "$TMPDIR" -t lunar.`basename $0`.$$.$TMPFILE.XXXXXXXXXX ) ; then
echo $TMPFILE
else
message "${PROBLEM_COLOR}ERROR:${NORMAL_COLOR}${DEFAULT_COLOR}" \
"Cannot create temp file${NORMAL_COLOR}"
exit 1
fi
}
temp_destroy() {
debug_msg "temp_destroy ($@)"
if [ -e "$1" ] ; then
rm -f "$1"
fi
}
--- NEW FILE: tracking.lunar ---
#!/bin/bash
# #
# subroutines - Lunar subroutines #
# #
############################################################
# #
# this WAS the subroutines of a source based Linux distro, #
# calls Sorcerer GNU/Linux, or SGL. SGL is no longer #
# available with GPL license. Since this script was taken #
# before licensing scheme change, no legal problems I #
# guess. #
# #
# the code is re-written for Lunar. The previous Copyright #
# notices are kept; just in case some code is left :=) #
# Kagan Kongar <kongar at tsrsb.org.tr>, 20020519 #
# #
############################################################
# #
# Copyright 2001 by Kyle Sallee #
# #
# Parts Copyrighted Hendrik Visage 2002 under GPLv2 #
# #
# Parts Copyrighted Kagan Kongar 2002 under GPLv2 #
# #
############################################################
boost_locked() {
debug_msg "boost_locked ($@)"
[ -f $BOOST_LOCK ] && ps `cat $BOOST_LOCK` | grep -q lin
}
# function : invoke_installwatch
# usage : invoke_installwatch
# purpose : start logging all disk accesses with installwatch
invoke_installwatch() {
debug_msg "invoke_installwatch ($@)"
if [ -e /usr/lib/installwatch.so ] ; then
export LD_PRELOAD=/usr/lib/installwatch.so
fi
}
# function : devoke_installwatch
# usage : devoke_installwatch
# purpose : stop logging all disk accesses with installwatch
devoke_installwatch() {
debug_msg "devoke_installwatch ($@)"
unset LD_PRELOAD
}
# function : parse_iw
# usage : parse_iw
# purpose : remove unwanted accesses from the installwatch file
parse_iw() {
debug_msg "parse_iw ($@)"
OMIT="^/dev\|^/tmp\|^/usr/src"
OMIT_IN=" rename\| symlink\| unlink"
grep -v "$OMIT_IN" $INSTALLWATCHFILE | cut -f3 | grep -v "$OMIT"
cat $INSTALLWATCHFILE | cut -f4 | grep -v "$OMIT" | grep "^/"
}
# function : create_install_log
# usage : create_install_log
# purpose : create an install log
create_install_log() {
debug_msg "create_install_log ($@)"
MOD_SNAME=$(echo $MODULE | sed 's:/:.:g')
TMP_INST_LOG=$(temp_create "install-log")
INST_LOG="$INSTALL_LOGS/$MOD_SNAME-$VERSION"
rm -f $INST_LOG &> /dev/null
message "${MESSAGE_COLOR}Creating ${FILE_COLOR}${INST_LOG}${DEFAULT_COLOR}"
export IFS="$TAB_ENTER_IFS"
parse_iw |
sort |
uniq |
filter "$EXCLUDED" |
filter "$LOCAL_EXCLUDED" |
exists > $TMP_INST_LOG
echo "$INSTALL_LOGS/$MOD_SNAME-$VERSION" >> $TMP_INST_LOG
echo "$COMPILE_LOGS/$MOD_SNAME-$VERSION.bz2" >> $TMP_INST_LOG
echo "$MD5SUM_LOGS/$MOD_SNAME-$VERSION" >> $TMP_INST_LOG
MISOWNED_SYMLINKS=$(syms_not_owned $TMP_INST_LOG
echo -n "/dev/null")
if [ "$MISOWNED_SYMLINKS" == "/dev/null" ] ; then
install -m644 $TMP_INST_LOG $INST_LOG
else
grep -v "$MISOWNED_SYMLINKS" $TMP_INST_LOG > $INST_LOG
fi
temp_destroy $TMP_INST_LOG
}
create_md5sum_log() {
debug_msg "create_md5sum_log ($@)"
MOD_SNAME=$(echo $MODULE | sed 's:/:.:g')
rm -f $MD5SUM_LOGS/$MOD_SNAME-$VERSION &> /dev/null
message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$MD5SUM_LOGS/$MOD_SNAME-$VERSION${DEFAULT_COLOR}"
files < $INSTALL_LOGS/$MOD_SNAME-$VERSION | while read FILE ; do
md5sum $FILE >> $MD5SUM_LOGS/$MOD_SNAME-$VERSION
done
}
create_install_cache() {
debug_msg "create_install_cache($@)"
MOD_SNAME=$(echo $MODULE | sed 's:/:.:g')
if [ "$ARCHIVE" == "off" ] ; then
return
fi
message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$INSTALL_CACHE/$MOD_SNAME-$VERSION-$BUILD.tar.bz2${DEFAULT_COLOR}"
tar cPjf "$INSTALL_CACHE/$MOD_SNAME-$VERSION-$BUILD.tar.bz2" --no-recursion -T $INSTALL_LOGS/$MOD_SNAME-$VERSION
}
boost() {
debug_msg "boost ($@)"
create_install_log &&
create_md5sum_log &&
create_install_cache &&
add_module $MODULE installed $VERSION $(find_module_size $MODULE $VERSION)
verbose_msg "module size is $(find_module_size $MODULE $VERSION)"
rm -f $BOOST_LOCK
}
--- NEW FILE: uniqid.lunar ---
#!/bin/bash
# #
# uniqid.lunar - Make a uniqe id for tracking clients #
# #
############################################################
# #
# Copyright Fw systems LLC Under eitherGPL v2 or BSD Lic. #
# #
############################################################
push_uniq_id() {
debug_msg "push_uniq_id ($@)"
if [ -z "$UNIQID" ]; then
create_uniq_id
fi
verbose_msg "registering \"$UNIQID\" with server"
wget -q -O - "www.lunar-linux.org/cgi-bin/houston?loc=$UNIQID"
}
create_uniq_id() {
debug_msg "create_uniq_id ($@)"
if [ -n "$UNIQID" ]; then
return
fi
OS=$(uname -s)
if [ "$OS" == "OpenBSD" ]; then
HASH="sha1"
IFACE=`netstat -r | grep default | awk '{print $7}'`
elif [ "$OS" == "Linux" ]; then
HASH="md5sum"
IFACE=`netstat -r | grep default | awk '{print $8}'`
else
exit 1
fi
UNIQID=`ifconfig $IFACE |\
awk '/addr.*[:]* [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]/ {print $NF}' |\
tr 'A-Z' 'a-z' | $HASH | awk '{print $1}'`
export UNIQID
verbose_msg "id(\"$IFACE\")=\"$UNIQID\""
echo " UNIQID=$UNIQID" >> $LOCAL_CONFIG
}
--- NEW FILE: updatelog.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/updatelog #
# includes display_update_log #
# 20020711 #
# #
############################################################
# #
# Copyrighted Jason Jackson 2002 under GPLv2 #
# #
############################################################
# function : display_update_log
# usage : display_update_log update|rebuild
# purpose : display a log describing update successes, failures, and summaries
display_update_log() {
debug_msg "display_update_log ($@)"
rm -f /var/log/lunar/update
{
if [ -e "$TMP_LIN_SUCCESS" -a -e "$TMP_LIN_FAIL" ] ; then
display_success_info
fi
} | tee /var/log/lunar/update
}
# function : display_success_info
# usage : display_success_info update|rebuild
# purpose : display a list of update successes and failures
display_success_info() {
debug_msg "display_success_info ($@)"
NUMSUCCESS=$(cat $TMP_LIN_SUCCESS | wc -l)
NUMFAILURES=$(cat $TMP_LIN_FAIL | wc -l)
message
message "${MESSAGE_COLOR}Lunar renew completed at `date`${DEFAULT_COLOR}"
message "Successful : " $NUMSUCCESS
message "Failed : " $NUMFAILURES
message
if [ "$NUMSUCCESS" -gt "0" ]; then
message "${MESSAGE_COLOR}Successfully updated modules:${DEFAULT_COLOR}"
cat $TMP_LIN_SUCCESS
message
fi
if [ "$NUMFAILURES" -gt "0" ]; then
message "${MESSAGE_COLOR}Failed updated modules:${DEFAULT_COLOR}"
cat $TMP_LIN_FAIL
message
fi
}
# function : display_moonbase_changes
# usage : display_moonbase_changes
# purpose : display a list of modules added or removed during this update
display_moonbase_changes() {
debug_msg "display_moonbase_changes ($@)"
if [ -e "$MODULE_INDEX" ] && [ -e "$TMP_MODULE_INDEX" ]; then
NEW_MODULES=$(diff -I MOONBASE_MD5 $MODULE_INDEX $TMP_MODULE_INDEX | grep '<' | wc -l)
DEL_MODULES=$(diff -I MOONBASE_MD5 $MODULE_INDEX $TMP_MODULE_INDEX | grep '>' | wc -l)
if [ "$NEW_MODULES" != "0" ]; then
message "${MESSAGE_COLOR}New modules:${DEFAULT_COLOR}"
diff -I "MOONBASE_MD5:" $MODULE_INDEX $TMP_MODULE_INDEX | grep '<' | cut -d \ -f 2 -
message
fi
if [ "$DEL_MODULES" != "0" ]; then
message "${MESSAGE_COLOR}Removed modules:${DEFAULT_COLOR}"
diff -I "MOONBASE_MD5:" $MODULE_INDEX $TMP_MODULE_INDEX | grep '>' | cut -d \ -f 2 -
message
fi
fi
}
--- NEW FILE: useradd.lunar ---
#!/bin/bash
# #
# This code is written for Lunar Linux, see #
# http://www.lunar-linux.org #
# #
############################################################
# #
# $FUNCTIONS/uid.lunar #
# includes add_priv_user add_priv_group #
# 20030306 #
# #
############################################################
# #
# Copyrighted Auke Kok 2003 under GPLv2 #
# #
############################################################
# function: add_priv_user
# usage : add_priv_user username:groupname [adduseropts [adduseropts]...]
# info : adds username:groupname and passes adduseropts to 'adduser'
function add_priv_user() {
debug_msg "function add_priv_user ($@)"
USERNAME=$(echo $1 | cut -d: -f1)
GROUPNAME=$(echo $1 | cut -d: -f2)
if [ -z "$USERNAME" ] ; then
message "${PROBLEM_COLOR}!add_priv_user: no username specified${DEFAULT_COLOR}"
exit 1
fi
if [ -z "$GROUPNAME" ] ; then
message "${PROBLEM_COLOR}!add_priv_user: no groupname specified${DEFAULT_COLOR}"
exit 1
fi
if id $USERNAME &> /dev/null ; then
verbose_msg "user \"$USERNAME\" already exists, not creating or modifying"
else
if grep -q "^$GROUPNAME:" /etc/group ; then
verbose_msg "group \"$GROUPNAME\" already exists, not creating"
else
# add the group:
for (( N=0 ; N<100 ; N++)) ; do
if [ -z "$(cat /etc/group | cut -d: -f3 | grep "^$N$" )" ] ; then
break
fi
done
if [ "$N" == "100" ] ; then
message "${PROBLEM_COLOR}!add_priv_user: no more group id's left under gid=100, bailing out!${DEFAULT_COLOR}"
exit 1
fi
verbose_msg "creating group \"$GROUPNAME\" with id=\"$N\""
groupadd -g $N $GROUPNAME
fi
# add the user:
for (( N=0 ; N<100 ; N++)) ; do
if [ -z "$(cat /etc/passwd | cut -d: -f3 | grep "^$N$" )" ] ; then
break
fi
done
if [ "$N" == "100" ] ; then
message "${PROBLEM_COLOR}!add_priv_user: no more user id's left under uid=100, bailing out!${DEFAULT_COLOR}"
exit 1
fi
shift
verbose_msg "creating user \"$USERNAME\" (opts=\"-u $N -g $GROUPNAME $@\")"
useradd -u $N -g $GROUPNAME $USERNAME $@
fi
}
--- NEW FILE: view.lunar ---
#!/bin/bash
# #
# display.lunar - functions to view files #
# #
####################################################################
# function : view_file
# usage : view_file FILENAME
# purpose : to view a file
view_file() {
debug_msg "view_file ($@)"
if [ -n "$1" ] ; then
# show a file $1
case $(file -b $1 | cut -d' ' -f1) in
ASCII) cat $1 | ${PAGER:-less} ;;
bzip2) cat $1 | bzcat | ${PAGER:-less} ;;
gzip) cat $1 | zcat | ${PAGER:-less} ;;
esac
else
cat | ${PAGER:-less}
fi
}
More information about the Lunar-commits
mailing list