View previous topic :: View next topic |
Author |
Message |
xorader n00b

Joined: 07 Oct 2003 Posts: 9
|
Posted: Fri Feb 13, 2004 10:52 am Post subject: HOWTO: create CD's distributive |
|
|
I wrote some script for create CD's distributive:
Code: |
#!/bin/sh
#
# Created by Xorader (xorader@mail.ru)
# 04-02-2004
# Fri Feb 13 13:31:56 MSK 2004
#echo $@
WORKDIR="/var/tmp/process"
OUTDIR="${WORKDIR}/out"
DISTDIR="/var/gentoo-distfiles"
GRLIST="${WORKDIR}/group_dists.txt"
CDDIR="/var/tmp"
MAXCD=3
######################
ProgramName=${0##*/}
mkdir -p ${OUTDIR}
mkdir -p ${CDDIR}
groups_list="bootstrap"
usage()
{
echo -e "Usage: $ProgramName [-h] [-u <groupname>]"
echo -e "\t-u <groupname> ... show using of flags at group"
echo -e "\t-h ... display this help message."
}
checktarballs()
{
error=0
echo -e "\t\t>>> check '$1' <<<"
for tb in `cat $1`; do
if [ -f ${DISTDIR}/$tb ] ; then
echo "OK:: $tb"
else
echo -e "\tERROR:: $tb"
error=`echo "$error + 1" | bc`
fi
done
if [ $error -eq 0 ] ; then
echo -e "\t\t-= Success =-"
else
echo "Found some errors: $error"
fi
}
noyes()
{
ans=""
echo -n "$@ " '[N/y] '
read -e ans
case "$ans" in
y*|Y*)
return 0
;;
*)
return 1
;;
esac
}
check_flag()
{
gl_flags=$1
flags=$2
for ff in `echo $flags` ; do
finded=""
for ffs in `echo ${gl_flags}` ; do
if [ "$ff" == "$ffs" ] ; then
finded="yep"
fi
done
if [ -z "$finded" ] ; then
gl_flags="$gl_flags $ff"
fi
# if ! echo "$gl_flags" | grep $ff > /dev/null ; then
# gl_flags="$gl_flags $ff"
# fi
done
echo "$gl_flags"
}
show_flags()
{
dist=$1
all_dists=$2
on_f=$3
off_f=$4
on_f=`echo ${on_f} | sed -e 's/^ //'`
off_f=`echo ${off_f} | sed -e 's/^ //'`
shortdist=`echo $dist | sed -e 's/..*\///'`
if echo $all_dists | grep $shortdist > /dev/null ; then
strdist="\033[01;32m${dist}\033[00m"
else
strdist="${dist}"
fi
if [ -z "$on_f" ] ; then
echo -e "\t${strdist} \033[01;34m-(${off_f})\033[00m"
elif [ -z "$off_f" ] ; then
echo -e "\t${strdist} \033[01;31m+(${on_f})\033[00m"
else
echo -e "\t${strdist} \033[01;31m+(${on_f}) \033[01;34m-(${off_f})\033[00m"
fi
}
showuflags_group()
{
group_name=$1
tmpfile="$OUTDIR/_tmp_$!"
resultfile="$OUTDIR/GROUP_pv_${group_name}.txt"
dists=`cat ${OUTDIR}/GROUP_d_${group_name}.txt`
flags=`cat ${OUTDIR}/GROUP_f_${group_name}.txt`
idist=""
on_flags=""
off_flags=""
gl_on_flags=""
gl_off_flags=""
if ! echo "$groups_list" | /bin/grep "$group_name" >/dev/null ; then
echo "Not found group: $group_name"
exit 1
fi
USE="${flags}" emerge -pv ${dists} 2>/dev/null > $tmpfile
egrep "^\[ebuild.+\]" $tmpfile | sed -e 's/^\[ebuild.[^]]*\] //' \
-e 's/\(^.[^ ]*\) \[..*\] \(.*\)/\1 \2/' \
-e 's/[0-9,]* kB .*$//' \
-e 's/\[empty\/missing\/bad digest\] .*$//' \
-e 's/^\(.*\)\/\(.*\)-[0-9][^ ]*/\1\/\2/' \
> ${tmpfile}_2
# sort | uniq
mv -f $tmpfile $resultfile
for str in `cat ${tmpfile}_2`
do
if echo $str | egrep "^[+-]" > /dev/null ; then
if echo $str | egrep "^[+]" > /dev/null ; then
on_flags="${on_flags} `echo $str | sed -e 's/^+//' -e 's/(\(..*\))/\1/'`"
else
off_flags="${off_flags} `echo $str | sed -e 's/^-//' -e 's/(\(..*\))/\1/'`"
fi
else
if [ ! -z "$idist" -a ! -z "$on_flags" -o ! -z "$off_flags" ] ; then
gl_on_flags=`check_flag "${gl_on_flags}" "${on_flags}"`
gl_off_flags=`check_flag "${gl_off_flags}" "${off_flags}"`
show_flags "${idist}" "${dists}" "${on_flags}" "${off_flags}"
# echo -e "\t${idist} \033[01;31m+(${on_flags} ) \033[01;34m-(${off_flags} )\033[00m"
idist=""
off_flags=""
on_flags=""
fi
idist="$str"
fi
done
if [ ! -z "$idist" -a ! -z "$on_flags" -o ! -z "$off_flags" ] ; then
gl_on_flags=`check_flag "${gl_on_flags}" "${on_flags}"`
gl_off_flags=`check_flag "${gl_off_flags}" "${off_flags}"`
show_flags "${idist}" "${dists}" "${on_flags}" "${off_flags}"
fi
gl_on_flags=`echo $gl_on_flags | sed -e 's/^ //'`
gl_off_flags=`echo $gl_off_flags | sed -e 's/^ //'`
echo -e "\t\tGlobal \033[01;31mon\033[00m flags is:\n${gl_on_flags}"
echo -e "\t\tGlobal \033[01;34moff\033[00m flags is:\n${gl_off_flags}"
if noyes "Show info about every offing flag?" ; then
for ff in `echo ${gl_off_flags}` ; do
euse -i $ff
done
fi
echo -e "\tLook $resultfile for logs..."
}
relist_distgroup()
{
group_name=$1
group_flags=$2
group_dists=$3
someerr=""
LOGFILE="${OUTDIR}/LOG_${group_name}.txt"
GRFILE="${OUTDIR}/${group_name}.txt"
echo -e "\t\tReconstruct tarballs list of '$group_name'"
if [ -n "$group_flags" ] ; then
echo -e "\tUse flags next:"
echo $group_flags
else
echo -e "\tNo use flags (will be default)"
fi
echo -e "\tDistribs next:"
echo $group_dists
USE="${group_flags}" emerge -feDv ${group_dists} 2>/dev/null > $LOGFILE
if grep "Some fetch errors were encountered" $LOGFILE > /dev/null ; then
someerr="Some err..."
fi
egrep "^>>> md5 src_uri ;-\) .*" $LOGFILE | awk '{ print $5 }' > $GRFILE
checktarballs $GRFILE
if [ ! -z "$someerr" ] ; then
echo "Some fetch errors were encountered. Please see '$LOGFILE' for details."
fi
}
parse_grlist()
{
doworkrecreate=$1
groupdist=""
useflags=""
dists=""
douselines=0
groups_list="bootstrap"
while read string ; do
if [ $douselines -eq 1 ] ; then
if [ -z "`echo $string | grep '"'`" ] ; then
useflags="$useflags $string"
else
douselines=0
adddists=`echo $string | cut -d\" -f2`
addflags=`echo $string | cut -d\" -f1`
if [ -n "$adddists" -a ! "_$adddists" == "_" ] ; then
dists="${dists} ${adddists}"
fi
useflags="$useflags $addflags"
fi
else
if [ -z "$string" ] ; then
if [ ! -z "$groupdist" ] ; then
grname=""
dists=`echo $dists | sed -r "s/^ //"`
#
# We can skip recreate trbls list of group
# by using '#' at begining of the line
# with groupname.
#
if [ ! -z "`echo $groupdist | egrep '^#'`" ] ; then
if [ $doworkrecreate -eq 1 ] ; then
echo "skiping group dists: $groupdist"
fi
grname=`echo $groupdist | sed -r "s/^#[ \t]*//"`
else
if [ $doworkrecreate -eq 1 ] ; then
relist_distgroup "$groupdist" "$useflags" "$dists"
fi
grname=`echo $groupdist | sed -r "s/^[ \t]*//"`
fi
echo -e "${useflags}" > ${OUTDIR}/GROUP_f_${grname}.txt
echo -e "${dists}" > ${OUTDIR}/GROUP_d_${grname}.txt
groups_list="$groups_list $grname"
#echo $grname
groupdist=""
useflags=""
dists=""
fi
fi
if [ -z "$groupdist" ] ; then
groupdist=$string
elif [ -n "`echo $string | egrep '^USE="'`" ] ; then
useline=`echo $string | sed -r 's/^USE="//'`
if [ -z "`echo $useline | grep '"'`" ] ; then
useflags="$useline"
douselines=1
else
adddists=`echo $useline | cut -d\" -f2`
useflags=`echo $useline | cut -d\" -f1`
if [ -n "$adddists" -a ! "_$adddists" == "_" ] ; then
dists="${dists} ${adddists}"
fi
fi
else
dists="${dists} ${string}"
fi
fi
done
groups_list=`echo $groups_list | sed -r "s/^ //"`
}
calc_tarballs_size()
{
error=0
grsize=0
file=$1
if [ ! -f $file ] ; then
echo
echo "Can't find '$groupfile'"
return 0
fi
for tb in `cat $file`; do
if [ -f ${DISTDIR}/$tb ] ; then
tb_size=`ls -al ${DISTDIR}/$tb | awk '{ print $5 }'`
grsize=`echo "$grsize + $tb_size + 0" | bc`
else
echo
echo -e "\tERROR:: $tb"
error=`echo "$error + 1" | bc`
fi
done
if [ $error -ne 0 ] ; then
echo
echo "Found some errors: $error"
fi
grsize_mb=`echo "$grsize / 1024 / 1024" | bc`
echo "$grsize (${grsize_mb}Mb)"
return ${grsize_mb}
}
calc_group_size()
{
dist_group=$1
echo -n "Calculate size of '$dist_group' group: "
calc_tarballs_size "${OUTDIR}/${dist_group}.txt"
}
calc_cd_size()
{
dist_cd=$1
echo -n "Calculate size of '$dist_cd' CD [`cat ${OUTDIR}/CD${dist_cd}_groups.txt`]: "
calc_tarballs_size "${OUTDIR}/CD${dist_cd}.txt"
}
###################################################################
########################## Start programm #########################
###################################################################
while getopts "u:h" opt
do
case $opt in
h) usage
exit 2
;;
u) parse_grlist 0 < "$GRLIST"
showuflags_group $OPTARG
exit 0
;;
esac
done
if [ "$OPTIND" -gt 1 ] ; then
shift $[$OPTIND - 1]
fi
if noyes "Relisting bootstrap?" ; then
/usr/portage/scripts/bootstrap.sh -f 2>/dev/null > ${OUTDIR}/log_bootstrap1.txt
egrep "^>>> md5 src_uri ;-\) .*" ${OUTDIR}/log_bootstrap1.txt | awk '{ print $5 }' \
> ${OUTDIR}/bootstrap_tmp.txt
# /usr/portage/scripts/bootstrap-2.6.sh -f 2>/dev/null > ${OUTDIR}/log_bootstrap2.txt
# egrep "^>>> md5 src_uri ;-\) .*" ${OUTDIR}/log_bootstrap2.txt | awk '{ print $5 }' \
# >> ${OUTDIR}/bootstrap_tmp.txt
sort ${OUTDIR}/bootstrap_tmp.txt | uniq > ${OUTDIR}/bootstrap.txt
checktarballs ${OUTDIR}/bootstrap.txt
rm -rf ${OUTDIR}/bootstrap_tmp.txt
else
echo "ok, skiping"
fi
if noyes "Create(Recreate) tarballs list of distribs?" ; then
parse_grlist 1 < "$GRLIST"
else
parse_grlist 0 < "$GRLIST"
fi
echo "Finded groups: $groups_list"
if noyes "Show some stats of groups?" ; then
for group in `echo $groups_list` ; do
calc_group_size $group
done
fi
rm -f $OUTDIR/CD?.txt
icd=1
while [ $icd -le $MAXCD ] ; do
cdgrfile="$OUTDIR/CD${icd}_groups.txt"
cdtbfile="$OUTDIR/CD${icd}.txt"
tmpfile="$OUTDIR/_tmp_$!"
if [ -f $cdgrfile ] ; then
defaultgrcd=`cat $cdgrfile`
dftgrcdstr="[$defaultgrcd]"
else
defaultgrcd=""
dftgrcdstr=""
fi
echo -n "What groups you choose for '$icd' CD ?${dftgrcdstr}: "
read cd_groups
if [ -z "$cd_groups" ] ; then
if [ ! -z "$defaultgrcd" ] ; then
cd_groups="$defaultgrcd"
# echo "Using defaults: $defaultgrcd"
else
echo "You must choose groups first!"
exit 1
fi
fi
echo "$cd_groups" > $cdgrfile
(
for grcd in `cat $cdgrfile` ; do
for tbf in `cat ${OUTDIR}/${grcd}.txt` ; do
if [ -z "`/bin/grep $tbf $OUTDIR/CD?.txt 2>/dev/null`" ] ; then
echo $tbf
fi
done
done
) | sort | uniq > $tmpfile
mv -f $tmpfile $cdtbfile
icd=`echo $icd + 1 | bc`
done
if noyes "Calc CD discs sizes?" ; then
icd=1
while [ $icd -le $MAXCD ] ; do
calc_cd_size $icd
icd=`echo $icd + 1 | bc`
done
fi
if noyes "Move prepared tarballs to CD's 'dist' directories?" ; then
icd=1
while [ $icd -le $MAXCD ] ; do
cddistdir="${CDDIR}/gentoo-${icd}/dists"
cdtbfile="$OUTDIR/CD${icd}.txt"
error=0
count=0
mkdir -p ${cddistdir}
for tbf in `cat $cdtbfile` ; do
count=`echo "$count + 1" | bc`
if [ -f ${DISTDIR}/$tbf ] ; then
mv ${DISTDIR}/$tbf $cddistdir
else
error=`echo "$error + 1" | bc`
fi
done
success=`echo "${count} - ${error}" | bc`
echo "Tarballs for CD${icd} moved: [${success} / ${count}]"
if [ $error -ne 0 ] ; then
if noyes "Can't find some (${error}) tarrbals, check CD${icd} list?" ; then
mv $cddistdir/* ${DISTDIR}
checktarballs $cdtbfile
fi
fi
icd=`echo $icd + 1 | bc`
done
fi
echo "done"
|
Script read $GRLIST config file and interactive create $MAXCD
directories with tarballs. Example of config ($GRLIST):
Code: |
system
system
sysutils
USE="pnp ruby 3dfx gamma i8x0 rage128 radeon sis qt kde gnome socks5 tcltk
gatos acl cscope vim-with-x caps dvdr maildir activefilter ipv6"
pciutils net-tools vixie-cron usbutils quota netkit-base mkinitrd mii-diag
lsof lm-sensors i2c kudzu grub lilo eject daemontools cloop attr at apmd
anacron acpid syslinux dosfstools evms ext2resize ntfsprogs mtools lvm-user
lvm2 reiserfsprogs progsreiserfs raidtools xfsprogs gdb addpatches
app-admin/analog
cronolog killproc metalog procinfo sudo sysstat rar zip arc rpm rpm2targz arj
cdrtools cdrdao gnupg howto-text nano vim joe epm gentoolkit mirrorselect zsh
dos2unix ipcalc
psutils rcs unix2dos hotplug nvidia-kernel nforce-net nforce-audio e100
e1000 emu10k1 ati-drivers genkernel xfree-drm pcmcia-cs syslog-ng
rp-pppoe screen sysklogd nvidia-glx sys-kernel/development-sources
daemons
USE="imap postgres qt informix firebird innodb sasl lcms tiff wmf tetex
apache2 curl flash freetds gd mcal odbc yaz oci8 fam fax maildir oav
exiscan-acl lmtp ipv6 afs acl slp"
mysql cvs php qmail squirrelmail openldap cups cups-pdf foomatic net-print/omni
bind apache xinetd oops courier-imap courier cyrus-imapd
cyrus-imap-admin clamav exim mailx getmail sendmail squid esound samba
vsftpd ftpd dhcpcd ntp
nettools
USE="javascript fbcon tiff oav acl activefilter ipv6"
nmap minicom pppconfig wvdial pppoed bind-tools ftp lynx traceroute
mgetty iptables nfs-utils bitchx iputils fetchmail ppp
mailx procmail dhcp netkit-routed netkit-bootpd netkit-fingerd
netkit-rsh netkit-talk netkit-telnetd netkit-tftp netkit-timed taylor-uucp
whois portmap leafnode links mtr trafshow
wm
USE="xinerama ipv6 gstreamer acpi guile dvdr accessibility slp pda sse
speex nas gphoto2 scanner tetex kde dvd arts"
fluxbox gnome kde windowmaker wmclock wmcalc wmail gkrellm wmnetload
x11-terms/aterm xscreensaver
xapps
USE="tiff jbig lcms wmf ipv6 mozaccess mozcalendar clamav dillo pda xface kde
mmx xml arts dga dvb dvd fbcon ggi sse gstreamer qt dv dvdr flac Xaw3d canna
dnd freewnn mule nas postgres mozilla gtk"
gimp gimp-print mozilla sylpheed-claws x11-themes/sylpheed-iconset
mozilla-firebird opera xchat xmms alsa-xmms media-fonts/urw-fonts
net-www/netscape-flash
mplayer xmule tkabber psi epiphany galeon gnomemeeting xpdf gpdf cdparanoia
k3b xv openoffice nedit gtksee gqview gentoo xemacs app-xemacs/gnus
emul
USE="arts nas"
wine dosemu glukalka spectemu zsnes gens epsxe dosbox
utils
USE="tetex lcms tiff wmf imap maildir"
memtest86 zisofs-tools alsa-driver alsa-utils alsa-lib alsa-oss cdparanoia
lame fontconfig cabextract antiword aspell ispell ispell-ru aspell-ru
aspell-en enscript pstotext a2ps apsfilter mutt pine centericq mpg123 sox mc
devel
USE="tetex socks5 tcltk"
motor anjuta ddd ruby
games
USE="xinerama arts dga fbcon ggi nas fusion mmx sse Xaw3d dedicated 3dfx qt
offensive"
nethack fortune-mod fortune-mod-all xbill freeciv tuxracer quake2-icculus
quake2-data quake3 quake3-osp quake1 aaquake2 soldieroffortune ttyquake
tf scorched3d qstat app-sci/chessbrain games-board/gnuchess zangband
# other
inn
|
Example of work with script:
Code: |
# ./get_list_tarballs.sh
Relisting bootstrap? [N/y] n
ok, skiping
Create(Recreate) tarballs list of distribs? [N/y] n
Finded groups: bootstrap system sysutils daemons nettools wm xapps emul utils devel games other
Show some stats of groups? [N/y] y
Calculate size of 'bootstrap' group: 59548670 (56Mb)
Calculate size of 'system' group: 347604273 (331Mb)
Calculate size of 'sysutils' group: 571972659 (545Mb)
Calculate size of 'daemons' group: 570338839 (543Mb)
Calculate size of 'nettools' group: 364594027 (347Mb)
Calculate size of 'wm' group: 864975351 (824Mb)
Calculate size of 'xapps' group: 972899013 (927Mb)
Calculate size of 'emul' group: 444836462 (424Mb)
Calculate size of 'utils' group: 529717583 (505Mb)
Calculate size of 'devel' group: 517371806 (493Mb)
Calculate size of 'games' group: 619038913 (590Mb)
Calculate size of 'other' group:
Can't find ''
What groups you choose for '1' CD ?[bootstrap system sysutils]:
What groups you choose for '2' CD ?[wm nettools utils daemons emul devel]:
What groups you choose for '3' CD ?[xapps games]:
Calc CD discs sizes? [N/y] y
Calculate size of '1' CD [bootstrap system sysutils]: 554759164 (529Mb)
Calculate size of '2' CD [wm nettools utils daemons emul devel]: 606849735 (578Mb)
Calculate size of '3' CD [xapps games]: 529567826 (505Mb)
Move prepared tarballs to CD's 'dist' directories? [N/y] n
done
|
Also this script can help with choosing USE flags:
Code: |
# ./get_list_tarballs.sh -u devel
dev-util/motor +(nls)
net-libs/libwww +(mysql ssl)
app-text/tetex +(X)
gnome-base/gnome-print +(nls tetex)
gnome-base/oaf +(nls)
gnome-base/bonobo +(nls)
net-misc/dante +(tcpd) -(debug)
dev-lang/ruby +(socks5 tcltk) -(ruby16)
Global on flags is:
nls mysql ssl X tetex tcpd socks5 tcltk
Global off flags is:
debug ruby16
Show info about every offing flag? [N/y] y
debug [-] [ ] [G] Tells configure and the makefiles to build for debugging.
Effects vary acrosss packages, but generally it will at
least add -g to CFLAGS. Remember to set FEATURES+=nostrip
too.
ruby16 [-] [ ] [L] [dev-lang/ruby] : Use ruby-1.6 as default ruby
Look /var/tmp/process/out/GROUP_pv_devel.txt for logs...
|
I using this script for create distributives(snapshot of fresh gentoo-world) for my friends.
This very simple and fast: edit config, run - and burn CDs  |
|
Back to top |
|
 |
grudge Tux's lil' helper


Joined: 26 Oct 2002 Posts: 77 Location: South Africa
|
Posted: Wed Feb 25, 2004 9:58 am Post subject: |
|
|
I dont' understand this. Whats this supposed to do exaclty ? |
|
Back to top |
|
 |
irf2003 Veteran

Joined: 10 Sep 2003 Posts: 1078
|
Posted: Wed Feb 25, 2004 5:26 pm Post subject: |
|
|
why don't you use the gentoo tool "catalyst"
hth |
|
Back to top |
|
 |
steel300 Veteran


Joined: 10 Jul 2003 Posts: 1155
|
Posted: Wed Feb 25, 2004 6:17 pm Post subject: |
|
|
I haven't hadtime to play with catalyst, and your script made it really easy to migrate my system to a new machine. Good Work. _________________ Rationality is the recognition of the fact that nothing can alter the truth and nothing can take precedence over that act of perceiving it. |
|
Back to top |
|
 |
xorader n00b

Joined: 07 Oct 2003 Posts: 9
|
Posted: Thu Feb 26, 2004 2:48 pm Post subject: |
|
|
this script parsing lines from 'USE="..." emerge -fveD <packets>' output and create(and download) listing of require tarballs. Then this script split require tarballs by group and then by CD's... |
|
Back to top |
|
 |
Chickpea l33t

Joined: 03 Jun 2002 Posts: 846 Location: Vancouver WA
|
Posted: Thu Feb 26, 2004 6:23 pm Post subject: |
|
|
grudge wrote: | I dont' understand this. Whats this supposed to do exaclty ? |
Me too...what is the purpose? Is this just cloning an existing install? |
|
Back to top |
|
 |
Serj n00b

Joined: 04 Aug 2003 Posts: 46 Location: Ukraine
|
Posted: Fri Feb 27, 2004 7:00 am Post subject: |
|
|
Great!
And this is my attempt to do the same. |
|
Back to top |
|
 |
xorader n00b

Joined: 07 Oct 2003 Posts: 9
|
Posted: Fri Feb 27, 2004 1:27 pm Post subject: |
|
|
Chickpea wrote: | grudge wrote: | I dont' understand this. Whats this supposed to do exaclty ? |
Me too...what is the purpose? Is this just cloning an existing install? |
No... this script prepare a list of require list of tarballs (with all dependes!) for selected packages/ebuilds. I will upgrade this script soon (will add comments and functionals). |
|
Back to top |
|
 |
unnamed n00b

Joined: 08 May 2004 Posts: 50 Location: Russia, Velikiy Novgorod
|
Posted: Mon May 10, 2004 9:32 am Post subject: Re: ... |
|
|
Script doesn't work. |
|
Back to top |
|
 |
|