Advertisement
s243a

rcS -- /etc/init.d/ TazPup Files

Mar 5th, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.99 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # /etc/init.d/rcS    : Initial boot script for SliTaz GNU/Linux
  4. # Configuration file : /etc/rcS.conf
  5. #
  6. # rcS is the main initialization script used to check fs, mount, clean,
  7. # run scripts and start daemons.
  8. #
  9. . /etc/init.d/rc.functions
  10. . /etc/rcS.conf
  11.  
  12. # Set PATH, TZ and boot time.
  13. export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
  14.  
  15. fix_nodes(){
  16.  echo "Fixing device nodes..."
  17.  #device nodes created by kernel in initrd are all 'root' group. fix (before starting udevd)...
  18.  chmod 666 /dev/* 2>/dev/null
  19.  chmod 666 /dev/pts/* 2>/dev/null
  20.  chown -R root:tty /dev/pts/ 2>/dev/null
  21.  chmod 666 /dev/null
  22.  chmod 666 /dev/zero
  23.  chmod 666 /dev/[pt]ty* 2>/dev/null
  24.  chmod 666 /dev/ptmx 2>/dev/null
  25.  chmod 777 /dev/pts/
  26.  chgrp tty /dev/[pt]ty* 2>/dev/null
  27.  chown -R root:tty /dev/pts/
  28.  chown root:tty /dev/tty1
  29.  chown root:tty /dev/ptmx
  30.  chgrp tty /dev/console #bugfix 140617
  31.  chmod 777 /dev/console
  32.  chgrp video /dev/fb0 2>/dev/null
  33.  chgrp floppy /dev/fd[0-9] 2>/dev/null
  34.  chgrp disk /dev/[hs]d[a-z]* 2>/dev/null
  35.  chgrp disk /dev/fuse
  36.  chgrp disk /dev/mmcblk* 2>/dev/null
  37.  chgrp disk /dev/nvme* 2>/dev/null
  38.  chgrp cdrom /dev/sr[0-9] 2>/dev/null
  39.  chgrp cdrom /dev/scd[0-9] 2>/dev/null
  40.  chmod 666 /dev/usb/* 2>/dev/null #rcrsn51 finally added 140618
  41.  chmod -R 1777 /dev/shm #SFR .. ditto
  42.  chmod 666 /dev/urandom #and again
  43. }
  44.  
  45. config_soundcard(){
  46.  
  47. nscard="$(cat /proc/asound/cards)"
  48.  
  49. if [ -f /var/hwdata/soundcards.lst ]; then
  50.    oscard="$(cat /var/hwdata/soundcards.lst)"
  51.     if [ "$nscard" != "$oscard" ]; then
  52.      if [ -d /usr/share/alsa/init ]; then
  53.       mv -f /etc/asound.conf /etc/asound.conf.old 2>/dev/null
  54.       mv -f /etc/asound.state /etc/asound.state.old 2>/dev/null
  55.      fi
  56.      
  57.      rm -f /etc/modprobe.d/soundcards.conf 2>/dev/null   
  58.      
  59.      echo "$nscard" > /var/hwdata/soundcards.lst
  60.     fi
  61. else
  62.    echo "$nscard" > /var/hwdata/soundcards.lst
  63.    if [ -d /usr/share/alsa/init ]; then
  64.       mv -f /etc/asound.conf /etc/asound.conf.old 2>/dev/null
  65.       mv -f /etc/asound.state /etc/asound.state.old 2>/dev/null
  66.    fi
  67.    rm -f /etc/modprobe.d/soundcards.conf 2>/dev/null
  68. fi
  69.    
  70. }
  71.  
  72. config_backlight(){
  73. if [ ! -d /etc/backlight-configs ]; then
  74.   mkdir /etc/backlight-configs
  75. fi
  76.        
  77. if [ -d /sys/class/backlight ]; then
  78.  
  79.  vbacklight="$(ls -1 /sys/class/backlight | sort)"
  80.  
  81.     if [ ! -f /var/hwdata/backlights.lst ]; then
  82.       rm -f /etc/xdg/autostart/SSB_*.desktop 2>/dev/null
  83.       echo "$vbacklight" > /var/hwdata/backlights.lst
  84.     else
  85.      blist="$(cat /var/hwdata/backlights.lst)"
  86.         if [ "$blist" != "$vbacklight" ]; then
  87.            while IFS='' read -r line || [[ -n $line ]]
  88.            do
  89.             bl1="$line"
  90.             xbl="$(basename "$bl1" | sed -e "s#---# #g")"
  91.             if [ ! -e "/sys/class/backlight/$bl1" ]; then
  92.               if [ -e /etc/xdg/autostart/SSB_$xbl.desktop ]; then
  93.                mv -f /etc/xdg/autostart/SSB_$xbl.desktop /etc/backlight-configs/ 2>/dev/null
  94.               fi
  95.             else
  96.               if [ ! -e /etc/xdg/autostart/SSB_$xbl.desktop ] && [ -e /etc/backlight-configs/SSB_$xbl.desktop ]; then
  97.                mv -f /etc/backlight-configs/SSB_$xbl.desktop /etc/xdg/autostart/ 2>/dev/null
  98.               fi
  99.             fi
  100.            done < /var/hwdata/backlights.lst
  101.         fi
  102.      echo "$vbacklight" > /var/hwdata/backlights.lst  
  103.     fi
  104. else
  105.  if [ "$(ls -1 /etc/xdg/autostart/ | grep "SSB_")" != "" ]; then
  106.   mv -f /etc/xdg/autostart/SSB_*.desktop /etc/backlight-configs/ 2>/dev/null
  107.  fi
  108.  echo "" > /var/hwdata/backlights.lst
  109. fi 
  110. }
  111.  
  112. get_edid_hash(){
  113.  
  114. for medid in $(ls -1 /sys/class/drm/*/edid 2>/dev/null | grep "card" | grep "-")
  115. do
  116.  sc1="$(dirname $medid)/status"
  117.  if [ "$(cat $sc1)" == "connected" ]; then
  118.   md5sum $medid
  119.  fi
  120. done
  121.        
  122. }
  123.  
  124. set_screen(){
  125.  echo "$1"
  126.  HOME='/root'
  127.  tazx init 2>/dev/null
  128.  echo "$screens" > /var/hwdata/screen.lst
  129. }
  130.  
  131. config_screen(){
  132.    
  133. screens="$(get_edid_hash)" 
  134.  
  135. if [ ! -f /var/hwdata/screen.lst ]; then
  136.  set_screen "Configuring Xorg..."
  137. else
  138.     if [ "$screens" != "$(cat /var/hwdata/screen.lst)" ]; then
  139.      set_screen "Display setup changed. Configuring Xorg..."
  140.     fi
  141. fi 
  142.    
  143. }
  144.  
  145. config_videocard(){
  146. vlist="$(busybox lspci | grep "Class 03" | cut -c 21-29 | sort)"
  147.  
  148. if [ ! -f /var/hwdata/videocards.lst ]; then
  149.     echo 'Configuring Xorg server...'
  150.     HOME='/root'
  151.     tazx init 2>/dev/null
  152.     echo "$vlist" > /var/hwdata/videocards.lst 
  153.     get_edid_hash > /var/hwdata/screen.lst 
  154. else
  155.     ocard=$(cat /var/hwdata/videocards.lst)
  156.     if [ "$vlist" != "$ocard" ]; then
  157.         echo 'Graphics card setup changed. Configuring Xorg server...'
  158.         HOME='/root'
  159.         tazx init 2>/dev/null
  160.         echo "$vlist" > /var/hwdata/videocards.lst
  161.         get_edid_hash > /var/hwdata/screen.lst
  162.     else
  163.       config_screen
  164.     fi
  165. fi 
  166. }
  167.  
  168. config_hardware(){
  169. idev=$(listdev)
  170.  
  171. if [ ! -d /var/hwdata ]; then
  172.  mkdir /var/hwdata
  173. fi
  174.  
  175. if [ ! -f /var/hwdata/onboard-devices.lst ] || [ "$idev" != "$(cat /var/hwdata/onboard-devices.lst)" ]; then
  176.     rm -f /var/lib/detected-modules 2>/dev/null
  177.     tazhw init
  178.     echo "$idev" > /var/hwdata/onboard-devices.lst
  179. elif [ ! -f /var/hwdata/kernel.lst ] || [ "$(uname -r)" != "$(cat /var/hwdata/kernel.lst)" ]; then
  180.     rm -f /var/lib/detected-modules 2>/dev/null
  181.     tazhw init
  182.     uname -r > /var/hwdata/kernel.lst
  183. fi
  184.  
  185. if [ ! -e '/var/lib/detected-modules' ]; then
  186.     tazhw init
  187. fi
  188. }
  189.  
  190. init_readonly(){
  191.        
  192. # Mount /proc
  193. if [ "$(mount | grep "/proc")" == "" ]; then
  194.  action 'Mounting proc filesystem on /proc'
  195.  mount -t proc none /proc
  196.  status
  197. fi
  198.        
  199. }
  200.  
  201. init_readwrite(){
  202.  
  203. # Be quiet
  204.         echo '0 0 0 0' > /proc/sys/kernel/printk
  205.  
  206.         # Store boot messages to log files.
  207.         dmesg > /var/log/dmesg.log &
  208.        
  209.         ##########new udev#################
  210.        
  211.         # Clean up the system and set up tmp dirs.
  212.         # */run/* are tmpfs so they are cleaned up at shutdown.
  213.         if [ "$CLEAN_UP_SYSTEM" == 'yes' ]; then
  214.             action 'Cleaning up the system...'
  215.             mv -f /tmp/bootsysinit.log /var/tmp/
  216.             rm -rf /tmp/* > /dev/null
  217.             mkdir -p /tmp/.X11-unix /tmp/.ICE-unix
  218.             mv -f /var/tmp/bootsysinit.log /tmp/
  219.             chmod -R 1777 /tmp
  220.             status
  221.         else
  222.             echo 'System clean up is disabled in /etc/rcS.conf'
  223.         fi
  224.        
  225.         if [ -f /initrd/tmp/bootinit.log ]; then
  226.          cat /initrd/tmp/bootinit.log > /tmp/puppyboot.log
  227.         fi
  228.  
  229.         cat /tmp/bootsysinit.log >> /tmp/puppyboot.log
  230.        
  231.         mkdir /tmp/pup_event_backend > /dev/null #101210 for logging into, see /sbin/pup_event_backend_modprobe.
  232.         mkdir /tmp/simple_network_setup > /dev/null #101216
  233.         mkdir -p /tmp/pup_event_ipc > /dev/null #130629 for new pup_event IPC.
  234.  
  235.         # Trigger udev and handle hotplug events
  236.         if [ "$UDEV" == 'yes' ]; then
  237.            
  238.             if [ "$(mount | grep "/dev")" == "" ]; then
  239.              action 'Mounting devtmpfs filesystem on /dev'
  240.              mount -t devtmpfs devtmpfs /dev
  241.              status
  242.             fi
  243.            
  244.             [ -d '/lib/udev/devices' ] && cp -af /lib/udev/devices/* /dev/
  245.  
  246.             fix_nodes
  247.  
  248.             if [ -d '/etc/udev/hwdb.d' ]; then
  249.                 echo 'Creating the udev hardware database...'
  250.                 udevadm hwdb --update
  251.             fi
  252.            
  253.             #killall udevd 2>/dev/null
  254.            
  255.             if [ "$(pidof udevd)" == "" ]; then
  256.              echo 'Starting udev daemon...'
  257.              udevd --daemon 2>/dev/null
  258.             fi
  259.  
  260.             echo 'Udevadm requesting events from the Kernel...'
  261.             udevadm trigger
  262.  
  263.             echo 'Udevadm waiting for the event queue to finish...'
  264.             udevadm settle --timeout=120
  265.             # Disable hotplug helper since udevd listen to netlink
  266.             echo '' > /proc/sys/kernel/hotplug
  267.         else
  268.             action 'Executing mdev -s to populate /dev...'
  269.             mdev -s && echo 'mdev' > /proc/sys/kernel/hotplug
  270.             status
  271.         fi
  272.        
  273.         #############################
  274.  
  275.         # Parse cmdline args for earlier boot options. All other boot options
  276.         # are in /etc/init./bootopts.sh.
  277.         action 'Searching for early boot options...'
  278.         opt=$(cmdline_option modprobe); [ -z "$opt" ] || export MODPROBE='yes'
  279.         opt=$(cmdline_option config);   [ -z "$opt" ] || export CONFIG="$opt"
  280.         opt=$(cmdline_option screen);   [ -z "$opt" ] || export SCREEN="$opt"
  281.        
  282.         if [ "$(echo $(cmdline_option pfix) | grep "nox")" != "" ]; then
  283.         export SCREEN="text"
  284.         fi
  285.        
  286.         status
  287.  
  288.         # Handle kernel cmdline parameter modprobe=<module_list>
  289.         if [ -n "$MODPROBE" ]; then
  290.             for i in $(cmdline_option modprobe | tr ',' '\n'); do
  291.                 action 'Loading kernel module: %s' "$i"
  292.                 modprobe $i
  293.                 status
  294.             done
  295.         fi
  296.  
  297.         # Handle kernel cmdline parameter config=<device>,<path> to source a
  298.         # disk init script
  299.         if [ -n "$CONFIG" ]; then
  300.             DEVICE=${CONFIG%,*}
  301.             SCRIPT=${CONFIG#*,}
  302.             echo "Probing $DEVICE..."
  303.             if ! mount -r $DEVICE /mnt; then
  304.                 if echo $DEVICE | grep -Eq '/dev/sd|UUID=|LABEL='; then
  305.                     USBDELAY=$(cat /sys/module/usb_storage/parameters/delay_use)
  306.                     USBDELAY=$((1+$USBDELAY))
  307.                     echo "$DEVICE is potentially a USB device: sleep for $USBDELAY seconds"
  308.                     sleep $USBDELAY
  309.                 fi
  310.                 if ! mount -r $DEVICE /mnt; then
  311.                     CONFIG=''
  312.                 fi
  313.             fi
  314.             action 'Source %s from %s...' "$SCRIPT" "$DEVICE"
  315.             if [ -n "$CONFIG" ]; then
  316.                 . /mnt/$SCRIPT
  317.                 umount /mnt 2>/dev/null || true
  318.             fi
  319.             status
  320.         fi
  321.  
  322.         # Mount /proc/bus/usb
  323.         if [ -d '/proc/bus/usb' ]; then
  324.             action 'Mounting usbfs filesystem on /proc/bus/usb'
  325.             mount -t usbfs usbfs /proc/bus/usb
  326.             status
  327.         fi
  328.  
  329.         # Start syslogd and klogd
  330.         action 'Starting system log daemon: syslogd...'
  331.         syslogd -s $SYSLOGD_ROTATED_SIZE; status
  332.         action 'Starting kernel log daemon: klogd...'
  333.         klogd
  334.         status
  335.    
  336.        
  337.         if [ ! -f /var/hwdata/kernel.lst ] || [ "$(uname -r)" != "$(cat /var/hwdata/kernel.lst)" ]; then
  338.          rm -f /var/lib/detected-modules 2>/dev/null
  339.          sed -i s/"LOAD_MODULES=.*"/"LOAD_MODULES=\"\""/ /etc/rcS.conf
  340.          . /etc/rcS.conf
  341.         fi
  342.            
  343.         # Load all modules listed in config file
  344.         if [ -n "$LOAD_MODULES" ]; then
  345.             colorize 33 'Loading Kernel modules...'
  346.            
  347.             KVER1=$(uname -r)
  348.             modlist="/lib/modules/$KVER1/modules.order"
  349.                          
  350.             for mod in $LOAD_MODULES; do
  351.               if [ "$(cat $modlist | grep "/${mod}.ko")" != "" ] || [ "$(cat $modlist | grep "/${mod}.o")" != "" ] || [ -d /sys/module/$mod ]; then
  352.                  action 'Loading module: %s' "$mod"
  353.                  modprobe $mod
  354.                  status
  355.               fi
  356.             done
  357.         fi
  358.  
  359.         # Detect PCI and USB devices with Tazhw from slitaz-tools. We load
  360.         # kernel modules only at first boot or in Live CD mode.
  361.         config_hardware
  362.  
  363.         # Call udevadm trigger to ensure /dev is fully populated now that all
  364.         # modules are loaded.
  365.         if [ "$UDEV" == 'yes' ]; then
  366.             action 'Triggering udev events: --action=add'
  367.             udevadm trigger --action=add
  368.             status
  369.         fi
  370.        
  371.         /etc/init.d/pup_devinit
  372.         /etc/init.d/pup_preroot
  373.        
  374.         config_soundcard
  375.         config_backlight
  376.        
  377.         # Start all scripts specified with $RUN_SCRIPTS
  378.         for script in $RUN_SCRIPTS; do
  379.             colorize 34 "Processing /etc/init.d/$script"
  380.            
  381.             if [ -e /etc/init.d/$script ]; then
  382.               /etc/init.d/$script
  383.             fi
  384.         done
  385.        
  386.         if [ -f /etc/net-random.cfg ]; then
  387.          . /etc/net-random.cfg
  388.          if [ "$(echo "$RANDOM_HWID" | tr "[a-z]" "[A-Z]")" == "ON" ]; then
  389.            cat /proc/sys/kernel/random/uuid | sed -e "s#-##g" > /var/lib/dbus/machine-id
  390.          fi
  391.         fi
  392.                
  393.         if [ "$(echo $(cmdline_option pfix) | grep "nox")" != "" ]; then
  394.             export SCREEN="text"
  395.         fi     
  396.        
  397.         # Back to a verbose mode
  398.         #(sleep 6; echo '7 4 1 7' > /proc/sys/kernel/printk) &
  399.        
  400.         #if [ "$(mount | grep "/dev")" != "" ]; then
  401.         # fix_nodes
  402.         #fi
  403.        
  404.         if [ -e /etc/init.d/hald ] && [ "$(echo "$RUN_DAEMONS" | grep "hald")" != "" ]; then
  405.           /etc/init.d/dbus start
  406.         fi
  407.        
  408.         # Start all daemons specified with $RUN_DAEMONS
  409.         if [ -n "$RUN_DAEMONS" ]; then
  410.             colorize 33 "Starting all daemons..."
  411.             for daemon in $RUN_DAEMONS; do
  412.                 if [ -e "/etc/init.d/$daemon" ] && [ -x "/etc/init.d/$daemon" ]; then
  413.                  echo "Starting $daemon..."
  414.                  echo -n ""
  415.                  /etc/init.d/$daemon start
  416.                 fi
  417.             done
  418.         fi
  419.        
  420.         killall smbd nmbd 2>/dev/null
  421.        
  422.         # Start X session. Dbus must be started before Xorg and other daemons.
  423.         # We started it here because X is run before RUN_DAEMONS. Sleep, in
  424.         # some live modes we boot too fast and X can't initialize.
  425.  
  426.         if [ "$SCREEN" != 'text' -a \
  427.             -n "$LOGIN_MANAGER" -a \
  428.             -x '/usr/bin/tazx' -a \
  429.             -s '/etc/slitaz/applications.conf' -a \
  430.             -x "/etc/init.d/$LOGIN_MANAGER" ]; then
  431.             # We need Xorg 40-Keyboard.conf and SliTaz applications.conf
  432.                        
  433.             config_videocard
  434.            
  435.             if [ ! -f /etc/X11/xorg.conf.d/40-Keyboard.conf ]; then
  436.               tazx keyboard    
  437.             fi
  438.            
  439.             if [ "$(pidof dbus-daemon)" == "" ]; then
  440.              /etc/init.d/dbus start
  441.              sleep 2
  442.             fi
  443.            
  444.             colorize 36 'Starting X environment in a moment...'
  445.                        
  446.             sleep 1
  447.            
  448.             exec /etc/init.d/$LOGIN_MANAGER start &
  449.         fi
  450.        
  451.        
  452.        
  453.         if [ -n "$MESSAGE" ]; then
  454.             newline
  455.             colorize 32 "$MESSAGE"
  456.         fi
  457.        
  458.         exit
  459. }
  460.  
  461.  
  462. # Main entry point.
  463. # --> readonly --> readwrite
  464.  
  465. colorize 34 'Processing /etc/init.d/rcS...'
  466.  
  467. if [ ! -s '/run/boot.log' ]; then
  468.     # Mount /run as tmpfs runtime data are not written to disk
  469.     mount -t tmpfs tmpfs /run
  470.     # cp -a in tazpkg does not support /var/run symlink
  471.     mount --bind /run /var/run
  472. fi
  473.  
  474. init_readonly 2>&1 | tee -a /run/boot.log
  475.  
  476. mv -f /run/boot.log /var/log/boot.log
  477.  
  478. init_readwrite  2>&1 | tee -a /var/log/boot.log
  479.  
  480. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement