second_stage_install.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # Copyright (C) 2017-2018 Daniel Tartavel-jeannot <contact@librepc.com>
  3. # Copyright (C) 2019-2020 Jean-Baptiste Biernacki <j.biernacki@free.fr>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. export ARCH=arm
  18. /usr/bin/chown :shadow /etc/shadow /etc/gshadow /etc/login.defs /etc/pam.d/chage-chfn-chsh /etc/pam.d/chpasswd-newusers /etc/pam.d/system-auth /etc/pam.d/user-group-mod /bin/passwd /bin/chage
  19. /usr/bin/chown :systemd-journal -R /var/log/journal
  20. #Install all packages you need
  21. /usr/bin/dnf --setopt=ignorearch=True --nogpgcheck --assumeyes install basesystem chrony polkit lockdev rng-tools man openssh-server rfkill wireless-tools bluez wpa_supplicant make rsync binutils ldetect usbutils #kernel-desktop-latest # systemd-bootchart libcap-utils keyutils mindi-busybox plymouth-scripts lvm2 #dmsetup
  22. #For dracut :
  23. # /usr/bin/dnf --setopt=ignorearch=True --nogpgcheck --assumeyes install u-boot-tools mindi-busybox plymouth-scripts #systemd-bootchart libcap-utils keyutils lvm2 #dmsetup
  24. # ############################
  25. # ## For compiling a module ##
  26. # ############################
  27. # BUG : Make does not like to build inside chroot. It doesn't find tools. Impossible to build any module there.
  28. # /usr/bin/dnf --setopt=ignorearch=True --nogpgcheck --assumeyes install kernel-source-latest
  29. # #See if it is a Server or Desktop kernel :
  30. # rpm -q kernel-serveur-latest
  31. # if [ 0 -ne ${?} ]; then
  32. # K_INST_VERSION=$(rpm -q kernel-desktop-latest | sed -e 's/kernel-\([[:alnum:]]*\)-latest-\([\.[:digit:]]*\)-\([\.[:alnum:]]*\).*$/\2-\1-\3/' )
  33. # else
  34. # K_INST_VERSION=$(rpm -q kernel-serveur-latest | sed -e 's/kernel-\([[:alnum:]]*\)-latest-\([\.[:digit:]]*\)-\([\.[:alnum:]]*\).*$/\2-\1-\3/' )
  35. # fi
  36. # #Recover the kernel module path :
  37. # K_MOD_PATH=$(urpmf "modules/${K_INST_VERSION}$" | cut -d ':' -f 2)
  38. # #Recover the source version :
  39. # K_SRC_VERSION=$(rpm -q kernel-source-latest | sed -e 's/kernel-source-latest-\([\.[:digit:]]*\)-\([\.[:alnum:]]*\).*$/\1-\2/' )
  40. # #Recover the source path :
  41. # K_SRC_PATH=$(urpmf "src/kernel-${K_SRC_VERSION}$" | cut -d ':' -f 2)
  42. # #Set the default Mageia's configuration file into the source path :
  43. # cp /boot/config-${K_INST_VERSION} ${K_SRC_PATH}/.config
  44. # ## Can't go further... Make does not like to build inside chroot. It doesn't find tools.
  45. # ## Impossible to build any module there.
  46. # ####################################################
  47. # ## To embed a module inside the early boot initrd ##
  48. # ####################################################
  49. # #Set the kernel name :
  50. # KERNELVERSION="5.3.7-desktop-4.mga7"
  51. K_INST_VERSION=$(rpm -q kernel-desktop-latest | sed -e 's/kernel-\([[:alnum:]]*\)-latest-\([\.[:digit:]]*\)-\([\.[:alnum:]]*\).*$/\2-\1-\3/')
  52. # #Set the list of added modules and omitted modules :
  53. # DRIVER_ADD_LIST="8250_dw"
  54. # DRIVER_OMI_LIST="drm"
  55. # #Create a configuration file inside the FS, it will be used by dracut for all kernel update
  56. # echo -e "# Omiting drm as it failed for arm :\nomit_dracutmodules+=\" ${DRIVER_OMI_LIST} \"\n\n# Driver to add for banana Pro (serial) :\nadd_drivers+=\" ${DRIVER_ADD_LIST} \"\n" > /etc/dracut.conf.d/30-bananapro.conf
  57. # #Generate the initrd :
  58. # OUTPUT=$(ARCH=arm CROSS_COMPILE=arm-linux-gnu- dracut --no-compress --force --no-hostonly --local --no-early-microcode --confdir "/etc/dracut.conf.d" --kmoddir="/lib/modules/${K_INST_VERSION}" --xz --printsize --kernel-image /boot/vmlinuz --fstab initrd-${K_INST_VERSION}.img ${K_INST_VERSION} 2>&1 | tee /dev/tty )
  59. dracut --no-compress --force --no-hostonly --local --no-early-microcode --confdir "/etc/dracut.conf.d" --kmoddir="/lib/modules/${K_INST_VERSION}" --xz --printsize --kernel-image /boot/vmlinuz --fstab /boot/initrd-${K_INST_VERSION}.img ${K_INST_VERSION}
  60. ln -r -s /boot/initrd-${K_INST_VERSION}.img /boot/initrd.img
  61. # #Add the uboot header to the initrd file, first, find the file :
  62. # INITRD_FILE="$(echo "${OUTPUT}" | grep "Creating initramfs image file" | sed -e "s/^[*:[:space:][:alnum:]]*'//" -e "s/'.*$//" )"
  63. # #Add the uboot header, the result file will contain a 'u' as prefix-name.
  64. # mkimage -A arm -T ramdisk -C lzma -n initrd -d ${INITRD_FILE} "$(dirname "${INITRD_FILE}")/u$(basename "${INITRD_FILE}")"
  65. # #generate a symlink relative r and symbolic s :
  66. # rm -f /boot/initrd
  67. # ln -r -s "$(dirname "${INITRD_FILE}")/u$(basename "${INITRD_FILE}")" /boot/initrd
  68. ###########################################
  69. ## Install a package from testing repo : ##
  70. ###########################################
  71. # dnf --refresh --enablerepo=updates_testing-\* --assumeyes install kernel-desktop-latest
  72. ############################################
  73. ## Installing the kernel (not on testing) ##
  74. ############################################
  75. # dnf --refresh --assumeyes install kernel-desktop-latest
  76. ###############################################
  77. ## Create a symlink for the lastest kernel : ##
  78. ###############################################
  79. ## As long as the first installed kernel remains installed, the boot.scr script will continue to work, even if the extlinux.conf file is not working with uboot anymore.
  80. # #Last rpm package :
  81. # KERNELRPM=$(rpm -qa --last | grep "^kernel-[sd]e[[:alpha:]]*-[[:digit:]]" | head -n 1 | cut -d ' ' -f 1 | sed -e 's/\(kernel-[[:alnum:]]*-[\.[:digit:]]*-[\.[:alnum:]]*\)-.*/\1/' )
  82. # #Get the vmlinuz file :
  83. # VMLINUZ=$(urpmf ${KERNELRPM} | grep "boot/vmlinuz" | cut -d ':' -f 2)
  84. #Get the vmlinuz file :
  85. VMLINUZ=$(ls --sort=time -1 /boot/vmlinuz-[[:digit:]]* | head -n 1)
  86. rm -f /boot/uvmlinuz
  87. ln -r -s "${VMLINUZ}" /boot/uvmlinuz #For the uboot script
  88. # Normally, /boot/vmlinuz is generated with the /sbin/installkernel script, but it is not generated with chroot.
  89. ln -r -s "${VMLINUZ}" /boot/vmlinuz #For extlinux.conf
  90. ################################
  91. ## Create the extlinux script ##
  92. ################################
  93. # BUG : installkernel call bootloader-config which doesn't process inside a chroot.
  94. # echo -e "\nTrying to generate extlinux script\n"
  95. # K_INST_VERSION=$(rpm -q kernel-desktop-latest | sed -e 's/kernel-\([[:alnum:]]*\)-latest-\([\.[:digit:]]*\)-\([\.[:alnum:]]*\).*$/\2-\1-\3/')
  96. # /sbin/installkernel %{kversion}-$kernel_flavour-%{buildrpmrel}
  97. # bash -x /sbin/installkernel ${K_INST_VERSION}
  98. # perl -d /usr/sbin/bootloader-config --kernel-version ${K_INST_VERSION} --initrd-options '' --action add-kernel
  99. # /usr/sbin/bootloader-config --kernel-version ${K_INST_VERSION} --initrd-options '' --action add-kernel
  100. # echo -e "\nEnd trying to generate extlinux script with errcode ${?}\n"
  101. /usr/bin/chown :chrony -R /etc/chrony.keys /var/log/chrony
  102. /usr/bin/chown :daemon /etc/wpa_supplicant.conf
  103. /usr/bin/chown :tty /bin/write /bin/wall
  104. /usr/bin/chown :lock /sbin/lockdev
  105. /usr/bin/chown :bin /sbin/traceroute
  106. /usr/bin/chown polkitd /etc/polkit-1/rules.d
  107. ## DO NOT EXIT THE SCRIPT. A second part is automatically added in this script during the process in order to create the default user and set root password.