Browse Source

enable multiselect in the "Cross Toolchain Template Menu" to support batched builds of cross toolchains (v0.8.0)

optimization of temp path handling to support the execution of multiple instances of s3
correct path setting in config builder function
fix library version detection
beautifying details on some menus
pull/8/head
WXbet 5 years ago
parent
commit
34709f23d9
  1. 138
      support/functions/_plugin_update_toolchain

138
support/functions/_plugin_update_toolchain

@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
#simplebuild_plugin tcupdate (s3.TUP) 0.7.0 #simplebuild_plugin tcupdate (s3.TUP) 0.8.0
tcupdate(){ tcupdate(){
clear && _check_bin; clear && _check_bin;
pversion="0.7.0"; pversion="0.8.0";
pname="s3.TUP"; pname="s3.TUP";
pdesc="Plugin $pname v$pversion"; pdesc="Plugin $pname v$pversion";
configname="$configdir/plugin_update_toolchain.config"; configname="$configdir/plugin_update_toolchain.config";
@ -39,7 +39,6 @@ tcupdate(){
#check config #check config
_check_config; _check_config;
IFS="#";
if [ "$1" == "-c" ] || [ "$1" == "--create" ];then if [ "$1" == "-c" ] || [ "$1" == "--create" ];then
_create_tc; _create_tc;
bye; bye;
@ -51,14 +50,16 @@ tcupdate(){
for i in "${INST_TCLIST[@]}";do for i in "${INST_TCLIST[@]}";do
if [ ! "$i" == "native" ];then if [ ! "$i" == "native" ];then
source "$tccfgdir/$i"; source "$tccfgdir/$i";
MENU_OPTIONS+="$_toolchainname#$_description#toolchain folder:"$tcdir/$i" | config file:"$tccfgdir/$i"#"; MENU_OPTIONS+=("$_toolchainname" "$_description" "toolchain folder:$tcdir/$i | config file:$tccfgdir/$i");
counter; counter;
fi; fi;
done; done;
fi; fi;
[ $COUNT -eq 0 ] && MENU_OPTIONS+="#no toolchains found#no toolchains found#" && counter; [ $COUNT -eq 0 ] && MENU_OPTIONS+=("" "no toolchains found" "no toolchains found") && counter;
fi; fi;
out=$("$gui" "$st_" "$bt_" "$title_ - $pdesc" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Update" "--cancel-label" "Create" "--help-button" "--help-label" "Exit" "--extra-button" "--extra-label" "Copy" "--title" "-[ Toolchain Menu ]-" --menu "\nSelect one of the installed tool chains that you want to update:\n " "${COUNT+10}" 0 0 ${MENU_OPTIONS}); out=$("$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Update" "--cancel-label" "Create" "--help-button" "--help-label" "Exit" "--extra-button" "--extra-label" "Copy" "--title" "-[ Toolchain Menu ]-" \
--menu "\nSelect one of the installed tool chains that you want to update:\n " \
"${COUNT+10}" 0 0 "${MENU_OPTIONS[@]}");
ret="$?" ret="$?"
tc=$(echo "$out" | awk '{printf $1}'); tc=$(echo "$out" | awk '{printf $1}');
@ -112,10 +113,9 @@ tcupdate(){
cd "$tcdir/$tc/$_sysroot" cd "$tcdir/$tc/$_sysroot"
fi; fi;
prefixdir="$PWD" prefixdir="$PWD"
pkg=$(find * | grep -m1 "/pkgconfig") && pkgdir="$prefixdir/$pkg"; pkg=$(find * | grep -m1 "/pkgconfig") && pkgdir="$prefixdir/$pkg" || pkgdir="$prefixdir";
#build menu items from config file #build menu items from config file
IFS=$OIFS;
unset MENU_OPTIONS;COUNT=0;unset libs; unset MENU_OPTIONS;COUNT=0;unset libs;
for i in "${LIBS[@]}" for i in "${LIBS[@]}"
do do
@ -140,9 +140,9 @@ tcupdate(){
lib=("$libkey" "$libname" "$libversion" "$libversioncheck" "$libcheck" "$libversioncurrent" "$liburl" "(${libtasks[*]@Q})"); lib=("$libkey" "$libname" "$libversion" "$libversioncheck" "$libcheck" "$libversioncurrent" "$liburl" "(${libtasks[*]@Q})");
libs+=("(${lib[*]@Q})"); libs+=("(${lib[*]@Q})");
done; done;
[ $COUNT -eq 0 ] && MENU_OPTIONS+="#no libraries found#no libraries found#" && counter; [ $COUNT -eq 0 ] && MENU_OPTIONS+=("" "no libraries found" "no libraries found") && counter;
opts=$("$gui" "--item-help" "--help-tags" "$st_" "$bt_" "$title_ - $pdesc" "--default-item" "$3" "--ok-label" "Start" "--help-button" "--help-label" "Info" "--cancel-label" "$([ "$tc_menu" == "1" ] && echo "Back" || echo "Exit")" --title "-[ Library Update Menu - $tc ]-" "$cl_"\ opts=$("$gui" "--item-help" "--help-tags" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--default-item" "$3" "--ok-label" "Start" "--help-button" "--help-label" "Info" "--cancel-label" "$([ "$tc_menu" == "1" ] && echo "Back" || echo "Exit")" "--title" "-[ Library Update Menu - \Z2$tc\Zn ]-" "$cl_"\
"\nSelect all libraries to update in toolchain's SYSROOT folder:\n$prefixdir\n\n library version NEW CURRENT" \ "\nSelect all libraries to update in toolchain's SYSROOT folder:\n$prefixdir\n\n library version NEW CURRENT" \
"${COUNT+12}" 70 0 "${MENU_OPTIONS[@]}"); "${COUNT+12}" 70 0 "${MENU_OPTIONS[@]}");
@ -159,19 +159,21 @@ tcupdate(){
bcd=$(cat "$configname" | grep ""$libkey"_tasks"); bcd=$(cat "$configname" | grep ""$libkey"_tasks");
txt=$(echo -e "Toolchain: $tcdir/$tc\nCompiler: $compilername\nSysroot: $sr\nPrefix: $prefixdir\n$sp\n\nLibrary configuration:\n$txt\n\nBuild command:\n$(_replace_tokens "$(_tidy_tasks "$bcd" "$libkey")")"); txt=$(echo -e "Toolchain: $tcdir/$tc\nCompiler: $compilername\nSysroot: $sr\nPrefix: $prefixdir\n$sp\n\nLibrary configuration:\n$txt\n\nBuild command:\n$(_replace_tokens "$(_tidy_tasks "$bcd" "$libkey")")");
tempfile=$(mktemp) && echo -e "$txt" > "$tempfile"; tempfile=$(mktemp) && echo -e "$txt" > "$tempfile";
"$gui" "$st_" "$nc_" "$bt_" "$title_ - $pdesc" "--textbox" "$tempfile" 30 80; "$gui" "$st_" "$nc_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--textbox" "$tempfile" 30 80;
rm "$tempfile" 2>/dev/null; rm "$tempfile" 2>/dev/null;
tcupdate $tc $tc_menu $libkey; tcupdate $tc $tc_menu $libkey;
fi; fi;
#BUILD section #BUILD section
ts=$(date +%F)_$(date +%T);
tmpdir="/tmp/lib_source/$ts";
icount=$(echo $opts | wc -w);i=0; icount=$(echo $opts | wc -w);i=0;
for o in $opts;do for o in $opts;do
unset buildtasks; unset buildtasks;
for l in "${libs[@]}";do for l in "${libs[@]}";do
declare -a lib="${l[*]}"; #populate libs array element declare -a lib="${l[*]}"; #populate libs array element
[ ! "$o" == "${lib[0]}" ] && continue || ((i++)); [ ! "$o" == "${lib[0]}" ] && continue || ((i++));
logfile="$ldir/$(date +%F)_$(date +%T)_update_toolchain_"$_toolchainname"_"${lib[1]}"_"${lib[2]}".log" logfile="$ldir/"$ts"_update_toolchain_"$_toolchainname"_"${lib[1]}"_"${lib[2]}".log"
#generate build command list #generate build command list
declare -a libtasks="${lib[7]}"; #populate tasks array element declare -a libtasks="${lib[7]}"; #populate tasks array element
@ -179,9 +181,10 @@ tcupdate(){
task=$(_replace_tokens "$task"); #replace tokens task=$(_replace_tokens "$task"); #replace tokens
buildtasks+=("$task"); buildtasks+=("$task");
done done
_build "($i/$icount) ${lib[1]}" $(_extract $(_dl "${lib[6]}")) "$logfile" "${buildtasks[@]}"; _build "($i/$icount) $tc: library ${lib[1]} ${lib[2]}" $(_extract $(_dl "${lib[6]}" "${lib[1]} ${lib[2]}") "$tmpdir") "$logfile" "${buildtasks[@]}";
done; done;
done; done;
[ -d "$tmpdir" ] && rm -r "$tmpdir";
#Reopen update menu #Reopen update menu
if [ ${#opts} -gt 0 ];then if [ ${#opts} -gt 0 ];then
@ -214,61 +217,66 @@ _create_tc(){
desc=$(sed -n -e '/#toolchain template/ s/.*\: *//p' $t); desc=$(sed -n -e '/#toolchain template/ s/.*\: *//p' $t);
[ ! "$desc" ] && desc="no description available"; [ ! "$desc" ] && desc="no description available";
[ -d "$tcdir/$t" ] && [ -f "$tccfgdir/$t" ] && color="\Z1" || color=""; [ -d "$tcdir/$t" ] && [ -f "$tccfgdir/$t" ] && color="\Z1" || color="";
MENU_OPTIONS+="$t#$color$desc\Zn#template filename:"$cttpldir/$t"#"; MENU_OPTIONS+=("$t" "$color$desc\Zn" "off" "template filename:$cttpldir/$t");counter;
counter; counter;
done; done;
fi; fi;
[ $COUNT -eq 0 ] && MENU_OPTIONS+="#no templates found#no templates found#" && counter; [ $COUNT -eq 0 ] && MENU_OPTIONS+=("" "no templates found" "no templates found") && counter;
opts=$("$gui" "$st_" "$bt_" "$title_ - $pdesc" "--colors" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Start" "--cancel-label" "Setup" "--help-button" "--help-label" "$([ $tc_menu ] && echo "Back" || echo "Exit")" "--title" "-[ Cross Toolchain Template Menu ]-" \ opts=$("$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--item-help" "--help-tags" "--default-item" "$3" "--ok-label" "Start" "--cancel-label" "Setup" "--help-button" "--help-label" "$([ $tc_menu ] && echo "Back" || echo "Exit")" "--title" "-[ Cross Toolchain Template Menu ]-" "$cl_"\
--menu "\nSelect on of the templates to create the cross toolchain you want:\n\n\Z1NOTE: If you create a cross toolchain from a template with a red colored description, an existing one with the same name will be replaced without asking!\Zn" \ "\nSelect on of the templates to create the cross toolchain you want:\n\n\Z1NOTE: If you create a cross toolchain from a template with a red colored description, an existing one with the same name will be replaced without asking!\Zn" \
"${COUNT+11}" 0 0 ${MENU_OPTIONS}); "${COUNT+11}" 0 0 "${MENU_OPTIONS[@]}");
ret="$?" ret="$?"
tpl=$(echo "$opts" | awk '{printf $1}');
case $ret in case $ret in
0) #Start - Build cross toolchain 0) #Start - Build cross toolchain
if [ -f "$ctsrcdir/ct-ng" ]; then if [ -f "$ctsrcdir/ct-ng" ]; then
if [ -f "$cttpldir/$tpl" ]; then icount=$(echo $opts | wc -w);i=0;
#logfile="$ldir/$(date +%F)_$(date +%T)_update_toolchain_crosstoolchain_"$tpl".log" for tpl in $opts;do
if [ -f "$cttpldir/$tpl" ]; then
#copy template and patching them logfile="$ldir/$(date +%F)_$(date +%T)_update_toolchain_crosstoolchain_"$tpl".log" && ((i++));
cp --no-preserve=mode,ownership -f "$cttpldir/$tpl" "$ctsrcdir/.config";
#CT_LOCAL_TARBALLS_DIR aka cache folder for downloads #copy template and patching them
sed -i "s#.*CT_LOCAL_TARBALLS_DIR=.*#CT_LOCAL_TARBALLS_DIR=\"$dldir\"#g" "$ctsrcdir/.config"; cp --no-preserve=mode,ownership -f "$cttpldir/$tpl" "$ctsrcdir/.config";
#CT_PREFIX_DIR aka folder that contains the final toolchain #CT_LOCAL_TARBALLS_DIR aka cache folder for downloads
sed -i "s#.*CT_PREFIX_DIR=.*#CT_PREFIX_DIR=\"$tcdir/$tpl\"#g" "$ctsrcdir/.config"; sed -i "s#.*CT_LOCAL_TARBALLS_DIR=.*#CT_LOCAL_TARBALLS_DIR=\"$dldir\"#g" "$ctsrcdir/.config";
#CT_PARALLEL_JOBS #CT_PREFIX_DIR aka folder that contains the final toolchain
sed -i "s#.*CT_PARALLEL_JOBS=.*#CT_PARALLEL_JOBS=$CTNG_PARALLEL_JOBS#g" "$ctsrcdir/.config"; sed -i "s#.*CT_PREFIX_DIR=.*#CT_PREFIX_DIR=\"$tcdir/$tpl\"#g" "$ctsrcdir/.config";
clear; #CT_PARALLEL_JOBS aka parallel build job count
sed -i "s#.*CT_PARALLEL_JOBS=.*#CT_PARALLEL_JOBS=$CTNG_PARALLEL_JOBS#g" "$ctsrcdir/.config";
#run build clear;
bcl=$(printf '%s\n' "${CTNG_BUILD_tasks[@]}");
sp=$(printf '%*s' 80 | tr ' ' '=') #run build as $CTNG_USER
echo -e "$sp\nbuild command list for cross toolchain $tpl (executed as user $CTNG_USER):\n$sp\ncd "$ctsrcdir"\n$(_replace_tokens "$bcl")\n$sp"; bcl=$(printf '%s\n' "${CTNG_BUILD_tasks[@]}");
sleep 2; sp=$(printf '%*s' 80 | tr ' ' '=')
cd "$ctsrcdir"; echo -e "$sp\nbuild ($i/$icount): command list for cross toolchain $tpl (executed as user $CTNG_USER):\n$sp\ncd "$ctsrcdir"\n$(_replace_tokens "$bcl")\n$sp";
cmd="${CTNG_BUILD_tasks[@]}"; sleep 2;
sudo -u "$CTNG_USER" -H -- sh -c "$(_replace_tokens "$cmd")" 2>&1; cd "$ctsrcdir";
err=$(grep '\[ERROR\]' "$ctsrcdir/build.log" | wc -l) cmd="${CTNG_BUILD_tasks[@]}";
sudo -u "$CTNG_USER" -H -- sh -c "$(_replace_tokens "$cmd")" 2>&1;
if [ ! $err -gt 0 ]; then err=$(grep '\[ERROR\]' "$ctsrcdir/build.log" | wc -l)
#get target from build.log
target=$(sed -n -e '/target = / s/.*\= *//p' "$ctsrcdir/build.log"); #save build.log in logs
cp -f "$ctsrcdir/build.log" "$logfile";
#compress toolchain
_compress "$dldir/Toolchain-$tpl.tar.xz" "$tcdir/$tpl" | "$gui" "$st_" --colors --title " -[ Compress cross toolchain $tpl... ]- " "$pb_" "$_lines" "$_cols"; if [ ! $err -gt 0 ]; then
#get target from build.log
#create toolchain.cfg target=$(sed -n -e '/target = / s/.*\= *//p' "$ctsrcdir/build.log");
desc=$(sed -n -e '/#toolchain template/ s/.*\: *//p' "$cttpldir/$tpl");
_create_toolchaincfg "$tcdir/$tpl" "$tpl" "$target" "$desc" "$dldir/Toolchain-$tpl.tar.xz"; #compress toolchain
_compress "$dldir/Toolchain-$tpl.tar.xz" "$tcdir/$tpl" | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Compress cross toolchain $tpl... ]- " "$pb_" "$_lines" "$_cols";
#create toolchain.cfg
desc=$(sed -n -e '/#toolchain template/ s/.*\: *//p' "$cttpldir/$tpl");
_create_toolchaincfg "$tcdir/$tpl" "$tpl" "$target" "$desc" "$dldir/Toolchain-$tpl.tar.xz";
else
_paktc_timer 10;
fi;
else else
_paktc_timer; [ "$tpl" == "" ] && echo -e "$r_l $txt_error:$y_l $tc$w_l Template $txt_n_installed""$rs_";
sleep 2;
fi; fi;
else done;
[ "$tpl" == "" ] && echo -e "$r_l $txt_error:$y_l $tc$w_l Template $txt_n_installed""$rs_";
sleep 2;
fi;
else else
echo -e "$r_l""CHECK -> crosstool-NG is not setup correctly. Please run 'Setup' from menu!\n""$re_"; echo -e "$r_l""CHECK -> crosstool-NG is not setup correctly. Please run 'Setup' from menu!\n""$re_";
_paktc_timer 10; _paktc_timer 10;
@ -302,8 +310,8 @@ _create_tc(){
cd "$ctsrcdir"; cd "$ctsrcdir";
cmd="${CTNG_SETUP_tasks[@]}"; cmd="${CTNG_SETUP_tasks[@]}";
sudo -u "$CTNG_USER" -H -- sh -c "$(_replace_tokens "$cmd")" 2>&1; sudo -u "$CTNG_USER" -H -- sh -c "$(_replace_tokens "$cmd")" 2>&1;
) | tee "$logfile" | "$gui" "$st_" --colors --title " -[ Setup crosstool-NG... ]- " "$pb_" "$_lines" "$_cols"; ) | tee "$logfile" | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Setup crosstool-NG... ]- " "$pb_" "$_lines" "$_cols";
_paktc_timer; _paktc_timer 10;
_create_tc;; _create_tc;;
2) #Exit 2) #Exit
return;; return;;
@ -324,7 +332,7 @@ _copy(){
#create toolchain.cfg #create toolchain.cfg
source "$tccfgdir/$1" && target="${_compiler%?}" && desc="$_description"; source "$tccfgdir/$1" && target="${_compiler%?}" && desc="$_description";
_create_toolchaincfg "$tcdir/$1" "$newtc" "$target" "$desc" "$xzfile"; _create_toolchaincfg "$tcdir/$1" "$newtc" "$target" "$desc" "$xzfile";
) | "$gui" "$st_" --colors --title " -[ Copy $1 to $newtc ... ]- " "$pb_" "$_lines" "$_cols"; ) | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Copy $1 to $newtc ... ]- " "$pb_" "$_lines" "$_cols";
[ -f "$newtccfgfile" ] && echo "$newtc"; [ -f "$newtccfgfile" ] && echo "$newtc";
}; };
_build(){ _build(){
@ -344,7 +352,7 @@ _build(){
sleep 2; sleep 2;
cd "$libsrcdir"; cd "$libsrcdir";
( eval "${tasks[@]}" ) 2>&1 | tee -a "$lf" ( eval "${tasks[@]}" ) 2>&1 | tee -a "$lf"
) | "$gui" "$st_" --colors --title " -[ Build $desc ... ]- " "$pb_" "$_lines" "$_cols";sleep 2; ) | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ Build $desc... ]- " "$pb_" "$_lines" "$_cols";sleep 2;
#build error message #build error message
error_on_build=$(grep -cw1 Error "$lf"); error_on_build=$(grep -cw1 Error "$lf");
@ -359,7 +367,7 @@ _dl(){
[ -d "$dldir/#tmp" ] && rm --recursive --force "$dldir/#tmp" [ -d "$dldir/#tmp" ] && rm --recursive --force "$dldir/#tmp"
mkdir --parents "$dldir/#tmp"; mkdir --parents "$dldir/#tmp";
cd "$dldir/#tmp"; cd "$dldir/#tmp";
wget --content-disposition "$1" 2>&1 | stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | "$gui" "$st_" "$bt_" "$title_ - $pdesc" --title " -[ download ]- " --gauge " $txt_loading $fname $txt_wait" 6 74; wget --content-disposition "$1" 2>&1 | stdbuf -o0 awk '/[.] +[0-9][0-9]?[0-9]?%/ { print substr($0,63,3) }' | "$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ download $2 ]- " --gauge " $txt_loading $txt_wait" 6 74;
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
fname="$(ls -t | head -n1)"; md5file="$fname.md5"; fname="$(ls -t | head -n1)"; md5file="$fname.md5";
md5sum "$fname" > "$md5file"; md5sum "$fname" > "$md5file";
@ -380,7 +388,7 @@ _extract(){
(($#)) || return; (($#)) || return;
edir=/tmp/lib_source; edir="$2";
[ -d "$edir" ] && rm -r "$edir"; [ -d "$edir" ] && rm -r "$edir";
mkdir --parents "$edir"; mkdir --parents "$edir";
@ -410,7 +418,7 @@ _extract(){
cd "$edir"; cd "$edir";
BEFORE=(.*/ */); BEFORE=(.*/ */);
command "${c[@]}" "$i" |"$gui" "$st_" --title " -[ $txt_extracting ]- " "$pb_" 20 74; command "${c[@]}" "$i" |"$gui" "$st_" "$bt_" "$title_ - \Z4$pdesc\Zn" "--colors" "--title" " -[ $txt_extracting $i ]- " "$pb_" 20 74;
((e = e || $?)); ((e = e || $?));
AFTER=(.*/ */); AFTER=(.*/ */);
@ -563,7 +571,7 @@ _create_config(){
ctng_build_tasks=( "(\"./ct-ng build;\")" ); ctng_build_tasks=( "(\"./ct-ng build;\")" );
ctng_build_tasks_comment="#build command"; ctng_build_tasks_comment="#build command";
ctng_setup_tasks=( "(\"git clone --progress \"\$CTNG_REPO_URL\" \"@CTNGSOURCE@\";\")" "(\"./bootstrap;\")" "(\"./configure --enable-local;\")" "(\"make;\")" "(\"touch \"@CTNGSOURCE@\.config\";\")" ); ctng_setup_tasks=( "(\"git clone --progress \"\$CTNG_REPO_URL\" \"@CTNGSOURCE@\";\")" "(\"./bootstrap;\")" "(\"./configure --enable-local;\")" "(\"make;\")" "(\"touch \"@CTNGSOURCE@/.config\";\")" );
ctng_setup_tasks_comment="#setup command"; ctng_setup_tasks_comment="#setup command";
echo '#CROSS toolchain build settings' >"$configname"; echo '#CROSS toolchain build settings' >"$configname";

Loading…
Cancel
Save