I did code review in order to write the "3.5. Initrd of ISO created by 'upnkernel' command".
http://forum.porteus.org/viewtopic.php? ... 788#p34856
The result as following might be my mistakes.
1. export_variables() in functions
Code: Select all
#======================================
# export_variables:
# Injects some variables into a config file
#--------------------------------------
export_variables()
{
uep=/union/etc/porteus.conf
if [ ! `grep -o "DISTRO=" $uep` ]
then
echo "DISTRO=porteus" >> $uep
fi
sed -i '/BOOTDEV/d' $uep
sed -i '/BASEDIR/d' $uep
sed -i '/PORTDIR/d' $uep
sed -i '/MODDIR/d' $uep
if [ "$BOOTDEV" ]
then
echo "BOOTDEV=$BOOTDEV" >> /union/etc/porteus.conf
else
echo "BOOTDEV=$SGNDEV" >> /union/etc/porteus.conf
fi
echo "BASEDIR=${PTH%/*}" >> /union/etc/porteus.conf
echo "PORTDIR=$PTH" >> /union/etc/porteus.conf
echo "MODDIR=$MODDIR" >> /union/etc/porteus.conf
uee=/union/etc/environment
if [ ! `grep -o "DISTRO=" $uee` ]
then
echo "DISTRO=porteus" >> $uee
fi
sed -i '/BOOTDEV/d' $uee
sed -i '/BASEDIR/d' $uee
sed -i '/PORTDIR/d' $uee
sed -i '/MODDIR/d' $uee
if [ "$BOOTDEV" ]
then
echo "BOOTDEV=$BOOTDEV" >> /union/etc/environment
else
echo "BOOTDEV=$SGNDEV" >> /union/etc/environment
fi
echo "BASEDIR=${PTH%/*}" >> /union/etc/environment
echo "PORTDIR=$PTH" >> /union/etc/environment
echo "MODDIR=$MODDIR" >> /union/etc/environment
}
[before]
-------------------------
network boot
BOOTDEV=/mnt/nfs
iso boot
BOOTDEV=/mnt/isoloop
[after]
------------------------
network boot
BOOTDEV=network
iso boot
BOOTDEV=/mnt/$DEV
2. check_desktop() in functions
Code: Select all
#======================================
# check_desktop:
# checks for desktop module in base
# and adds a service file for systemd
#
#--------------------------------------
check_desktop()
{
# If there is no desktop module then return
if [ `ls $PTH/base | grep -c 003` -eq 0 ]
then
return 0;
fi
## More than one desktop and exit
if [ `ls $PTH/base/ | grep -c "003-"` -gt 1 ]
then
return 0;
fi
dmod=`ls -1 $PTH/base/ | grep 003-`
ulss=usr/lib/systemd/system
ess=etc/systemd/system
if [ ! -d /union/$ess/multi-user.target.wants ]
then
mkdir -p /union/$ess/multi-user.target.wants
fi
# If there is more than 1 then return
mod=${dmod##*/}
case $mod in
003-lxde.xzm | 003-fvwm.xzm )
if [ -e /union/$ulss/lxdm.service ]
then
ln -s /$ulss/lxdm.service /union/$ess/multi-user.target.wants/lxdm.service
fi
;;
003-kde.xzm )
if [ -e /union/$ulss/gdm.service ]
then
ln -s /$ulss/gdm.service /union/$ess/multi-user.target.wants/gdm.service
fi
;;
esac
}
[before]
-------------------------
[ -e /union/$ulss/gdm.service ] && ln -s /$ulss/lxdm.service /union/$ess/multi-user.target.wants/gdm.service
[after]
------------------------
[ -e /union/$ulss/gdm.service ] && ln -s /$ulss/gdm.service /union/$ess/multi-user.target.wants/gdm.service
3. check_firstrun() in functions
Code: Select all
#======================================
# check_firstrun:
# checks for firstrun file in
# $BOOTDEV/config/.firstrun and adds a
# line to bashrc
#--------------------------------------
check_firstrun()
{
## Obviously if the firstrun tag doesn't exist then don't firstrun
if [ ! -e $SGNDEV/config/.firstrun ]
then
return 1
fi
## If config folder is not writable there is no use of firstrun
## since we can't remove the tag file to nullify firstrun at next boot.
if [ ! -w $SGNDEV/config ]
then
firstrun=no
## Check if we are on virtualbox
dmesg | grep -qi vbox
vbox=$?
## If we are in vbox I want to run firstrun anyway. (testing)
if [ $vbox -eq 0 ]
then
firstrun=yes
fi
else
firstrun=yes
fi
## If firstrun exists then append to .bashrc
if [ "$firstrun" = yes ]
then
echo "/usr/local/bin/firstrun" >> /union/root/.bashrc
fi
}
[before]
-------------------------
## Check if we are on virtualbox
vbox=`dmesg | grep -qi vbox`
## If we are in vbox I want to run firstrun anyway. (testing)
[ "$vbox" ] && firstrun=yes
[after]
-------------------------
## Check if we are on virtualbox
dmesg | grep -qi vbox
vbox=$?
## If we are in vbox I want to run firstrun anyway. (testing)
if [ $vbox -eq 0 ]
then
firstrun=yes
fi
Thanks.