|
|
|
@ -17,8 +17,10 @@
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
# выбор строки перемонтирования разделов в зависимости от используемого модуля
|
|
|
|
|
BUILDER=/mnt/builder
|
|
|
|
|
ROOTDIR=/
|
|
|
|
|
UPDATE_DIRS="/boot /lib/modules /lib/firmware"
|
|
|
|
|
# выбор строки перемонтирования разделов в зависимости от используемого модуля
|
|
|
|
|
if [[ -n `mount | grep " / type aufs"` ]];
|
|
|
|
|
then
|
|
|
|
|
REMOUNT="mount -t aufs -o remount,br:/ none /"
|
|
|
|
@ -27,9 +29,75 @@ else
|
|
|
|
|
REMOUNT="mount -t unionfs -o remount,dirs=/ unionfs /"
|
|
|
|
|
REMOUNTBUILDER=":"
|
|
|
|
|
fi
|
|
|
|
|
TIMERUN=`python -c "import time;print str(time.time())[:10]"`
|
|
|
|
|
TIMERUN=`date +%s`
|
|
|
|
|
EMERGELOG=${BUILDER}/var/log/emerge.log
|
|
|
|
|
TAILEMERGELOG="tail -f ${EMERGELOG}"
|
|
|
|
|
REPLACE_ANSWER=${REPLACE_ANSWER}
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
# Ask: whether to replace the old file
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
ask_replace() {
|
|
|
|
|
[[ $REPLACE_ANSWER == "yes" ]] && return 0
|
|
|
|
|
[[ $REPLACE_ANSWER == "no" ]] && return 1
|
|
|
|
|
local destfile=$1
|
|
|
|
|
echo "File '$destfile' in builder is newer than in workspace"
|
|
|
|
|
local line
|
|
|
|
|
while true
|
|
|
|
|
do
|
|
|
|
|
echo -n "Do you want replace old file (Yes/No/All/None):"
|
|
|
|
|
read line <&1
|
|
|
|
|
case $line in
|
|
|
|
|
All|all) REPLACE_ANSWER=yes;return 0;;
|
|
|
|
|
None|none) REPLACE_ANSWER=no;return 1;;
|
|
|
|
|
Y*|y*) return 0 ;;
|
|
|
|
|
N*|n*) return 1 ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
# Compare modify time of the first and second file
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
test_newer() {
|
|
|
|
|
# [[ file1 -nt file2 ]] not correct work with symbolic link, because
|
|
|
|
|
# get modify time of target file
|
|
|
|
|
if [[ -L $1 || -L $2 ]]
|
|
|
|
|
then
|
|
|
|
|
[[ `stat -c %Y $1` -gt `stat -c %Y $2` ]]
|
|
|
|
|
else
|
|
|
|
|
[[ $1 -nt $2 ]]
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
# Compare modify time, ask user for update and update file
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
try_update_file() {
|
|
|
|
|
[[ -e $2 || -L $2 ]] && test_newer $1 $2 &&
|
|
|
|
|
ask_replace $2 && cp -P $1 $2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
# Find in first directory files and symbolic links with modify time great than
|
|
|
|
|
# same files in the second directory
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
update_from_builder() {
|
|
|
|
|
basesrc=${1%/}
|
|
|
|
|
basedest=${2%/}
|
|
|
|
|
shift 2
|
|
|
|
|
for place in $*
|
|
|
|
|
do
|
|
|
|
|
src=$basesrc/${place#/}
|
|
|
|
|
dest=$basedest/${place#/}
|
|
|
|
|
find $src -type f -o -type l |
|
|
|
|
|
while read srcfile;
|
|
|
|
|
do
|
|
|
|
|
dstfile=${dest}/${srcfile#${src}/}
|
|
|
|
|
try_update_file $srcfile $dstfile
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
# Обновление Unionfs в течение сборки пакетов
|
|
|
|
@ -78,7 +146,7 @@ umountres() {
|
|
|
|
|
MOUNTDIRS=`mount | grep -Po "${BUILDER}/[^ ]+" | sed "{N;s/\n/ /}"`
|
|
|
|
|
for MOUNTDIR in $( echo $MOUNTDIRS | rev )
|
|
|
|
|
do
|
|
|
|
|
umount $(echo $MOUNTDIR | rev) || exit
|
|
|
|
|
umount $(echo $MOUNTDIR | rev) || exit 1
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -90,13 +158,13 @@ checkrun() {
|
|
|
|
|
if [[ `/usr/bin/id -u` -ne 0 ]]
|
|
|
|
|
then
|
|
|
|
|
echo "Only root can perform system building."
|
|
|
|
|
exit;
|
|
|
|
|
exit 1;
|
|
|
|
|
fi
|
|
|
|
|
#не запустим если загрузка не в Scrach режиме
|
|
|
|
|
if ! mount | grep /mnt/scratch &>/dev/null
|
|
|
|
|
then
|
|
|
|
|
echo "This program only works in the system, installed by Calculate with the option '--build'."
|
|
|
|
|
exit;
|
|
|
|
|
exit 1;
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
#не запустим второй раз
|
|
|
|
@ -105,7 +173,7 @@ checkrun() {
|
|
|
|
|
if [ `ps ax | grep -v grep | grep -c "/bin/bash /usr/bin/cl-builder"` -gt 3 ];
|
|
|
|
|
then
|
|
|
|
|
echo "This program is already run."
|
|
|
|
|
exit;
|
|
|
|
|
exit 1;
|
|
|
|
|
else
|
|
|
|
|
umountres
|
|
|
|
|
fi
|
|
|
|
@ -115,7 +183,7 @@ checkrun() {
|
|
|
|
|
if [ `mount | grep -c "devpts on /dev/pts "` -ne 1 ];
|
|
|
|
|
then
|
|
|
|
|
echo "This program can't be run from Scratch layer."
|
|
|
|
|
exit;
|
|
|
|
|
exit 1;
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -136,4 +204,4 @@ configure
|
|
|
|
|
$REMOUNTBUILDER &>/dev/null
|
|
|
|
|
mountres && runchroot
|
|
|
|
|
umountres
|
|
|
|
|
|
|
|
|
|
update_from_builder $BUILDER $ROOTDIR $UPDATE_DIRS
|
|
|
|
|