frontend_startup 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/ash
  2. #(c) Copyright 2013 Barry Kauler bkhome.org
  3. #2013 Licence GPL3 (/usr/share/doc/legal).
  4. #this is startup code, called from /usr/local/pup_event/pup_event_frontend_d
  5. # (which in turn is called from /root/.xinitrd when X starts).
  6. #the code in this script was extracted from the retired script /sbin/pup_event_frontend_d.
  7. #130609 first version.
  8. #130807 L18L: gettext declaration moved to frontend_funcs.
  9. #export TEXTDOMAIN=pup_event_frontend_d
  10. #export OUTPUT_CHARSET=UTF-8
  11. #. gettext.sh
  12. OLDLANG=$LANG #100613
  13. export LANG=C #w004
  14. sleep 3 #1 #let the dust settle after X has started. 120718 reduce 2 to 1. 121105 try 2, see also /usr/sbin/delayedrun. 121212
  15. #w471 slow cpus need more delay (well, rox does)...
  16. DELAYFACTOR=0
  17. CPUMHZ=`grep -m 1 -i '^cpu MHz' /proc/cpuinfo | tr -d ' ' | cut -f 2 -d ':' | cut -f 1 -d '.'` #my laptop: 933.000
  18. if [ $CPUMHZ ];then
  19. [ $CPUMHZ -gt 100 ] && DELAYFACTOR=$((1600 / $CPUMHZ)) #120829 L18L: need 1 sec for my 1514 MHZ CPU. #`expr 1100 \/ $CPUMHZ`
  20. else #120718 raspi: 697.95 my laptop: 4789.47
  21. BOGOMIPS=`grep -m 1 -i '^bogomips' /proc/cpuinfo | tr -d ' ' | cut -f 2 -d ':' | cut -f 1 -d '.'`
  22. [ $BOGOMIPS ] && [ $BOGOMIPS -gt 200 ] && DELAYFACTOR=`expr 2100 \/ $BOGOMIPS`
  23. fi
  24. [ $DELAYFACTOR -gt 0 ] && sleep $DELAYFACTOR
  25. [ "$DISPLAY" = "" ] && exit 1 #X not running.
  26. #v404 /usr/sbin/video-wizard (Xvesa) does create /var/local/pup_event_icon_change_flag (120213 changed path from /tmp)
  27. #which /sbin/clean_desk_icons reads via .xinirc when X starts, to wipe all drive icons.
  28. #however I think it would be good to test here also if X mode not yet settled on...
  29. if [ -f /tmp/videomode ];then #only exists during X resolution setup.
  30. if [ "`readlink /usr/bin/X`" = "Xvesa" ];then
  31. while [ -f /tmp/videomode ];do
  32. sleep 1
  33. done
  34. fi
  35. fi
  36. #TOGGLE=1
  37. echo -n "" > /tmp/pup_event_frontend_d_curpos.log #see frontend_timeout
  38. ZDRV='';ZDRVINIT='no' #these usually set in PUPSTATE.
  39. . /etc/rc.d/PUPSTATE
  40. PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/X11R7/bin"
  41. #KERNVER="`uname -r`"
  42. . /etc/eventmanager #has RAMSAVEINTERVAL, ICONDESK, HOTPLUGNOISY, ICONPARTITIONS, BACKENDON, POWERTIMEOUT
  43. . /etc/rc.d/functions4puppy4
  44. . /usr/local/pup_event/frontend_funcs
  45. SCRNXY="`xwininfo -root | grep -o '\-geometry .*' | tr -s ' ' | cut -f 2 -d ' ' | cut -f 1 -d '+'`"
  46. SCRN_X="`echo -n "$SCRNXY" | cut -f 1 -d 'x'`"
  47. SCRN_Y="`echo -n "$SCRNXY" | cut -f 2 -d 'x'`"
  48. echo -n "$SCRN_X" > /tmp/pup_event_frontend_scrn_x #read by frontend_change.
  49. echo -n "$SCRN_Y" > /tmp/pup_event_frontend_scrn_y #read by frontend_change.
  50. #RETVALm=1
  51. ######################################################################
  52. #stuff to setup at entry...
  53. mkdir -p /root/.pup_event
  54. #build the desktop icons...
  55. DRV_CATEGORY='drive'
  56. PROBEDISK="`probedisk`"
  57. echo "$PROBEDISK" > /tmp/pup_event_probedisk_startup #130610 read by frontend_timeout.
  58. #v407 ls120/zip floppy drives are probed every 4 secs...
  59. DRVS_FLOPPY="`echo "$PROBEDISK" | grep '|floppy|' | cut -f 1 -d '|' | cut -f 3 -d '/'`"
  60. echo "$DRVS_FLOPPY" > /tmp/pup_event_drvs_floppy #also written by frontend_change, read by frontend_timeout.
  61. #v407 same thing for all optical drives...
  62. DRVS_OPTICAL="`echo "$PROBEDISK" | grep '|optical|' | cut -f 1 -d '|' | cut -f 3 -d '/'`"
  63. echo "$DRVS_OPTICAL" > /tmp/pup_event_drvs_optical #130610 also written by frontend_change, read by frontend_timeout.
  64. if [ "$ICONDESK" = "false" ];then
  65. #only show a single 'drives' icon on desktop...
  66. DRV_NAME='drives'
  67. DRV_CATEGORY='any' #see pmount.
  68. DRV_DESCRIPTION="all drives"
  69. create_icon_func #needs DRV_NAME, DRV_CATEGORY, DRV_DESCRIPTION.
  70. else
  71. #show all drives on desktop... w476 add ext4... 130216 add f2fs...
  72. PROBEPART="`probepart -k | grep -E '\|f2fs\||\|ext4\||\|ntfs\||\|msdos\||\|vfat\||\|ext2\||\|ext3\||\|iso9660\||\|udf\||\|audiocd\||\|xfs\||\|reiser'`"
  73. if [ "$FD0ICON" = "true" ];then #see /etc/eventmanager
  74. if [ -e /sys/block/fd0 ];then
  75. PROBEDISK="/dev/fd0|floppy|Legacy floppy drive
  76. $PROBEDISK"
  77. PROBEPART="/dev/fd0|vfat|1440
  78. $PROBEPART"
  79. fi
  80. fi
  81. for ONEDRV in `echo "$PROBEDISK" | cut -f 1,2,3 -d '|' | tr ' ' '_' | tr '\n' ' '`
  82. do
  83. DRV_NAME="`echo -n "$ONEDRV" | cut -f 1 -d '|' | cut -f 3 -d '/'`"
  84. DRV_CATEGORY="`echo -n "$ONEDRV" | cut -f 2 -d '|'`"
  85. DRV_DESCRIPTION="`echo -n "$ONEDRV" | cut -f 3 -d '|' | tr '_' ' '`"
  86. [ "`echo "$PROBEPART" | grep "$DRV_NAME"`" = "" ] && continue #precaution (such as CD not inserted).
  87. create_icon_func startup #needs DRV_NAME, DRV_CATEGORY, DRV_DESCRIPTION, PROBEPART.
  88. done
  89. fi
  90. if [ "$BACKENDON" = "false" ];then #see /etc/eventmanager.
  91. killall udevd
  92. exit 2
  93. fi
  94. [ "$HOTPLUGON" = "false" ] && exit 3 #turn off all frontend hotplug support. see /etc/eventmanager.
  95. exit 0
  96. ###END###