WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: simple useful bootlocal scripting (: subscripting :)  (Read 5620 times)

Offline AbNoRMiS

  • Hero Member
  • *****
  • Posts: 550
  • nothing can be impeccable in this imperfect world
    • @ß№®M!$
simple useful bootlocal scripting (: subscripting :)
« on: October 14, 2012, 05: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
Quote
#!/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
« Last Edit: October 14, 2012, 07:12:13 PM by AbNoRMiS »
Basic Design Concept © @ß№®M!$
please forgive my terrible english :)

Offline AbNoRMiS

  • Hero Member
  • *****
  • Posts: 550
  • nothing can be impeccable in this imperfect world
    • @ß№®M!$
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #1 on: October 14, 2012, 07:11:13 PM »
adding icons
script for adding missing or additional icons
for example for start programs under root
adding_icons.sh
Code: [Select]
#!/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
Quote
X-FullPathIcon=/usr/local/share/pixmaps/extension.png
« Last Edit: October 23, 2012, 06:05:28 AM by AbNoRMiS »
Basic Design Concept © @ß№®M!$
please forgive my terrible english :)

Offline AbNoRMiS

  • Hero Member
  • *****
  • Posts: 550
  • nothing can be impeccable in this imperfect world
    • @ß№®M!$
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #2 on: October 23, 2012, 12:53:03 AM »
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
Code: [Select]
#!/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
Code: [Select]
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
Quote
~/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
« Last Edit: October 25, 2012, 12:39:59 AM by AbNoRMiS »
Basic Design Concept © @ß№®M!$
please forgive my terrible english :)

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #3 on: October 23, 2012, 02:05:57 AM »
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.

Offline AbNoRMiS

  • Hero Member
  • *****
  • Posts: 550
  • nothing can be impeccable in this imperfect world
    • @ß№®M!$
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #4 on: October 23, 2012, 04:08:40 AM »
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
Code: [Select]
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
« Last Edit: October 23, 2012, 04:12:56 AM by AbNoRMiS »
Basic Design Concept © @ß№®M!$
please forgive my terrible english :)

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #5 on: October 23, 2012, 04:28:35 AM »
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.

Offline netnomad

  • Hero Member
  • *****
  • Posts: 1026
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #6 on: October 23, 2012, 04:57:54 AM »
hi abnormis,

i solved it quick and dirty with

Quote
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
« Last Edit: October 23, 2012, 05:14:45 AM by netnomad »

Offline AbNoRMiS

  • Hero Member
  • *****
  • Posts: 550
  • nothing can be impeccable in this imperfect world
    • @ß№®M!$
Re: simple useful bootlocal scripting (: subscripting :)
« Reply #7 on: October 23, 2012, 05:16:07 AM »
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
« Last Edit: October 23, 2012, 05:44:40 AM by AbNoRMiS »
Basic Design Concept © @ß№®M!$
please forgive my terrible english :)