desktop.sh 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
  4. #
  5. # This file is licensed under the terms of the GNU General Public
  6. # License version 2. This program is licensed "as is" without any
  7. # warranty of any kind, whether express or implied.
  8. # Functions:
  9. # create_desktop_package
  10. # install_ppa_prerequisites
  11. # add_apt_sources
  12. # add_desktop_package_sources
  13. # desktop_postinstall
  14. create_desktop_package ()
  15. {
  16. echo "Showing PACKAGE_LIST_DESKTOP before postprocessing" >> "${DEST}"/${LOG_SUBPATH}/output.log
  17. # Use quotes to show leading and trailing spaces
  18. echo "\"$PACKAGE_LIST_DESKTOP\"" >> "${DEST}"/${LOG_SUBPATH}/output.log
  19. # Remove leading and trailing spaces with some bash monstruosity
  20. # https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable#12973694
  21. DEBIAN_RECOMMENDS="${PACKAGE_LIST_DESKTOP#"${PACKAGE_LIST_DESKTOP%%[![:space:]]*}"}"
  22. DEBIAN_RECOMMENDS="${DEBIAN_RECOMMENDS%"${DEBIAN_RECOMMENDS##*[![:space:]]}"}"
  23. # Replace whitespace characters by commas
  24. DEBIAN_RECOMMENDS=${DEBIAN_RECOMMENDS// /,};
  25. # Remove others 'spacing characters' (like tabs)
  26. DEBIAN_RECOMMENDS=${DEBIAN_RECOMMENDS//[[:space:]]/}
  27. echo "DEBIAN_RECOMMENDS : ${DEBIAN_RECOMMENDS}" >> "${DEST}"/${LOG_SUBPATH}/output.log
  28. # Replace whitespace characters by commas
  29. PACKAGE_LIST_PREDEPENDS=${PACKAGE_LIST_PREDEPENDS// /,};
  30. # Remove others 'spacing characters' (like tabs)
  31. PACKAGE_LIST_PREDEPENDS=${PACKAGE_LIST_PREDEPENDS//[[:space:]]/}
  32. local destination tmp_dir
  33. tmp_dir=$(mktemp -d)
  34. destination=${tmp_dir}/${BOARD}/${CHOSEN_DESKTOP}_${REVISION}_all
  35. rm -rf "${destination}"
  36. mkdir -p "${destination}"/DEBIAN
  37. echo "${PACKAGE_LIST_PREDEPENDS}" >> "${DEST}"/${LOG_SUBPATH}/output.log
  38. # set up control file
  39. cat <<-EOF > "${destination}"/DEBIAN/control
  40. Package: ${CHOSEN_DESKTOP}
  41. Version: $REVISION
  42. Architecture: all
  43. Maintainer: $MAINTAINER <$MAINTAINERMAIL>
  44. Installed-Size: 1
  45. Section: xorg
  46. Priority: optional
  47. Recommends: ${DEBIAN_RECOMMENDS//[:space:]+/,}, orangepi-bsp-desktop
  48. Provides: ${CHOSEN_DESKTOP}, orangepi-${RELEASE}-desktop
  49. Pre-Depends: ${PACKAGE_LIST_PREDEPENDS//[:space:]+/,}
  50. Description: Orange Pi desktop for ${DISTRIBUTION} ${RELEASE}
  51. EOF
  52. # Recreating the DEBIAN/postinst file
  53. echo "#!/bin/sh -e" > "${destination}/DEBIAN/postinst"
  54. local aggregated_content=""
  55. aggregate_all_desktop "debian/postinst" $'\n'
  56. echo "${aggregated_content}" >> "${destination}/DEBIAN/postinst"
  57. echo "exit 0" >> "${destination}/DEBIAN/postinst"
  58. chmod 755 "${destination}"/DEBIAN/postinst
  59. #display_alert "Showing ${destination}/DEBIAN/postinst"
  60. cat "${destination}/DEBIAN/postinst" >> "${DEST}"/${LOG_SUBPATH}/install.log
  61. # OrangePi create_desktop_package scripts
  62. unset aggregated_content
  63. mkdir -p "${destination}"/etc/orangepi
  64. local aggregated_content=""
  65. aggregate_all_desktop "orangepi/create_desktop_package.sh" $'\n'
  66. eval "${aggregated_content}"
  67. [[ $? -ne 0 ]] && display_alert "create_desktop_package.sh exec error" "" "wrn"
  68. display_alert "Building desktop package" "${CHOSEN_DESKTOP}_${REVISION}_all" "info"
  69. mkdir -p "${DEB_STORAGE}/${RELEASE}"
  70. cd "${destination}"; cd ..
  71. fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${DEB_STORAGE}/${RELEASE}/${CHOSEN_DESKTOP}_${REVISION}_all.deb" >/dev/null
  72. # cleanup
  73. rm -rf "${tmp_dir}"
  74. unset aggregated_content
  75. }
  76. create_bsp_desktop_package ()
  77. {
  78. display_alert "Creating board support package for desktop" "${package_name}" "info"
  79. local package_name="${BSP_DESKTOP_PACKAGE_FULLNAME}"
  80. local destination tmp_dir
  81. tmp_dir=$(mktemp -d)
  82. destination=${tmp_dir}/${BOARD}/${BSP_DESKTOP_PACKAGE_FULLNAME}
  83. rm -rf "${destination}"
  84. mkdir -p "${destination}"/DEBIAN
  85. copy_all_packages_files_for "bsp-desktop"
  86. # set up control file
  87. cat <<-EOF > "${destination}"/DEBIAN/control
  88. Package: orangepi-bsp-desktop-${BOARD}
  89. Version: $REVISION
  90. Architecture: $ARCH
  91. Maintainer: $MAINTAINER <$MAINTAINERMAIL>
  92. Installed-Size: 1
  93. Section: xorg
  94. Priority: optional
  95. Provides: orangepi-bsp-desktop, orangepi-bsp-desktop-${BOARD}
  96. Depends: ${BSP_CLI_PACKAGE_NAME}
  97. Description: Orange Pi Board Specific Packages for desktop users using $ARCH ${BOARD} machines
  98. EOF
  99. # Recreating the DEBIAN/postinst file
  100. echo "#!/bin/sh -e" > "${destination}/DEBIAN/postinst"
  101. local aggregated_content=""
  102. aggregate_all_desktop "debian/orangepi-bsp-desktop/postinst" $'\n'
  103. echo "${aggregated_content}" >> "${destination}/DEBIAN/postinst"
  104. echo "exit 0" >> "${destination}/DEBIAN/postinst"
  105. chmod 755 "${destination}"/DEBIAN/postinst
  106. # Orange Pi create_desktop_package scripts
  107. unset aggregated_content
  108. mkdir -p "${destination}"/etc/orangepi
  109. local aggregated_content=""
  110. aggregate_all_desktop "debian/orangepi-bsp-desktop/prepare.sh" $'\n'
  111. eval "${aggregated_content}"
  112. [[ $? -ne 0 ]] && display_alert "prepare.sh exec error" "" "wrn"
  113. mkdir -p "${DEB_STORAGE}/${RELEASE}"
  114. cd "${destination}"; cd ..
  115. fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${destination}" "${DEB_STORAGE}/${RELEASE}/${package_name}.deb" >/dev/null
  116. # cleanup
  117. rm -rf "${tmp_dir}"
  118. unset aggregated_content
  119. }
  120. install_ppa_prerequisites() {
  121. # Myy : So... The whole idea is that, a good bunch of external sources
  122. # are PPA.
  123. # Adding PPA without add-apt-repository is poorly conveninent since
  124. # you need to reconstruct the URL by hand, and find the GPG key yourself.
  125. # add-apt-repository does that automatically, and in a way that allows you
  126. # to remove it cleanly through the same tool.
  127. # Myy : TODO Try to find a way to install this package only when
  128. # we encounter a PPA.
  129. run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get install -yqq software-properties-common"
  130. }
  131. add_apt_sources() {
  132. local potential_paths=""
  133. local sub_dirs_to_check=". "
  134. if [[ ! -z "${SELECTED_CONFIGURATION+x}" ]]; then
  135. sub_dirs_to_check+="config_${SELECTED_CONFIGURATION}"
  136. fi
  137. get_all_potential_paths "${DEBOOTSTRAP_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt"
  138. get_all_potential_paths "${CLI_SEARCH_RELATIVE_DIRS}" "${sub_dirs_to_check}" "sources/apt"
  139. get_all_potential_paths "${DESKTOP_ENVIRONMENTS_SEARCH_RELATIVE_DIRS}" "." "sources/apt"
  140. get_all_potential_paths "${DESKTOP_APPGROUPS_SEARCH_RELATIVE_DIRS}" "${DESKTOP_APPGROUPS_SELECTED}" "sources/apt"
  141. display_alert "Adding additional apt sources"
  142. for apt_sources_dirpath in ${potential_paths}; do
  143. if [[ -d "${apt_sources_dirpath}" ]]; then
  144. for apt_source_filepath in "${apt_sources_dirpath}/"*.source; do
  145. apt_source_filepath=$(echo $apt_source_filepath | sed -re 's/(^.*[^/])\.[^./]*$/\1/')
  146. local new_apt_source="$(cat "${apt_source_filepath}.source")"
  147. local apt_source_gpg_filepath="${apt_source_filepath}.gpg"
  148. # extract filenames
  149. local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})"
  150. local apt_source_filename="$(basename ${apt_source_filepath}).list"
  151. display_alert "Adding APT Source ${new_apt_source}"
  152. if [[ "${new_apt_source}" == ppa* ]] ; then
  153. # ppa with software-common-properties
  154. run_on_sdcard "add-apt-repository -y -n \"${new_apt_source}\""
  155. # add list with apt-add
  156. # -y -> Assumes yes to all queries
  157. # -n -> Do not update package cache after adding
  158. if [[ -f "${apt_source_gpg_filepath}" ]]; then
  159. display_alert "Adding GPG Key ${apt_source_gpg_filepath}"
  160. cp "${apt_source_gpg_filepath}" "${SDCARD}/tmp/${apt_source_gpg_filename}"
  161. run_on_sdcard "apt-key add \"/tmp/${apt_source_gpg_filename}\""
  162. echo "APT Key returned : $?"
  163. fi
  164. else
  165. # installation without software-common-properties, sources.list + key.gpg
  166. echo "${new_apt_source}" > "${SDCARD}/etc/apt/sources.list.d/${apt_source_filename}"
  167. if [[ -f "${apt_source_gpg_filepath}" ]]; then
  168. display_alert "Adding GPG Key ${apt_source_gpg_filepath}"
  169. # local apt_source_gpg_filename="$(basename ${apt_source_gpg_filepath})"
  170. mkdir -p "${SDCARD}"/usr/share/keyrings/
  171. cp "${apt_source_gpg_filepath}" "${SDCARD}"/usr/share/keyrings/
  172. fi
  173. fi
  174. done
  175. fi
  176. done
  177. }
  178. add_desktop_package_sources() {
  179. # Myy : I see Snap and Flatpak coming up in the next releases
  180. # so... let's prepare for that
  181. add_apt_sources
  182. ls -l "${SDCARD}/usr/share/keyrings" >> "${DEST}"/${LOG_SUBPATH}/install.log
  183. ls -l "${SDCARD}/etc/apt/sources.list.d" >> "${DEST}"/${LOG_SUBPATH}/install.log
  184. cat "${SDCARD}/etc/apt/sources.list" >> "${DEST}"/${LOG_SUBPATH}/install.log
  185. }
  186. desktop_postinstall ()
  187. {
  188. # disable display manager for the first run
  189. #run_on_sdcard "systemctl --no-reload disable lightdm.service >/dev/null 2>&1"
  190. #run_on_sdcard "systemctl --no-reload disable gdm3.service >/dev/null 2>&1"
  191. # update packages index
  192. run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1"
  193. # install per board packages
  194. if [[ -n ${PACKAGE_LIST_DESKTOP_BOARD} ]]; then
  195. run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_BOARD"
  196. fi
  197. # install per family packages
  198. if [[ -n ${PACKAGE_LIST_DESKTOP_FAMILY} ]]; then
  199. run_on_sdcard "DEBIAN_FRONTEND=noninteractive apt-get -yqq --no-install-recommends install $PACKAGE_LIST_DESKTOP_FAMILY"
  200. fi
  201. # Compile Turbo Frame buffer for sunxi
  202. if [[ $LINUXFAMILY == sun8i && $BRANCH == legacy ]]; then
  203. sed 's/name="use_compositing" type="bool" value="true"/name="use_compositing" type="bool" value="false"/' -i "${SDCARD}"/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml
  204. # enable memory reservations
  205. echo "disp_mem_reserves=on" >> "${SDCARD}"/boot/orangepiEnv.txt
  206. echo "extraargs=cma=96M" >> "${SDCARD}"/boot/orangepiEnv.txt
  207. fi
  208. if [[ -d ${SDCARD}/etc/lightdm ]]; then
  209. mkdir -p ${SDCARD}/etc/lightdm/lightdm.conf.d
  210. cat <<-EOF > ${SDCARD}/etc/lightdm/lightdm.conf.d/22-orangepi-autologin.conf
  211. [Seat:*]
  212. autologin-user=$OPI_USERNAME
  213. autologin-user-timeout=0
  214. user-session=xfce
  215. EOF
  216. fi
  217. #mkdir -p /etc/gdm3
  218. #cat <<-EOF > /etc/gdm3/custom.conf
  219. #[daemon]
  220. #AutomaticLoginEnable = true
  221. #AutomaticLogin = $RealUserName
  222. #EOF
  223. }