Skip to content

Commit

Permalink
First implementation of OBSOLETE libs feature #142
Browse files Browse the repository at this point in the history
The new feature KEEP_OBSOLETE_LIBS is on by default.

Libs with changed soname's will be automatically copied to
/usr/lib/lunar/OBSOLETE. This makes it safe to lin modules again, or update
modules that have not changed the lib version without ending up
with duplicated libs in OBSOLETE.

`lunar fix` will cleanup the OBSOLETE folder, but only if _ALL_ integrity checks
pass. And only if `lunar fix` is executed without module arguments, e.g. `lunar
fix module` will not clean OBSOLETE even if that module is fixed. The reason is
that multiple modules may still depend on the OBSOLETE libs.

TODO: fix so that only the LDD_CHECK need to pass for the cleanup function to
execute.
  • Loading branch information
Ratler committed Feb 11, 2020
1 parent 0cfa336 commit bc1b84c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 65 deletions.
2 changes: 2 additions & 0 deletions etc/config
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export DIALOGRC=/etc/lunar/dialogrc

DEFAULT_PREFIX=/usr

OBSOLETE_LIB_DIR=/usr/lib/lunar/OBSOLETE

BOOTSTRAP=/var/lib/lunar/bootstrap
EXCLUDED=/var/lib/lunar/excluded
MOONBASE=/var/lib/lunar/moonbase
Expand Down
52 changes: 44 additions & 8 deletions libs/build.lunar
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
# #
# Parts Copyrighted Steven Michalske 2004 under GPLv2 #
# #
# Parts Copyrighted Stefan Wold 2020 under GPLv2 #
# #
############################################################


Expand All @@ -33,23 +35,22 @@ save_libraries() {

[ "$MODULE" == "glibc" ] && return 0

OLD_VERSION=`installed_version $MODULE`
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
mkdir -p $OLD_LIBS

SAVED=$OLD_LIBS/$MODULE.saved.libraries
rm -rf $SAVED

grep "/lib/" "$OLD_LOG" |
egrep "/lib(32|64)?/" "$OLD_LOG" |
while read LINE; do

if [ -f "$LINE" ] &&
file -bL $LINE |
grep -E -q "shared object|pie executable"
egrep -q "shared object|pie executable"
then
verbose_msg "saving library \"$LINE\""
if [ -h $LINE ]; then
Expand All @@ -58,11 +59,11 @@ save_libraries() {
cut -c 2-
)
)
ln -sf $DEST $OLD_LIBS/`basename $LINE`
ln -sf $DEST $OLD_LIBS/$(basename $LINE)
else
cp $LINE $OLD_LIBS
cp $LINE $OLD_LIBS
fi
echo $OLD_LIBS/`basename $LINE` >> $SAVED
echo $OLD_LIBS/$(basename $LINE) >> $SAVED
fi
done

Expand All @@ -75,6 +76,40 @@ save_libraries() {
}


save_obsolete_libraries() {
local OLD_LIBS LIB
debug_msg "save_obsolete_libraries($@)"
OLD_LIBS=$SOURCE_DIRECTORY/old.libraries

if [[ "$KEEP_OBSOLETE_LIBS" != "on" ]]; then
verbose_msg "KEEP_OBSOLETE_LIBS is currently disabled"
return
fi

if [ ! -d "$OBSOLETE_LIB_DIR" ]; then
mkdir -p "$OBSOLETE_LIB_DIR"
fi

for f in $(ls -1 $OLD_LIBS/*.so* 2> /dev/null); do
LIB=$(basename $f)
if ! parse_iw | grep -q $LIB; then
verbose_msg "saving obsolete library ($LIB)"
cp -P $f "$OBSOLETE_LIB_DIR"/
fi
done

ldconfig $OBSOLETE_LIB_DIR
}


remove_obsolete_libraries() {
debug_msg "remove_obsolete_libraries($@)"
verbose_msg "Removing OBSOLETE libraries"
rm -rf "$OBSOLETE_LIB_DIR"
ldconfig
}


release_saved_libraries() {
local OLD_LIBS SAVED FILE
debug_msg "release_saved_libraries ($@)"
Expand Down Expand Up @@ -400,6 +435,7 @@ default_post_build() {
fi

ldconfig
save_obsolete_libraries
release_saved_libraries
cd /
}
Expand Down
15 changes: 12 additions & 3 deletions libs/check.lunar
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ fix_depends () {


run_fix() {
local MODULES MODULE
local MODULES MODULE KEEP_OBSOLETE
debug_msg "run_fix ($@)"
KEEP_OBSOLETE=1
MODULES=$*

if [ -z "$MODULES" ] ; then
MODULES=$(list_installed | fgrep -v -x moonbase)
unset KEEP_OBSOLETE
fi

if [[ -n "$FIXDEPENDS" ]] ; then
Expand Down Expand Up @@ -136,7 +138,7 @@ run_fix() {
export TMP_LIN_SUCCESS=$(temp_create "successful")
export TMP_LIN_FAIL=$(temp_create "failed")

if [[ ! -n "$NOFIX" ]] ; then
if [[ ! -n "$NOFIX" ]] ; then
for MODULE in $(sort_by_dependency ${BROKEN_MODULES[@]}) ; do
if module_installed $MODULE && ! module_held $MODULE ; then
if ! run_checks $MODULE ; then
Expand All @@ -150,13 +152,20 @@ run_fix() {
continue
elif ! run_checks $MODULE ; then
verbose_msg "Attempt to recompile \"$MODULE\" succeeded but \"$MODULE\" still is broken!"
KEEP_OBSOLETE=1
continue
fi
fi
fi
fi
done


# Only remove OBSOLETE if `lunar fix` pass all checks
# not perfect but it will have to do for now
if [ ! -n "$KEEP_OBSOLETE" ]; then
remove_obsolete_libraries
fi

display_update_log fix
else
display_update_log nofix
Expand Down
1 change: 1 addition & 0 deletions misc/unset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ unset MODULE_STATUS
unset MODULE_STATUS_BACKUP
unset MOONBASE
unset MOONBASE_URL
unset OBSOLETE_LIB_DIR
unset PATCH_URL
unset PLATFORM
unset PRESERVE
Expand Down
6 changes: 4 additions & 2 deletions plugins/check-ldd.plugin
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# #
# Copyright 2005 by Auke Kok under GPLv2 #
# #
# Copyright 2020 by Stefan Wold under GPLv2 #
# #
#############################################################


Expand All @@ -31,11 +33,11 @@ plugin_module_check_ldd() {
LOG=$(egrep "/(bin|games|lib(32|64)?|sbin|libexec)/" $I_LOG | egrep -v "/(doc|fonts|include|locale|man|modules|var|share|pkgconfig)/")

for FILE in $LOG; do
if [ -f "$FILE" ] && [ ! -h "$FILE" ] && file -b "$FILE" | grep -q "ELF" && LD_LIBRARY_PATH=$NEW_LD ldd "$FILE" 2>&1 | grep -q "not found" ; then
if [ -f "$FILE" ] && [ ! -h "$FILE" ] && file -b "$FILE" | grep -q "ELF" && LD_LIBRARY_PATH=$NEW_LD ldd "$FILE" 2>&1 | egrep -q "(not found|lunar/OBSOLETE/)" ; then
(
export IFS="$IFS_OLD"
message "${FILE_COLOR}${FILE}${DEFAULT_COLOR} of ${MODULE_COLOR}${MODULE} ${PROBLEM_COLOR}is broken. ${DEFAULT_COLOR}"
LD_LIBRARY_PATH=$NEW_LD ldd "$FILE" 2>&1 | grep "not found"
LD_LIBRARY_PATH=$NEW_LD ldd "$FILE" 2>&1 | egrep "(not found|lunar/OBSOLETE/)"
)
LDD_STATUS=1
fi
Expand Down
110 changes: 58 additions & 52 deletions prog/lunar
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ feature_menu() {
I_HELP="Create archives of installed software?"
K_HELP="Keep source code in /usr/src on good compiles? (gcc profiling needs it)"
M_HELP="Email reports?"
O_HELP="Preserve old libaries on module upgrade until lunar fix has completed?"
P_HELP="Preserve modified files or backup them up and overwrite with defaults?"
R_HELP="Prompt to view reports?"
S_HELP="Play audio with prompts?"
Expand All @@ -526,21 +527,22 @@ feature_menu() {
Z_HELP="Custom modules in zlocal override equally named ones (NOT RECOMMENDED) ?"
L_HELP="Use xz compression for logs and caches?"

ARCHIVE=${ARCHIVE:-on}
AUTORESURRECT=${AUTORESURRECT:-on}
AUTOFIX=${AUTOFIX:-on}
AUTOPRUNE=${AUTOPRUNE:-off}
COLOR=${COLOR:-on}
KEEP_SOURCE=${KEEP_SOURCE:-off}
MAIL_REPORTS=${MAIL_REPORTS:-off}
VIEW_REPORTS=${VIEW_REPORTS:-off}
PRESERVE=${PRESERVE:-on}
SOUND=${SOUND:-off}
SUSTAIN=${SUSTAIN:-on}
VOYEUR=${VOYEUR:-on}
REAP=${REAP:-on}
GARBAGE=${GARBAGE:-on}
VERBOSE=${VERBOSE:-off}
ARCHIVE=${ARCHIVE:-on}
AUTORESURRECT=${AUTORESURRECT:-on}
AUTOFIX=${AUTOFIX:-on}
AUTOPRUNE=${AUTOPRUNE:-off}
COLOR=${COLOR:-on}
KEEP_SOURCE=${KEEP_SOURCE:-off}
KEEP_OBSOLETE_LIBS=${KEEP_OBSOLETE_LIBS:-on}
MAIL_REPORTS=${MAIL_REPORTS:-off}
VIEW_REPORTS=${VIEW_REPORTS:-off}
PRESERVE=${PRESERVE:-on}
SOUND=${SOUND:-off}
SUSTAIN=${SUSTAIN:-on}
VOYEUR=${VOYEUR:-on}
REAP=${REAP:-on}
GARBAGE=${GARBAGE:-on}
VERBOSE=${VERBOSE:-off}

case $VOYEUR in
off) VOYEUR=off ; VOYEUR_progress=off ;;
Expand All @@ -561,46 +563,48 @@ feature_menu() {
--checklist \
"" \
0 40 14 \
"ARCHIVE" "Toggle" "$ARCHIVE" "$I_HELP" \
"AUTORESURRECT" "Toggle" "$AUTORESURRECT" "$H_HELP" \
"AUTOFIX" "Toggle" "$AUTOFIX" "$F_HELP" \
"AUTOPRUNE" "Toggle" "$AUTOPRUNE" "$U_HELP" \
"COLOR" "Toggle" "$COLOR" "$C_HELP" \
"KEEP_SOURCE" "Toggle" "$KEEP_SOURCE" "$K_HELP" \
"GARBAGE" "Toggle" "$GARBAGE" "$G_HELP" \
"MAIL_REPORTS" "Toggle" "$MAIL_REPORTS" "$M_HELP" \
"PRESERVE" "Toggle" "$PRESERVE" "$P_HELP" \
"SOUND" "Toggle" "$SOUND" "$S_HELP" \
"SUSTAIN" "Toggle" "$SUSTAIN" "$T_HELP" \
"VIEW_REPORTS" "Toggle" "$VIEW_REPORTS" "$R_HELP" \
"VOYEUR" "Choice" "$VOYEUR" "$V_HELP" \
"VOYEUR_progress" "Choice" "$VOYEUR_progress" "$VP_HELP" \
"REAP" "Toggle" "$REAP" "$E_HELP" \
"VERBOSE" "Toggle" "$VERBOSE" "$W_HELP" \
"ZLOCAL_OVERRIDES" "Toggle" "$ZLOCAL_OVERRIDES" "$Z_HELP" \
"PROBE_EXPIRED" "Toggle" "$PROBE_EXPIRED" "$X_HELP" \
"COMPRESS_XZ" "Toggle" "$COMPRESS_XZ" "$L_HELP"`
"ARCHIVE" "Toggle" "$ARCHIVE" "$I_HELP" \
"AUTORESURRECT" "Toggle" "$AUTORESURRECT" "$H_HELP" \
"AUTOFIX" "Toggle" "$AUTOFIX" "$F_HELP" \
"AUTOPRUNE" "Toggle" "$AUTOPRUNE" "$U_HELP" \
"COLOR" "Toggle" "$COLOR" "$C_HELP" \
"KEEP_SOURCE" "Toggle" "$KEEP_SOURCE" "$K_HELP" \
"KEEP_OBSOLETE_LIBS" "Toggle" "$KEEP_OBSOLETE_LIBS" "$O_HELP" \
"GARBAGE" "Toggle" "$GARBAGE" "$G_HELP" \
"MAIL_REPORTS" "Toggle" "$MAIL_REPORTS" "$M_HELP" \
"PRESERVE" "Toggle" "$PRESERVE" "$P_HELP" \
"SOUND" "Toggle" "$SOUND" "$S_HELP" \
"SUSTAIN" "Toggle" "$SUSTAIN" "$T_HELP" \
"VIEW_REPORTS" "Toggle" "$VIEW_REPORTS" "$R_HELP" \
"VOYEUR" "Choice" "$VOYEUR" "$V_HELP" \
"VOYEUR_progress" "Choice" "$VOYEUR_progress" "$VP_HELP" \
"REAP" "Toggle" "$REAP" "$E_HELP" \
"VERBOSE" "Toggle" "$VERBOSE" "$W_HELP" \
"ZLOCAL_OVERRIDES" "Toggle" "$ZLOCAL_OVERRIDES" "$Z_HELP" \
"PROBE_EXPIRED" "Toggle" "$PROBE_EXPIRED" "$X_HELP" \
"COMPRESS_XZ" "Toggle" "$COMPRESS_XZ" "$L_HELP"`

then

ARCHIVE=off
AUTORESURRECT=off
AUTOFIX=off
AUTOPRUNE=off
COLOR=off
KEEP_SOURCE=off
MAIL_REPORTS=off
PRESERVE=off
SOUND=off
SUSTAIN=off
VIEW_REPORTS=off
VOYEUR=off
REAP=off
GARBAGE=off
VERBOSE=off
ZLOCAL_OVERRIDES=off
PROBE_EXPIRED=off
COMPRESS_METHOD=bz2
ARCHIVE=off
AUTORESURRECT=off
AUTOFIX=off
AUTOPRUNE=off
COLOR=off
KEEP_SOURCE=off
KEEP_OBSOLETE_LIBS=off
MAIL_REPORTS=off
PRESERVE=off
SOUND=off
SUSTAIN=off
VIEW_REPORTS=off
VOYEUR=off
REAP=off
GARBAGE=off
VERBOSE=off
ZLOCAL_OVERRIDES=off
PROBE_EXPIRED=off
COMPRESS_METHOD=xz

for TOGGLE in $TOGGLES; do
case $TOGGLE in
Expand All @@ -610,6 +614,7 @@ ZLOCAL_OVERRIDES=off
AUTOPRUNE) AUTOPRUNE=on ;;
COLOR) COLOR=on ;;
KEEP_SOURCE) KEEP_SOURCE=on ;;
KEEP_OBSOLETE_LIBS) KEEP_OBSOLETE_LIBS=on ;;
MAIL_REPORTS) MAIL_REPORTS=on ;;
PRESERVE) PRESERVE=on ;;
SOUND) SOUND=on ;;
Expand Down Expand Up @@ -638,6 +643,7 @@ ZLOCAL_OVERRIDES=off
set_local_config "AUTOFIX" "$AUTOFIX"
set_local_config "AUTOPRUNE" "$AUTOPRUNE"
set_local_config "KEEP_SOURCE" "$KEEP_SOURCE"
set_local_config "KEEP_OBSOLETE_LIBS" "$KEEP_OBSOLETE_LIBS"
set_local_config "MAIL_REPORTS" "$MAIL_REPORTS"
set_local_config "PRESERVE" "$PRESERVE"
set_local_config "SOUND" "$SOUND"
Expand Down

0 comments on commit bc1b84c

Please sign in to comment.