install.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #!/usr/bin/env bash
  2. # An installation script for openbox-config.
  3. # Fix path whether run by repo root install.sh symlink or script file
  4. cd "$(dirname $0)" && cd scripts &>/dev/null
  5. source "inc/common.sh"
  6. show_message '' $MESSAGE_TYPES[warning]
  7. show_message " > WARNING! This script is under development and may not work as expected." $MESSAGE_TYPES[warning]
  8. show_message " > This can potentially break your system! Use at your own risk!" $MESSAGE_TYPES[warning]
  9. show_message " > To avoid risk please press Ctrl+C to quit out of it." $MESSAGE_TYPES[warning]
  10. show_message '' $MESSAGE_TYPES[warning]
  11. # Reset cache so that it can be updated, in case package list changed
  12. rm "${ENV_INFO[search_cache_installed]}" 2>/dev/null
  13. rm "${ENV_INFO[search_cache_available]}" 2>/dev/null
  14. # Gather missing programs/packages that need to be installed
  15. missing_programs=$(get_missing_programs)
  16. # We need Python Pip for dotdrop
  17. if [ "$(is_binary_installed "pip")" = "$FALSE" ] && [ "$(is_binary_installed "pip3")" = "$FALSE" ]; then
  18. if [ "$(is_package_available "python3-pip")" = "$TRUE" ]; then
  19. missing_programs+=' python3-pip'
  20. elif [ "$(is_package_available "python-pip")" = "$TRUE" ]; then
  21. missing_programs+=' python-pip'
  22. elif [ "$(is_package_available "pip" "py[0-9][0-9]-pip")" = "$TRUE" ]; then # FreeBSD
  23. missing_programs+=' '$(package_search "pip" | sed -ne 's|^\(py[0-9][0-9]-pip\)$|\1|p')
  24. elif [ "$(is_package_available "py3-pip")" = "$TRUE" ]; then # OpenBSD
  25. missing_programs+=' py3-pip'
  26. elif [ "${ENV_INFO[package_manager]}" = "apk" ]; then # Alpine
  27. show_message "Enabling community repo if not enabled already..." $MESSAGE_TYPES[action]
  28. $subin sed -i'.bak' 's|#\(.*[0-9]\/community\)|\1|' /etc/apk/repositories
  29. $subin apk update
  30. if [ "$(is_package_available "py3-pip")" = "$TRUE" ]; then
  31. missing_programs+=' py3-pip'
  32. else
  33. missing_programs+=' python3'
  34. fi
  35. else
  36. show_message "Error: Python Pip package name cannot be determined for your system. Please install manually." $MESSAGE_TYPES[error]; exit 34762
  37. fi
  38. fi
  39. # dotdrop needs 'file' package (in case it is not installed, such as in Alpine)
  40. if [ "$(is_binary_installed file)" = "$FALSE" ]; then
  41. missing_programs+=' file'
  42. fi
  43. # To fix mouse cursor not moving after login
  44. if [ "$(is_package_installed xf86-input-evdev)" = "$FALSE" ]; then
  45. missing_programs+=' xf86-input-evdev'
  46. fi
  47. # install xorg-server if not installed
  48. if [ "$(is_binary_installed "X")" = "$FALSE" ]; then
  49. if [ "${ENV_INFO[operating_system_name]}" = 'alpine' ]; then
  50. $subin setup-xorg-base
  51. else
  52. missing_programs+=' xorg-server'
  53. # Install xf86 drivers for intel built in graphics
  54. if [ ! -z "$(cat /proc/cpuinfo | grep -i 'vendor_id.*Intel')" ]; then
  55. missing_programs+=' xf86-video-intel'
  56. fi
  57. show_message 'Xorg was not found on the system and it will be installed, but depending on your system you may have to do other things to make it work.' $MESSAGE_TYPE[warning]
  58. fi
  59. fi
  60. # Install icon package if needed
  61. if [ -d "/usr/share/icons/Papirus/" ] || [ -d "/usr/local/share/icons/Papirus/" ] || [ -d "$HOME/.icons/Papirus/" ]; then
  62. show_message 'Papirus icon theme is installed... Skipping install.' $MESSAGE_TYPES[info]
  63. else
  64. if [ "$(is_package_available "papirus-icon-theme")" = "$TRUE" ]; then
  65. missing_programs+=' papirus-icon-theme'
  66. else
  67. show_message 'Error: Papirus icon theme package not found. Install papirus icon theme manually.' $MESSAGE_TYPES[error]
  68. fi
  69. fi
  70. # Install font package if there are no fonts installed by default (e.g. on Alpine.)
  71. # There has to be some font, otherwise it shows boxes in place of text.
  72. fc-list | grep .ttf &>/dev/null
  73. if [ "$?" -gt "0" ]; then
  74. missing_programs+=' ttf-dejavu'
  75. fi
  76. show_message "Found missing programs: $missing_programs" $MESSAGE_TYPES[info]
  77. show_message 'Will attempt to install them...' $MESSAGE_TYPES[action]
  78. # Install the missing packages
  79. install_packages "$missing_programs"
  80. # To help detect userspace installation
  81. export PATH="$PATH:$HOME/.local/bin/"
  82. # Install dotdrop
  83. if [ "$(is_binary_installed "dotdrop")" = "$FALSE" ]; then
  84. if [ "$(is_binary_installed "pip")" = "$TRUE" ]; then
  85. pip_bin=pip
  86. elif [ "$(is_binary_installed "pip3")" = "$TRUE" ]; then
  87. pip_bin=pip3
  88. elif [ -n "$(ls /usr/local/bin/pip3*)" ]; then # OpenBSD
  89. pip_bin=$(ls /usr/local/bin/pip3* | head -n 1)
  90. else
  91. show_message 'Error: Python Pip is not installed. Please install and continue. Exiting...' $MESSAGE_TYPES[fatal]; exit 56928
  92. fi
  93. $pip_bin install dotdrop
  94. fi
  95. # Make sure dotdrop binary is accessible
  96. if [ "$(is_binary_installed "dotdrop")" = "$FALSE" ]; then
  97. show_message 'Error: dotdrop cannot be executed. Unfortunately cannot continue. Exiting...' $MESSAGE_TYPES[fatal]; exit 28492
  98. elif [ -f "$HOME/.local/bin/dotdrop" ]; then
  99. dotdrop_bin="$HOME/.local/bin/dotdrop"
  100. else
  101. dotdrop_bin=dotdrop
  102. fi
  103. # Dotdrop's BSD bug workaround
  104. # There is a bug that even if there are ./custom.yaml and ~/.local/share/openbox-config/custom.yaml, they are not read and respected. Only the first file is read for variables. This happens only in BSD platforms (confirmed on freebsd and openbsd). This is a workaround to fix this. One of the conditions is that, there should be *all* keys present in the custom.yaml.
  105. if [ "${ENV_INFO[operating_system_name]}" = 'freebsd' ] || [ "${ENV_INFO[operating_system_name]}" = 'openbsd' ]; then
  106. # Setting the preferred file
  107. if [ -f "${HOME}/.local/share/openbox-config/custom.yaml" ]; then
  108. pref_custom_file="$(realpath ~/.local/share/openbox-config/custom.yaml)"
  109. elif [ -f "../custom.yaml" ]; then
  110. pref_custom_file="$(realpath ../custom.yaml)"
  111. fi
  112. if [ -n "$pref_custom_file" ]; then
  113. # Create a temp dir to contain everything
  114. tmpdir=`mktemp -d -t openbox-config.XXXXXX`
  115. mkdir -p "$tmpdir"
  116. show_message "BSD environment detected. Will be creating workaround files in ${tmpdir}. This might fail if not *all* variables are found in ${pref_custom_file} file." $MESSAGE_TYPES[info]
  117. # Save temp file paths
  118. tmpconfigfile="${tmpdir}/config.yaml"
  119. cp -f ../config.yaml "${tmpdir}/"
  120. sed -i'.bak' "s|- custom.default.yaml$|- ${pref_custom_file}|" "$tmpconfigfile"
  121. # Place in repo root to maintain so that dotdrop can find paths
  122. cp "$tmpconfigfile" ../temp_custom.yaml
  123. # Add options to use temp custom file instead of default config.yaml
  124. dotdrop_extra_params="-ctemp_custom.yaml"
  125. fi
  126. fi
  127. # To clean leftover temp files
  128. function clean_temp_custom_yaml {
  129. if [ -n "$tmpconfigfile" ]; then
  130. show_message 'Removing BSD workaround files...' $MESSAGE_TYPES[info]
  131. rm ../temp_custom.yaml
  132. fi
  133. }
  134. # Continue rest of the installation
  135. show_message "There are ${#CONFIG_VARIATIONS[@]} variations available:" $MESSAGE_TYPES[info]
  136. for i in "${!CONFIG_VARIATIONS[@]}"; do
  137. echo " ${i} ${CONFIG_VARIATIONS[$i]}"
  138. done
  139. show_message 'Please enter the corresponding number to choose [Default is 1]: ' $MESSAGE_TYPES[info] -n
  140. read variation_input
  141. if [[ ! "$variation_input" =~ ^[0-9]+$ ]] || ( [ "$variation_input" -lt "1" ] || [ "$variation_input" -gt "${#CONFIG_VARIATIONS[@]}" ] ); then
  142. variation_input=1
  143. fi
  144. variation="${CONFIG_VARIATIONS[${variation_input}]}"
  145. show_message "'$variation' variation is chosen." $MESSAGE_TYPES[info]
  146. show_message 'Now proceeding to install...' $MESSAGE_TYPES[action]
  147. show_message "Are you sure you want to install '$variation' variation of the config [y/N]? " $MESSAGE_TYPES[info] -n
  148. read sure_input
  149. if [ "$(get_user_confirm $sure_input NO)" = "YES" ]; then
  150. cd ..
  151. $dotdrop_bin install -p "$variation" -f "$dotdrop_extra_params"
  152. cd scripts
  153. clean_temp_custom_yaml
  154. show_message 'Changing icon theme...' $MESSAGE_TYPES[action]
  155. if [ "$variation" = 'default' ]; then
  156. $REPO_ROOT/scripts/changeicon.sh Papirus
  157. elif [ "$variation" = 'dark' ]; then
  158. $REPO_ROOT/scripts/changeicon.sh Papirus-Dark
  159. fi
  160. # Only restart if on an openbox session
  161. if [ "$(is_process_running openbox)" = "$TRUE" ]; then
  162. show_message 'Restarting openbox and tint2 to apply changes...' $MESSAGE_TYPES[action]
  163. openbox --reconfigure
  164. [ "$(is_process_running tint2)" = "$TRUE" ] && kill -15 "$(get_process_id tint2)"
  165. # So that file manager doesn't open on $PWD after restart
  166. cd "$HOME"
  167. tint2 &>/dev/null && disown &
  168. else
  169. # Check if ~/.xinitrc exists and already has exec openbox-session line (by discarding commented lines first).
  170. # If not, ask to create one which starts openbox session.
  171. if ! sed -e '/^[[:space:]]*#.*/d' "$HOME/.xinitrc" | grep 'exec.*openbox-session' &>/dev/null; then
  172. show_message "This will automatically create a file so that you can start openbox session when you run 'startx' from tty. Enter yes if you boot into a text based tty and you don't have a Display Manager (like gdm, lightdm, xdm etc.) setup on the system. Do you want to create a ~/.xinitrc automatically [y/N]? " $MESSAGE_TYPES[info] -n
  173. read sure_input
  174. if [ "$(get_user_confirm $sure_input NO)" = "YES" ]; then
  175. $REPO_ROOT/scripts/autoxinitrc.sh
  176. fi
  177. fi
  178. show_message 'Currently not running an Openbox session. Please logout or restart and login into an Openbox session.' $MESSAGE_TYPES[warning]
  179. fi
  180. else
  181. clean_temp_custom_yaml
  182. show_message 'Chosen to abort. Exiting...' $MESSAGE_TYPES[fatal]; exit 34918
  183. fi