fant0men

Game installer script

Mar 21st, 2020
282
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # This script will serve as an installer for *.tar.xz files, containing
  3. # games, in the same directory. The script will also copy a start /
  4. # uninstall script to $HOME/bin, and modify ~/.bashrc (if needed) to
  5. # include that directory in the PATH.
  6.  
  7. script=$(readlink -f "$0")
  8. cwd=$(dirname "$script")
  9. start_script_of='0'
  10.  
  11. width='0'
  12. height='0'
  13. width_out='0'
  14. height_out='0'
  15.  
  16. userid_script=$(whoami)
  17. distro='0'
  18. userid_install='0'
  19. home_dir='0'
  20. bin_dir='0'
  21. install_dir='0'
  22. deb_dir='0'
  23. bashrc='0'
  24. bashrc_tmp='0'
  25.  
  26. if [[ $userid_script != 'root' ]]; then
  27.     cat <<USER_ID
  28.  
  29. You need root priviliges to run this installer!
  30. Run the script like this: sudo ${script}
  31.  
  32. USER_ID
  33.  
  34.     exit
  35. fi
  36.  
  37. get_distro () {
  38.     cat <<GET_DISTRO
  39.  
  40. Are you running a DEB-based or RPM-based Linux distribution?
  41. If neither, just choose 'Abort' and create the symlinks yourself manually.
  42.  
  43. GET_DISTRO
  44.  
  45.     until [[ $distro == 'deb' || $distro == 'rpm' ]]; do
  46.         clear
  47.  
  48.         cat <<CHOOSE_DISTRO
  49.  
  50. Choose your distribution type:
  51.  
  52. 1) DEB-based (Ubuntu, Mint, Debian etc.)
  53. 2) RPM-based (Fedora, CentOS, Red Hat etc.)
  54. 3) Abort
  55.  
  56. CHOOSE_DISTRO
  57.  
  58.         printf '>'
  59.         read distro_type
  60.  
  61.         case "$distro_type" in
  62.             1)
  63.                 distro='deb'
  64.             ;;
  65.             2)
  66.                 distro='rpm'
  67.             ;;
  68.             3)
  69.                 exit
  70.             ;;
  71.         esac
  72.     done
  73. }
  74.  
  75. get_userid_install () {
  76.     yesno='0'
  77.     regex_home_dir='^[0-9]+$'
  78.  
  79.     mapfile -t home_dir_list < <(find /home -type d -maxdepth 1 -iname "*" | tail -n +2)
  80.  
  81.     until [[ $yesno == 'yes' ]]; do
  82.         clear
  83.  
  84.         n='0'
  85.  
  86.         echo -e "\nChoose your home directory:\n"
  87.  
  88.         for (( i = 0; i < ${#home_dir_list[@]}; i++ )); do
  89.             n=$(( n + 1 ))
  90.  
  91.             echo "${n}) ${home_dir_list[${i}]}"
  92.  
  93.         done
  94.  
  95.         printf '\n>'
  96.         read home_dir_n
  97.  
  98.         if [[ $home_dir_n =~ $regex_home_dir ]]; then
  99.             if [[ $home_dir_n -gt 0 ]]; then
  100.                 home_dir_n=$(( home_dir_n - 1 ))
  101.             fi
  102.  
  103.             if [[ -d ${home_dir_list[${home_dir_n}]} ]]; then
  104.                 home_dir="${home_dir_list[${home_dir_n}]}"
  105.                 userid_install=$(basename "$home_dir")
  106.             else
  107.                 continue
  108.             fi
  109.         fi
  110.  
  111.         if [[ $home_dir != '0' ]]; then
  112.             cat <<YES_NO
  113.  
  114. Games will be installed in:
  115. ${home_dir}
  116.  
  117. Is this correct? (yes/no)
  118.  
  119. YES_NO
  120.  
  121.             printf '>'
  122.             read yesno
  123.         fi
  124.     done
  125.  
  126.     bin_dir="${home_dir}/bin"
  127.     install_dir="${home_dir}/id_games"
  128.     deb_dir="${install_dir}/debs"
  129.     start_script_of="${bin_dir}/id_games.sh"
  130.     bashrc="${home_dir}/.bashrc"
  131.     bashrc_tmp="${bashrc}-${RANDOM}"
  132. }
  133.  
  134. get_res () {
  135.     yesno='0'
  136.     regex_res='^[0-9]+x[0-9]+$'
  137.  
  138.     until [[ $yesno == 'yes' ]]; do
  139.         res_tmp='0'
  140.  
  141.         until [[ $res_tmp =~ $regex_res ]]; do
  142.             clear
  143.  
  144.             cat <<GET_RES
  145.  
  146. What's your screen resolution? (e.g. 1920x1080)
  147.  
  148. GET_RES
  149.  
  150.             printf '>'
  151.             read res_tmp
  152.         done
  153.  
  154.         if [[ $res_tmp =~ $regex_res ]]; then
  155.             cat <<YES_NO
  156.  
  157. You chose this resolution:
  158. ${res_tmp}
  159.  
  160. Is this correct? (yes/no)
  161.  
  162. YES_NO
  163.  
  164.             printf '>'
  165.             read yesno
  166.         fi
  167.     done
  168.  
  169.     mapfile -d'x' -t res_array <<<"$res_tmp"
  170.     width="${res_array[0]}"
  171.     height="${res_array[1]}"
  172. }
  173.  
  174. wolf4sdl_res () {
  175.     switch='0'
  176.     n='0'
  177.  
  178.     width_base='320'
  179.     height_base[0]='200'
  180.     height_base[1]='240'
  181.  
  182.     set_tmp_var () {
  183.         width_tmp=$(( width_base * n ))
  184.         height_tmp[0]=$(( ${height_base[0]} * n ))
  185.         height_tmp[1]=$(( ${height_base[1]} * n ))
  186.     }
  187.  
  188.     while [[ $switch -eq 0 ]]; do
  189.         n=$(( n + 1 ))
  190.         set_tmp_var
  191.  
  192.         if [[ $width_tmp -ge $width ]]; then
  193.             switch='1'
  194.         elif [[ ${height_tmp[0]} -ge $height ]]; then
  195.             switch='1'
  196.         fi
  197.     done
  198.  
  199.     if [[ $width_tmp -gt $width ]]; then
  200.         n=$(( n - 1 ))
  201.         set_tmp_var
  202.     elif [[ ${height_tmp[0]} -gt $height ]]; then
  203.         n=$(( n - 1 ))
  204.         set_tmp_var
  205.     fi
  206.  
  207.     width_out="$width_tmp"
  208.  
  209.     if [[ ${height_tmp[1]} -le $height ]]; then
  210.         height_out="${height_tmp[1]}"
  211.     else
  212.         height_out="${height_tmp[0]}"
  213.     fi
  214. }
  215.  
  216. rott_res () {
  217.     declare -A res_tmp
  218.  
  219.     res_tmp[320]='200'
  220.     res_tmp[640]='480'
  221.     res_tmp[800]='600'
  222.     res_list=(320 640 800)
  223.  
  224.     for width_tmp in ${res_list[@]}; do
  225.         if [[ $width_tmp -le $width ]]; then
  226.             width_out="$width_tmp"
  227.             height_out="${res_tmp[${width_tmp}]}"
  228.         fi
  229.     done
  230. }
  231.  
  232. change_res () {
  233.     declare -a config
  234.     prboom_plus='0'
  235.     wolf3d='0'
  236.     sod='0'
  237.     rott='0'
  238.  
  239.     read_config () {
  240.         mapfile -t config <"$if"
  241.     }
  242.  
  243.     change_config () {
  244.         for (( i = 0; i < ${#config[@]}; i++ )); do
  245.             if [[ ${config[${i}]} =~ $regex ]]; then
  246.                 if [[ $prboom_plus -eq 1 ]]; then
  247. echo prboom_plus
  248.                     line_edit=$(sed -E "s/\"[0-9]+x[0-9]+\"/\"${width}x${height}\"/" <<<"${config[${i}]}")
  249.                     prboom_plus='0'
  250.                 fi
  251.  
  252.                 if [[ $wolf3d -eq 1 ]]; then
  253. echo wolf3d
  254.                     line_edit=$(sed -E "s/--res [0-9]+ [0-9]+/--res ${width_out}x${height_out}/" <<<"${config[${i}]}")
  255.                     wolf3d='0'
  256.                 fi
  257.  
  258.                 if [[ $sod -eq 1 ]]; then
  259. echo sod
  260.                     line_edit=$(sed -E "s/--res [0-9]+ [0-9]+/--res ${width_out}x${height_out}/" <<<"${config[${i}]}")
  261.                     sod='0'
  262.                 fi
  263.  
  264.                 if [[ $rott -eq 1 ]]; then
  265. echo rott
  266.                     line_edit=$(sed -E "s/resolution [0-9]+x[0-9]+/resolution ${width_out}x${height_out}/" <<<"${config[${i}]}")
  267.                     rott='0'
  268.                 fi
  269.  
  270.                 config[${i}]="$line_edit"
  271.             fi
  272.         done
  273.     }
  274.  
  275.     write_config () {
  276.         touch "$of" || exit
  277.  
  278.         for (( i = 0; i < ${#config[@]}; i++ )); do
  279.             echo "${config[${i}]}" >> "$of" || exit
  280.         done
  281.  
  282.         mv "$of" "$if" || exit
  283.     }
  284.  
  285.     # Changing the config file for Quake...
  286.  
  287.     if="${install_dir}/quake/ID1/config.cfg"
  288.     of="${if}-${RANDOM}"
  289.     regex='"vid_width" "[0-9]+"'
  290.     line_edit="\"vid_width\" \"${width}\""
  291.  
  292.     read_config
  293.     change_config
  294.  
  295.     regex='"vid_height" "[0-9]+"'
  296.     line_edit="\"vid_height\" \"${height}\""
  297.  
  298.     change_config
  299.     write_config
  300.  
  301.     of="${install_dir}/quake/HIPNOTIC/config.cfg"
  302.     cp "$if" "$of" || exit
  303.  
  304.     of="${install_dir}/quake/ROGUE/config.cfg"
  305.     cp "$if" "$of" || exit
  306.  
  307.     # Changing the config file for Quake 2...
  308.  
  309.     if="${install_dir}/quake2/baseq2/config.cfg"
  310.     of="${if}-${RANDOM}"
  311.     regex='set gl_mode ".*"'
  312.     line_edit='set gl_mode "-1"'
  313.  
  314.     read_config
  315.     change_config
  316.  
  317.     regex='set gl_customwidth "[0-9]+"'
  318.     line_edit="set gl_customwidth \"${width}\""
  319.  
  320.     change_config
  321.  
  322.     regex='set gl_customheight "[0-9]+"'
  323.     line_edit="set gl_customheight \"${height}\""
  324.  
  325.     change_config
  326.     write_config
  327.  
  328.     of="${install_dir}/quake2/xatrix/config.cfg"
  329.     cp "$if" "$of" || exit
  330.  
  331.     of="${install_dir}/quake2/rogue/config.cfg"
  332.     cp "$if" "$of" || exit
  333.  
  334.     # Changing the config file for Quake 3...
  335.  
  336.     if="${install_dir}/quake3/baseq3/q3config.cfg"
  337.     of="${if}-${RANDOM}"
  338.     regex='seta r_customwidth "[0-9]+"'
  339.     line_edit="seta r_customwidth \"${width}\""
  340.  
  341.     read_config
  342.     change_config
  343.  
  344.     regex='seta r_customheight "[0-9]+"'
  345.     line_edit="seta r_customheight \"${height}\""
  346.  
  347.     change_config
  348.     write_config
  349.  
  350.     # Changing the config file for PrBoom-plus...
  351.  
  352.     if="${install_dir}/prboom-plus/prboom-plus.cfg"
  353.     of="${if}-${RANDOM}"
  354.     regex='screen_resolution[[:blank:]]+"[0-9]+x[0-9]+"'
  355.     prboom_plus='1'
  356.  
  357.     read_config
  358.     change_config
  359.     write_config
  360.  
  361.     # Changing the config file for Doom 64 EX...
  362.  
  363.     if="${install_dir}/doom64ex/local/share/doom64ex/config.cfg"
  364.     of="${if}-${RANDOM}"
  365.     regex='seta "v_Width" "[0-9]+"'
  366.     line_edit="seta \"v_Width\" \"${width}\""
  367.  
  368.     read_config
  369.     change_config
  370.  
  371.     regex='seta "v_Height" "[0-9]+"'
  372.     line_edit="seta \"v_Height\" \"${height}\""
  373.  
  374.     change_config
  375.     write_config
  376.  
  377.     # Changing the run commands for Wolf3D, SoD, and RotT...
  378.  
  379.     wolf4sdl_res
  380.  
  381.     if="${bin_dir}/id_games.sh"
  382.     of="${if}-${RANDOM}"
  383.  
  384.     wolf3d='1'
  385.  
  386.     if [[ $distro == 'rpm' ]]; then
  387.         regex='[[:blank:]]*wolf4sdl-registered-id --res [0-9]+ [0-9]+.*'
  388.     elif [[ $distro == 'deb' ]]; then
  389.         regex='[[:blank:]]*wolf4sdl --res [0-9]+ [0-9]+.*'
  390.     fi
  391.  
  392.     read_config
  393.     change_config
  394.  
  395.     sod='1'
  396.  
  397.     if [[ $distro == 'rpm' ]]; then
  398.         regex='[[:blank:]]*wolf4sdl-spear --res [0-9]+ [0-9]+ --goodtimes.*'
  399.     elif [[ $distro == 'deb' ]]; then
  400.         regex='[[:blank:]]*wolf4sdl-sod --res [0-9]+ [0-9]+ --goodtimes.*'
  401.     fi
  402.  
  403.     change_config
  404.  
  405.     rott_res
  406.  
  407.     rott='1'
  408.  
  409.     if [[ $distro == 'rpm' ]]; then
  410.         regex='[[:blank:]]*rott-registered fullscreen resolution [0-9]+x[0-9]+.*'
  411.     elif [[ $distro == 'deb' ]]; then
  412.         regex='[[:blank:]]*rott-commercial fullscreen resolution [0-9]+x[0-9]+.*'
  413.     fi
  414.  
  415.     change_config
  416.     write_config
  417.  
  418.     chmod +x "$if" || exit
  419. }
  420.  
  421. install_games () {
  422.  
  423.     dir_list1=("$install_dir" "$bin_dir" "${home_dir}/.rott" "${home_dir}/.local/share" "${home_dir}/.darkplaces" "${home_dir}/.yq2" "${home_dir}/.q3a")
  424.     dir_list2=("$install_dir" "${home_dir}/.rott" "${home_dir}/.local/share/doom64ex" "${home_dir}/.darkplaces" "${home_dir}/.yq2" "${home_dir}/.q3a")
  425.     uninstall_list_f="${install_dir}/id_games_uninstall_list.txt"
  426.     uninstall_script_if="${cwd}/uninstall_id_games.sh"
  427.     uninstall_script_of="${bin_dir}/uninstall_id_games.sh"
  428.  
  429.     uninstall_list[0]='# THIS FILE IS FOR THE UNINSTALLER.'
  430.     uninstall_list[1]='# DO NOT EDIT OR REMOVE THIS FILE.'
  431.     uninstall_list[2]="$install_dir"
  432.     uninstall_list[3]="$start_script_of"
  433.  
  434.     extract_archives () {
  435.         cd "$install_dir" || exit
  436.  
  437.         echo -e "\nExtracting games!\n"
  438.  
  439.         for archive in "${cwd}"/*.tar.xz; do
  440.             echo "* ${archive}"
  441.             tar -xJf "$archive" || exit
  442.         done
  443.     }
  444.  
  445.     if [[ $distro == 'deb' ]]; then
  446.         start_script_if="${cwd}/id_games_deb.sh"
  447.         dir_list3=('/usr/share/games/wolf3d' '/usr/local/share/games/doom64ex')
  448.  
  449.         mkdir -p "${dir_list1[@]}" "${dir_list3[@]}" "$deb_dir" || exit
  450.  
  451. #       extract_archives
  452.  
  453.         echo -e "\nCreating symlinks!\n"
  454.  
  455.         echo "* Wolfenstein 3D"
  456.         mapfile -t wolf3d_files < <(ls -1 "${install_dir}/wolf3d")
  457.         for (( i = 0; i < ${#wolf3d_files[@]}; i++ )); do
  458.             f="${wolf3d_files[${i}]}"
  459.             ln -s "${install_dir}/wolf3d/${f}" "/usr/share/games/wolf3d/${f}" || exit
  460.         done
  461.  
  462.         echo "* Spear of Destiny"
  463.         mapfile -t spear_files < <(ls -1 "${install_dir}/spear")
  464.         for (( i = 0; i < ${#spear_files[@]}; i++ )); do
  465.             f="${spear_files[${i}]}"
  466.             ln -s "${install_dir}/spear/${f}" "/usr/share/games/wolf3d/${f}" || exit
  467.         done
  468.  
  469.         echo "* Rise of the Triad"
  470.         ln -s "${install_dir}/rott" '/usr/share/games/rott' || exit
  471.  
  472.         echo "* PrBoom-plus"
  473.         ln -s "${install_dir}/prboom-plus" "${home_dir}/.prboom-plus" || exit
  474.  
  475.         echo "* Doom 64 EX"
  476.         ln -s "${install_dir}/doom64ex/local/share/doom64ex" "${home_dir}/.local/share/doom64ex" || exit
  477.         ln -s "${install_dir}/doom64ex/doom64ex" '/usr/local/bin/doom64ex' || exit
  478.         ln -s "${install_dir}/doom64ex/doom64ex.pk3" '/usr/local/share/games/doom64ex/doom64ex.pk3' || exit
  479.  
  480.         echo "* Quake"
  481.         ln -s "${install_dir}/quake/ID1" "${home_dir}/.darkplaces/id1" || exit
  482.  
  483.         echo "* Quake: Scourge of Armagon"
  484.         ln -s "${install_dir}/quake/HIPNOTIC" "${home_dir}/.darkplaces/hipnotic" || exit
  485.  
  486.         echo "* Quake: Dissolution of Eternity"
  487.         ln -s "${install_dir}/quake/ROGUE" "${home_dir}/.darkplaces/rogue" || exit
  488.  
  489.         uninstall_list[4]='/usr/share/games/wolf3d'
  490.         uninstall_list[5]='/usr/share/games/rott'
  491.         uninstall_list[6]="${home_dir}/.prboom-plus"
  492.         uninstall_list[7]="${home_dir}/.local/share/doom64ex"
  493.         uninstall_list[8]='/usr/local/bin/doom64ex'
  494.         uninstall_list[9]='/usr/local/share/games/doom64ex/doom64ex.pk3'
  495.         uninstall_list[10]="${home_dir}/.darkplaces/id1"
  496.         uninstall_list[11]="${home_dir}/.darkplaces/hipnotic"
  497.         uninstall_list[12]="${home_dir}/.darkplaces/rogue"
  498.         uninstall_list[13]="${home_dir}/.yq2/baseq2"
  499.         uninstall_list[14]="${home_dir}/.q3a/baseq3"
  500.  
  501.     elif [[ $distro == 'rpm' ]]; then
  502.         start_script_if="${cwd}/id_games_rpm.sh"
  503.         dir_list3=('/usr/share/wolf3d' '/usr/share/spear' '/usr/local/share/games/doom64ex')
  504.  
  505.         mkdir -p "${dir_list1[@]}" "${dir_list3[@]}" || exit
  506.  
  507.         extract_archives
  508.  
  509.         echo -e "\nCreating symlinks!\n"
  510.  
  511.         echo "* Wolfenstein 3D"
  512.         ln -s "${install_dir}/wolf3d" '/usr/share/wolf3d/registered-id' || exit
  513.  
  514.         echo "* Spear of Destiny"
  515.         ln -s "${install_dir}/spear" '/usr/share/spear/full' || exit
  516.  
  517.         echo "* Rise of the Triad"
  518.         ln -s "${install_dir}/rott" "${home_dir}/.rott/registered" || exit
  519.  
  520.         echo "* PrBoom-plus"
  521.         ln -s "${install_dir}/prboom-plus" "${home_dir}/.prboom-plus" || exit
  522.  
  523.         echo "* Doom 64 EX"
  524.         ln -s "${install_dir}/doom64ex/local/share/doom64ex" "${home_dir}/.local/share/doom64ex" || exit
  525.         ln -s "${install_dir}/doom64ex/doom64ex" '/usr/local/bin/doom64ex' || exit
  526.         ln -s "${install_dir}/doom64ex/doom64ex.pk3" '/usr/local/share/games/doom64ex/doom64ex.pk3' || exit
  527.  
  528.         echo "* Quake"
  529.         ln -s "${install_dir}/quake/ID1" "${home_dir}/.darkplaces/id1" || exit
  530.  
  531.         echo "* Quake: Scourge of Armagon"
  532.         ln -s "${install_dir}/quake/HIPNOTIC" "${home_dir}/.darkplaces/hipnotic" || exit
  533.  
  534.         echo "* Quake: Dissolution of Eternity"
  535.         ln -s "${install_dir}/quake/ROGUE" "${home_dir}/.darkplaces/rogue" || exit
  536.  
  537.         echo "* Quake 2"
  538.         ln -s "${install_dir}/quake2/baseq2" "${home_dir}/.yq2/baseq2" || exit
  539.  
  540.         echo "* Quake 3"
  541.         ln -s "${install_dir}/quake3/baseq3" "${home_dir}/.q3a/baseq3" || exit
  542.  
  543.         uninstall_list[4]='/usr/share/wolf3d/registered-id'
  544.         uninstall_list[5]='/usr/share/spear/full'
  545.         uninstall_list[6]="${home_dir}/.rott/registered"
  546.         uninstall_list[7]="${home_dir}/.prboom-plus"
  547.         uninstall_list[8]="${home_dir}/.local/share/doom64ex"
  548.         uninstall_list[9]='/usr/local/bin/doom64ex'
  549.         uninstall_list[10]='/usr/local/share/games/doom64ex/doom64ex.pk3'
  550.         uninstall_list[11]="${home_dir}/.darkplaces/id1"
  551.         uninstall_list[12]="${home_dir}/.darkplaces/hipnotic"
  552.         uninstall_list[13]="${home_dir}/.darkplaces/rogue"
  553.         uninstall_list[14]="${home_dir}/.yq2/baseq2"
  554.         uninstall_list[15]="${home_dir}/.q3a/baseq3"
  555.     fi
  556.  
  557.     if [[ -f $uninstall_list_f ]]; then
  558.         rm -f "$uninstall_list_f"
  559.     fi
  560.  
  561.     # Create the uninstall list file, and copy the uninstaller script to $HOME/bin.
  562.     touch "$uninstall_list_f" || exit
  563.  
  564.     for (( i = 0; i < ${#uninstall_list[@]}; i++ )); do
  565.         echo "${uninstall_list[${i}]}" >> "$uninstall_list_f" || exit
  566.     done
  567.  
  568.     cp "$uninstall_script_if" "$uninstall_script_of" || exit
  569.  
  570.     # Copy the start script to $HOME/bin.
  571.     cp "$start_script_if" "$start_script_of" || exit
  572.  
  573.     # Change the resolution in the config files.
  574.     change_res
  575.  
  576.     # Changing owner of installed files to intended user.
  577.     chown -R "$userid_install" "${dir_list2[@]}" || exit
  578.     chown "$userid_install" "$bin_dir" "$start_script_of" "$uninstall_list_f"
  579. }
  580.  
  581. install_packages () {
  582.     if [[ $distro == 'deb' ]]; then
  583.         apt update || exit
  584.         apt install wolf4sdl rott prboom-plus darkplaces quake2 quake3 || exit
  585.  
  586.         gdp_bin='/usr/games/game-data-packager'
  587.  
  588.         eval "$gdp_bin" -d "$deb_dir" -i quake2 "${install_dir}/quake2" || exit
  589.         eval "$gdp_bin" -d "$deb_dir" -i quake3 "${install_dir}/quake3" || exit
  590.  
  591.         chown -R "$userid_install" "$deb_dir" || exit
  592.  
  593.         mapfile -t deb_list < <(find "$deb_dir" -type f -iname "*.deb")
  594.  
  595.         for (( i = 0; i < ${#deb_list[@]}; i++ )); do
  596.             deb="${deb_list[${i}]}"
  597.  
  598.             if [[ -f "$deb" ]]; then
  599.                 apt install "$deb" || exit
  600.             fi
  601.         done
  602.     elif [[ $distro == 'rpm' ]]; then
  603.         yum install wolf4sdl-registered-id wolf4sdl-spear rott-registered prboom-plus darkplaces quake2 quake3 || exit
  604.     fi
  605. }
  606.  
  607. fix_bashrc () {
  608.     new_bashrc () {
  609.         touch "$bashrc_tmp" || exit
  610.  
  611.         for (( j = 0; j < ${#bashrc_lines[@]}; j++ )); do
  612.             echo "${bashrc_lines[${j}]}" >> "$bashrc_tmp" || exit
  613.         done
  614.  
  615.         mv "$bashrc_tmp" "$bashrc" || exit
  616.  
  617.         chown "$userid_install" "$bashrc" || exit
  618.  
  619.         source "$bashrc" || exit
  620.     }
  621.  
  622.     # Edit ~/.bashrc to include $HOME/bin, if it's not already there.
  623.     if [[ ! -f $bashrc ]]; then
  624.         touch "$bashrc" || exit
  625.     fi
  626.  
  627.     mapfile -t bashrc_lines <"$bashrc"
  628.     switch='0'
  629.     regex='^PATH='
  630.     regex2='\$\{{0,1}HOME\}{0,1}/bin'
  631.  
  632.     if [[ $bashrc_lines ]]; then
  633.         for (( i = 0; i < ${#bashrc_lines[@]}; i++ )); do
  634.             line="${bashrc_lines[${i}]}"
  635.    
  636.             if [[ $line =~ $regex ]]; then
  637.                 path_var=$(sed 's/^PATH=//' <<<"$line")
  638.  
  639.                 if [[ $path_var =~ $regex2 || $path_var =~ $bin_dir ]]; then
  640.                     switch='1'
  641.  
  642.                     break
  643.                 else
  644.                     path_var="\${HOME}/bin:${path_var}"
  645.                     bashrc_lines[${i}]="PATH=${path_var}"
  646.                     new_bashrc
  647.  
  648.                     switch='1'
  649.  
  650.                     break
  651.                 fi
  652.             fi
  653.         done
  654.     fi
  655.  
  656.     if [[ $switch -eq 0 ]]; then
  657.         bashrc_lines+=("" "PATH=\${HOME}/bin:${PATH}")
  658.  
  659.         new_bashrc
  660.     fi
  661. }
  662.  
  663. get_distro
  664. get_userid_install
  665. get_res
  666. install_games
  667. install_packages
  668. read
  669. fix_bashrc
  670.  
  671. echo -e "\nYou can now start the games by typing: id_games.sh\n"
RAW Paste Data