#getretroarch.sh# 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #!/bin/bash
  2. # getretroarch.sh - Install RetroArch on GNU+Linux
  3. #
  4. # Written in 2017 by Caleb Herbert <csh@bluehome.net>
  5. #
  6. # To the extent possible under law, the author(s) have dedicated all
  7. # copyright and neighboring rights to this software to the public
  8. # domain worldwide. This software is distributed without any
  9. # warranty.
  10. #
  11. # You should have received a copy of the CC0 Public Domain Dedication
  12. # along with this software. If not, see
  13. # <http://creativecommons.org/publicdomain/zero/1.0/>.
  14. # # # # # # # # # # # # # # # # # # # # # # # # #
  15. # WARNING: #
  16. # This script is shit and contains Bashisms. #
  17. # # # # # # # # # # # # # # # # # # # # # # # # #
  18. # # # # # # # # # # # # # # # # # # # # # # # # #
  19. # RUNNING THIS SCRIPT #
  20. # #
  21. # To run this script on a GNU+Linux system, #
  22. # make it executable and run it from the #
  23. # terminal. #
  24. # #
  25. # $ chmod +x getretroarch.sh #
  26. # $ ./getretroarch.sh #
  27. # #
  28. # You may not need to do this if you got it #
  29. # in the recommended .tar.gz file. #
  30. # #
  31. # # # # # # # # # # # # # # # # # # # # # # # # #
  32. PROGRAM_ID="Get RetroArch"
  33. SYSTEM=x86_64-linux
  34. ME=$(whoami)
  35. GNU_URI="https://www.gnu.org/software/guix/manual/html_node/Binary-Installation.html"
  36. PACKAGE="retroarch"
  37. win() {
  38. zenity --"$1" \
  39. --title="$PROGRAM_ID" \
  40. --text="$2"
  41. }
  42. uhoh() {
  43. spd-say "Uh-oh"
  44. }
  45. # Get Guix
  46. pt1() {
  47. # Get Guix
  48. wget ftp://alpha.gnu.org/gnu/guix/guix-binary-0.13.0.$SYSTEM.tar.xz
  49. wget ftp://alpha.gnu.org/gnu/guix/guix-binary-0.13.0.$SYSTEM.tar.xz.sig
  50. # Get developer ID
  51. gpg --keyserver pgp.mit.edu --recv-keys 3CE464558A84FDC69DB40CFB090B11993D9AEBB5
  52. # Authenticate Guix
  53. gpg --verify guix-binary-0.13.0.$SYSTEM.tar.xz.sig
  54. }
  55. # Create storage for packages
  56. pt2() {
  57. gksudo bash <<EOF
  58. tar --warning=no-timestamp -xf \
  59. /guix-binary-0.13.0.$SYSTEM.tar.xz
  60. mv var/guix /var/ && mv gnu /
  61. EOF
  62. }
  63. pt3() {
  64. gksudo bash <<EOF
  65. ln -sf /var/guix/profiles/per-user/root/guix-profile \
  66. ~root/.guix-profile
  67. GUIX_PROFILE=$HOME/.guix-profile \
  68. source $GUIX_PROFILE/etc/profile
  69. EOF
  70. }
  71. # Create group and user accounts for build users
  72. pt4() {
  73. gksudo bash <<EOF
  74. groupadd --system guixbuild
  75. for i in `seq -w 1 10`;
  76. do
  77. useradd -g guixbuild -G guixbuild \
  78. -d /var/empty -s `which nologin` \
  79. -c "Guix build user $i" --system \
  80. guixbuilder$i;
  81. done
  82. EOF
  83. }
  84. # # # # # # # # # # # # # # # # # # # # # # # # #
  85. # WAIT! #
  86. # Um... Which init system are you running? #
  87. # # # # # # # # # # # # # # # # # # # # # # # # #
  88. # Run Guix daemon
  89. pt5() {
  90. gksudo bash <<EOF
  91. # BASHISM!!! # if [ "$(/sbin/init --version)" =~ upstart ]
  92. # if [ "$(/sbin/init --version)" =~ upstart ]
  93. # Instead, use:
  94. if $(/sbin/init --version | grep upstart > /dev/null)
  95. then
  96. your_init_system="upstart"
  97. elif $(systemctl | grep '-\.mount' > /dev/null)
  98. your_init_system="systemd"
  99. elif
  100. your_init_system="sysv"
  101. else
  102. your_init_system="idk"
  103. # Not used; IDK how to end 'if'.
  104. fi
  105. # Adapted from https://unix.stackexchange.com/a/164092
  106. if [ $your_init_system = "systemd" ]
  107. then
  108. cp ~root/.guix-profile/lib/systemd/system/guix-daemon.service \
  109. /etc/systemd/system/
  110. systemctl start guix-daemon && systemctl enable guix-daemon
  111. elif [ $your_init_system = "upstart" ]
  112. then
  113. initctl reload-configuration
  114. cp ~root/.guix-profile/lib/upstart/system/guix-daemon.conf \
  115. /etc/init/
  116. start guix-daemon
  117. else
  118. ~root/.guix-profile/bin/guix-daemon \
  119. --build-users-group=guixbuild
  120. fi
  121. EOF
  122. }
  123. pt6() {
  124. gksudo bash <<EOF
  125. # Provide "guix" command
  126. mkdir -p /usr/local/bin
  127. cd /usr/local/bin
  128. ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
  129. # Provide Guix Info manual
  130. mkdir -p /usr/local/share/info
  131. cd /usr/local/share/info
  132. for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
  133. do ln -s $i ; done
  134. EOF
  135. }
  136. pt7() {
  137. gksudo bash <<EOF
  138. # Authorize binary packages/"substitutes"
  139. guix archive --authorize < ~root/.guix-profile/share/guix/hydra.gnu.org.pub
  140. EOF
  141. }
  142. # All commands taken from
  143. # https://www.gnu.org/software/guix/manual/html_node/Binary-Installation.html
  144. pt8() {
  145. # Install RetroArch!
  146. guix package --install $PACKAGE
  147. }
  148. # The actions
  149. main() {
  150. pt1 || win warning "Part 1"
  151. pt2 || win warning "Failed to create GNU store."
  152. pt3 || win warning "Failed step 3 in $GNU_URI"
  153. pt4 || win warning "Failed to create build users."
  154. pt5 || win warning "Failed to start Guix daemon."
  155. pt6 || win warning "Failed to provide guix and info manual."
  156. pt7 || win warning "Failed to authorize binary package substitutes."
  157. pt8 || win warning "Failed to install $PACKAGE."
  158. }
  159. # The GUI
  160. cd /tmp
  161. if win question "Would you like me to install RetroArch for you?"
  162. then
  163. win warning \
  164. "Don't shut off your computer until you see another dialog box from me, OK? Don't worry, this shouldn't take more than half an hour."
  165. main || win error "Uh-oh, I'm not working right."
  166. else
  167. win notification "Done!"
  168. fi
  169. exit