Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: AbNoRMiS on October 14, 2012, 02:56:30 PM
-
hi there :)
here i thought that some of scripts that i usually use
during tinycore startup can be useful for someone else
to have these scripts could start at tinycore boot
first must add red highlighted row to bootlocal.sh
thus bootlocal.sh should look at least like this
bootlocal.sh
#!/bin/sh
[ -d /opt/bootlocal ] && for item in `find /opt/bootlocal -type f`; do [ -x $item ] && $item; done || mkdir -pm775 /opt/bootlocal
# put other system startup commands here
now after reboot can add any scripts to folder /opt/bootlocal
remembering that they must have execute permissions
-
adding icons
script for adding missing or additional icons
for example for start programs under root
adding_icons.sh
#!/bin/sh
ICONDIR=/opt/addicons
[ -d $ICONDIR ] || mkdir -pm775 $ICONDIR
find $ICONDIR -name '*.desktop' -type f -exec ln -sf {} /usr/local/share/applications \;
find $ICONDIR -name '*.png' -or -name '*.xpm' -type f -exec ln -sf {} /usr/local/share/pixmaps \;
now can add any needed icons and desktop files to folder /opt/addicons
examples
for adding icon to run program under root need copy
/tmp/tcloop/extension/usr/local/share/applications/extension.desktop
renaming it to /opt/addicons/extension-root.desktop
and add sudo to command line in Exec key
for adding missing icon need add icon extension.png
or other allowed graphic format to folder /opt/addicons
then create missing desktop file or copy an existing
/tmp/tcloop/extension/usr/local/share/applications/extension.desktop
to /opt/addicons/extension.desktop
and add to it the following row
X-FullPathIcon=/usr/local/share/pixmaps/extension.png
-
home folders
script for creating links in user home folder that are points to actual folders which are placed on the tinycore boot pendrive
actual folders can contain any data but nonpersistent user home folder that contains these links will not too large to backup
at first boot time the actual folders will be created on tinycore boot pendrive accordingly with list which is specified in this script
after each booting these home links will point to its actual folders regardless of device configuration on different computers
home_folders.sh
#!/bin/sh
FOLDERS="Documents Downloads Games Movies Music Pictures Programs Work tmp"
PREFIX="."
BOOTDEV=`readlink /etc/sysconfig/tcedir | cut -f3 -d/` || BOOTDEV=`cat /opt/.tce_dir | cut -f3 -d/`
[ "$BOOTDEV" == "tce" ] && BOOTDEV=`cat /etc/sysconfig/cde | cut -f3 -d/`
USER=`cat /etc/sysconfig/tcuser`
HOME=`eval echo ~$USER`
SYSDIRS="../DEVICES ./BOOT"
for folder in $SYSDIRS; do
REAL=/mnt/$BOOTDEV/${folder%/*}
LINK=$HOME/${folder#*/}
rm -f $LINK
ln -sf $REAL $LINK
done
for folder in $FOLDERS; do
REAL=/mnt/$BOOTDEV/$PREFIX$folder
LINK=$HOME/$folder
mkdir -pm775 $REAL
rm -f $LINK
ln -sf $REAL $LINK
chown $USER:staff $LINK 2>/dev/null
done
folder list and prefix can be changed as someone like
FOLDERS="Documents Downloads Games Movies Music Pictures Programs Work tmp"
PREFIX="."
example
if tinycore boot pendrive got mount point /mnt/sdb1 then links will look like this
~/BOOT -> /mnt/sdb1
~/DEVICES -> /mnt
~/Documents -> /mnt/sdb1/.Documents
~/Downloads -> /mnt/sdb1/.Downloads
~/Games -> /mnt/sdb1/.Games
~/Movies -> /mnt/sdb1/.Movies
~/Music -> /mnt/sdb1/.Music
~/Pictures -> /mnt/sdb1/.Pictures
~/Programs -> /mnt/sdb1/.Programs
~/Work -> /mnt/sdb1/.Work
~/tmp -> /mnt/sdb1/.tmp
-
hi AbNoRMiS,
i like your home_folder.sh.
what could be done to check whether these folders already exist in the boot-device?
if there exists a dir with the same name, a new dir is created inside of the directory, so there is an endless loop.
"mkdir -p dir" doesn't prevent this problem.
do you see there a way to check this in the first place and that you create only new dirs?
thank you for your help.
-
the fact is that command mkdir -p /mnt/$BOOTDEV/$PREFIX${folder%/*} is trying to create absolute folder path
and in this case when such folder already exists then mkdir with option -p does not performs folder creation
tc@box:~$ mkdir --help
BusyBox v1.20.2 (2012-08-07 01:31:01 UTC) multi-call binary.
Usage: mkdir [OPTIONS] DIRECTORY...
Create DIRECTORY
-m MODE Mode
-p No error if exists; make parent directories as needed
this script already tested and work for a long time on my fat32 pendrive and harddrive too
-
hi abnormis,
sorry, the command "mkdir -p /mnt/$BOOTDEV/$PREFIX${folder%/*}" makes no problem at all.
it's the command "ln -sf /mnt/$BOOTDEV/$PREFIX${folder%/*} $HOME/${folder#*/}" that creates an additional link in the link-directory in cases that the link-dir already exist.
i solved the problem with the help of the .xfiletool.lst, that these links are not permanent.
i was affected a couple of times with that problem, so i would appreciate to find a solution.
perhaps you have any idea.
-
hi abnormis,
i solved it quick and dirty with
for folder in $SYSDIRS $FOLDERS; do
mkdir -p /mnt/$BOOTDEV/$PREFIX${folder%/*}
if [ -L $HOME/${folder} ]; then
: # do nothing
else
ln -sf /mnt/$BOOTDEV/$PREFIX${folder%/*} $HOME/${folder#*/}
fi
done
-
indeed i now looked in the old version of this script
and found that some strange way when i cleaned out code
then mistakenly deleted line rm -f $HOME/${folder#*/}
surprising that it worked without creating folders recursively for me
thank you netnomad, that alert me about this annoying bug
p.s.
also i added changing permissions for drives with linux filesystems