# fss-0002

main:
  if [ ! -e $system_version_file ] ; then echo -e "# fss-0000\n\n$distribution_name $turtle_version" > $system_version_file ; fi
  if [ ! -e /etc/kevux-release ] ; then echo "$distribution_name kevux $turtle_version" > /etc/kevux-release ; fi
  mkdir -vp /share/icons/
  mkdir -vp /etc/network/
  mkdir -vp ${TC}lib/static/
  mkdir -vp /share/kiwi /etc/kiwi{,/layouts}
  mkdir -vp /etc/profile.d
  mkdir -vp /boot/{grub,settings,live,memtest,system}
  mkdir -vp /share/kbd/
  cp -v ${PR}group /etc/
  ln -vsf icons /share/pixmaps
  tkis_local_push absolute /dev/
  sh ${PR}make_devices
  sh ${PR}make_devices_permissions
  tkis_local_pop
  rm -Rf $root_user_home_dir
  cp -vR ${PR}skel $root_user_home_dir
  mkdir -vp /share/{icons,applications,desktop-directories,fonts,themes}
  mkdir -vp /home/{share,music} /etc/network
  mkdir -vp /etc/skel-targets
  chmod u+rwx,g+rx-w,o+x-rw / /bin /etc /lib /home/{users,targets} /dev /sbin
  chmod u+rwx,g+rxs-w,o+x-rw /etc /share /home /var /mnt
  chmod u+rwx,g+rx-w,o-rwx /sys $root_user_home_dir
  chmod u+rwx,g+rwx,o-rw+x /var/cache
  chmod u+rwx,g+rxs-w,o-rw+x /var/{run,log}
  chmod u+rwx,g+rxs-w,o-rwx /share/{icons,applications,desktop-directories,fonts,themes,kiwi,kbd} /etc/kiwi{,/layouts}
  chmod u+rwx,g+rx-w,o-rw+x /home/users /boot/system
  chmod u+rwx,g+rwxs,o-rw+x /home/{share,music} /etc/network/
  chmod u+rwx,g+rxs-w,o-rwx /checksum /firmware /modules ${TC} /documentation /boot/{grub,settings,live,memtest} /etc/profile.d/
  chmod u+rwx,g+rxs-w,o+x-rw /boot
  chmod u+rwx,g+rxs-w,o-rwx,+t /tmp
  chgrp d_root /
  chgrp d_module -R /firmware /modules
  chgrp d_boot /boot/{,grub,settings,system,live,memtest}
  chgrp d_checksum -R /checksum/
  chgrp d_share -R /home/share
  chgrp d_music -R /home/music
  chgrp d_program /bin
  chgrp d_program_system /sbin
  chgrp d_device /dev
  chgrp d_setting /etc
  chgrp d_home /home
  chgrp d_library /lib
  chgrp d_data /share
  chgrp d_toolchain ${TC}
  chgrp k_system /sys
  chgrp k_process /proc
  chgrp d_temporary /tmp
  chgrp d_mount /mnt
  chgrp d_variable /var
  chgrp d_cache /var/cache
  chgrp d_run /var/run
  chgrp d_log /var/log
  chgrp e_network_admin /etc/network
  chgrp d_user /home/users
  chgrp d_target /home/targets
  chgrp d_lock /var/locks
  chgrp d_icon /share/icons
  chgrp e_application /share/applications /share/desktop-directories /share/themes
  chgrp d_font /share/fonts
  chgrp e_install /share/kiwi /etc/kiwi{,/layouts}
  chgrp e_public /etc/profile.d/
  chgrp e_keymap /share/kbd
  sed -i -e "s|^ROOT_USER_NAME:|u_$root_user_name:|" /etc/group
  chmod u+rw-x,g+r-wx,o-rwx /etc/group
  chgrp e_public /etc/group
  chgrp e_public $system_version_file /etc/kevux-release
  cp -v ${PR}hosts /etc/network/
  cp -v ${PR}resolv.conf /etc/network/resolution
  cp -v ${PR}fstab /etc/
  cp -v ${PR}shells /etc/
  cp -v ${PR}inputrc /etc/
  cp -v ${PR}keymap /etc/
  cp -v ${PR}fstab /etc/
  cp -v ${PR}issue /etc/
  cp -v ${PR}issue2 /etc/
  cp -v ${PR}securetty /etc/
  cp -vR ${PR}skel /etc/
  cp -v ${PR}fix /bin/
  echo "$distribution_name-$RANDOM" > /etc/network/hostname
  echo "127.0.0.1 localhost" >> /etc/network/hosts
  echo "127.0.0.1 $(cat /etc/network/hostname)" >> /etc/network/hosts
  chgrp e_network /etc/network/{hosts,resolution,hostname}
  chgrp e_public /bin/fix
  umount /dev/pts ; true
  umount /proc ; true
  touch /etc/asound.state
  chgrp e_audio /etc/asound.state
  chgrp e_public -R /etc/{shells,inputrc,fstab,issue,issue2,securetty,keymap}
  chgrp 0 -R /etc/skel /etc/skel-targets
  chmod u+rwx,g+rx-w,o-rwx -R /etc/skel /etc/skel-targets
  mkdir -vp /etc/initng
  chgrp -R e_init /etc/initng
  chgrp e_public ${system_version_file}
  cp -v ${PR}olpc.fth /boot/
  chgrp d_boot /boot/olpc.fth
  mkdir -vp ${TC}lib/pkgconfig
  chgrp d_toolchain ${TC}lib/pkgconfig
  chmod g+s ${TC}lib/pkgconfig
  mkdir -vp ${TC}include
  chgrp d_toolchain ${TC}include
  chmod g+s ${TC}include

  # Make sure all of the files that display the Turtle Kevux Version are updated to reflect the TKV version
  sed -i -e "s|FILL_IN_VERSION_HERE|$turtle_version|g" /etc/issue{,2}

  # update Version_Date if medium allows write, otherwise this is not an error so return true
  echo $(date) > $tkis_path/Version_Date || true

  cp -v ${PR}sysctl.conf /etc/
  chmod u+rw-x,g+r-wx,o-rwx /etc/sysctl.conf
