Hi all,
i spend some time to write this Code for playing some around with Tinycore, with this Code it's possible to find the all dependencies, (the location of the extension must be in the tinycore default path), of a given extension like "Bash" and it will print them out sorted as its need to mount in the right order or tinycore not support, unmount.
this Script will print out:
./f_find_dependencies_sorted.sh bash
bash readline ncurses
As the output shows, bash needs "readline" and "ncurses", the last word is the first extention to mount, example: mount ncurses, then mount readline, then mount bash, to get bash working as example.
This script needs bash installed.
#!/bin/bash
#************************************************#
# f_find_dependencies_sorted.sh #
# written by Halma #
# July 20, 2017 #
# #
# Find dependencies of extension #
# and print them out sorted #
#************************************************#
#TinyCoreLinux EXTENSIONSARRAY Folder
TINYCOREEXTENSIONSFOLDER=/etc/sysconfig/tcedir/optional
#arg check
package=$1
if [ -z "$package" ]; then
echo "[Error]: No package name specified"
exit 1
fi
# --------------------------------------------------------- #
# f_finddepfile() #
# this function will try to find dep files of extension #
# --------------------------------------------------------- #
#function
f_finddepfile() {
var_path_to_file=""
var_depfile_found=false
if [ -f $TINYCOREEXTENSIONSFOLDER/$var_extension.tcz.dep ]; then
var_path_to_file=$TINYCOREEXTENSIONSFOLDER
var_depfile_found=true
fi
}
# --------------------------------------------------------- #
# f_sortoutput() #
# this function will sort the dependencies #
# in a sorted row as needed to load #
# --------------------------------------------------------- #
#function
f_sortoutput() {
List="${HELPERARRAY[@]}"
NewList=""
#run till List is zero
while [ $(echo "${#List}") -gt 1 ] ; do
leftvaluefound=false
rightvaluefound=false
#get first column
firstcolumn=$(echo "$List" | awk '{print $1}')
#split colum
leftvalue="${firstcolumn%_@_*}"
rightvalue="${firstcolumn#*_@_}"
#add $leftvalue to NewList if not exists
if ! $(echo "$NewList" | grep "$leftvalue" > /dev/null) ; then
#prevent whitespace on adding at starting of a NewList
if [ $( echo "$NewList" == "" ) ]; then
#echo "add1 leftvalue $leftvalue"
NewList="$NewList$leftvalue" #remove whitespace
#set true if added to NewList
leftvaluefound=true
else
#echo "add1 leftvalue $leftvalue"
NewList="$NewList $leftvalue"
#set true if added to NewList
leftvaluefound=true
fi
fi
#add $rightvalue to NewList if not exists
if ! echo "$NewList" | grep "$rightvalue" >/dev/null ; then
#echo "add2 rightvalue $leftvalue"
NewList="$NewList $rightvalue"
#set true if added to NewList
rightvaluefound=true
#delete first field from $List to prevent double matching #To remove all whitespace (including tabs) from left to first word, enter: sed -e 's/^[ \t]*//'
List=$(echo "$List" | awk '{$1 = ""; print $0}' | sed -e 's/^[ \t]*//')
#search for more Strings in $List containing "$rightvalue"
for i in $List; do
if [ "${i%_@_*}" == "$rightvalue" ]; then
#add ${i#*_@_} to NewList
NewList="$NewList ${i#*_@_}"
#delete field from $List to prevent double matching
List=$(echo "$List" | sed 's/'$i'//')
fi
done
fi
#if both left and right values allready exists in the Newlist delete from List to prevent looping
if [ "$leftvaluefound" == false ] && [ "$rightvaluefound" == false ]; then
List=$(echo "$List" | awk '{$1 = ""; print $0}' | sed -e 's/^[ \t]*//')
fi
done
echo "$NewList"
}
# --------------------------------------------------------- #
# f_find_dependencies() #
# this function will find all dependencies #
# of a given extension #
# --------------------------------------------------------- #
#function
function f_find_dependencies () {
declare -a EXTENSIONSARRAY # indexed array for the EXTENSIONSARRAY
declare -a HELPERARRAY # indexed HELPERARRAY array for the EXTENSIONSARRAY
EXTENSIONSARRAY=( "$1" )
HELPERARRAY=()
#echo "$EXTENSIONSARRAY"
while [ $(echo ${#EXTENSIONSARRAY[@]}) -gt 0 ] ; do
for var_extension in ${EXTENSIONSARRAY[@]}; do
#search for a depfile
f_finddepfile
#
#--- if a dep file was found
#
if [ "$var_depfile_found" == "true" ]; then
#case
case "$var_path_to_file " in
/*)
for var_dep_file in $var_extension; do
while read line ; do
#check for empty line
[ -z "$line" ] && continue
#add extension to EXTENSIONSARRAYarray
#echo "add depencie: ${line%%.*}"
EXTENSIONSARRAY+=(${line%%.*})
HELPERARRAY+="${var_extension}_@_${line%%.*} "
done < $var_path_to_file/$var_dep_file.tcz.dep;
#remove current array-element from array EXTENSIONSARRAY[0] #http://stackoverflow.com/a/34199081
EXTENSIONSARRAY_TEMP=("${EXTENSIONSARRAY[0]}")
result=("${EXTENSIONSARRAY[@]}")
#remove array element [0]
for element in "${EXTENSIONSARRAY_TEMP[@]}"; do
result=(${result[@]/*${element}*/}) #/*${element}*/
done
#(re)set the array EXTENSIONSARRAY=( "${result[@]}" )
EXTENSIONSARRAY=( "${result[@]}" )
done;;
esac
fi
#
#--- if no dep file was found
#
if [ "$var_depfile_found" == "false" ]; then
#remove current array-element from array EXTENSIONSARRAY[0] #http://stackoverflow.com/a/34199081
EXTENSIONSARRAY_TEMP=("${EXTENSIONSARRAY[0]}")
result=("${EXTENSIONSARRAY[@]}")
#remove array element [0]
for element in "${EXTENSIONSARRAY_TEMP[@]}"; do
result=(${result[@]/*${element}*/}) #/*${element}*/
done
#(re)set the array EXTENSIONSARRAY=( "${result[@]}" ) #if just one array element is left, reset the array =()
if [ $( echo "${#EXTENSIONSARRAY[@]}") -eq 1 ]; then
EXTENSIONSARRAY=()
else
EXTENSIONSARRAY=( "${result[@]}" )
fi
fi
done #end for var_extension in ${EXTENSIONSARRAY[@]}; do
done
#
#--- Done, print out
#
if [ ! ${#HELPERARRAY[@]} -eq 0 ]; then
#sort the output
f_sortoutput
fi
}
# run the script with the given arg=extension
f_find_dependencies "$1"
usage of your own risk, no warranty for this code.
any suggestions are welcome
please use the second attachment, i dont know how to delete the first attachment, if an mod can do delete the first attachment, it would be nice
thx