freedombone-utils-guile 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Recent version of guile
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. GUILE_VERSION='2.2.0'
  31. GUILE_HASH='c707b9cf6f97ecca3a4e3e704e62b83f95f1aec28ed1535f5d0a1d36af07a015'
  32. EIGHTSYNC_REPO="git://git.savannah.gnu.org/8sync.git"
  33. EIGHTSYNC_COMMIT='8cbb7f22227c0afdd3b0bd758ebec0efba2fa1e1'
  34. GUIX_VERSION='0.13.0'
  35. GUIX_DOWNLOAD_URL='ftp://alpha.gnu.org/gnu/guix'
  36. function install_8sync {
  37. apt-get -qy install flex libunistring-dev libgc-dev autoconf texinfo
  38. if [ ! -d $INSTALL_DIR ]; then
  39. mkdir $INSTALL_DIR
  40. fi
  41. cd $INSTALL_DIR
  42. git_clone $EIGHTSYNC_REPO $INSTALL_DIR/eightsync
  43. cd $INSTALL_DIR/eightsync
  44. git checkout ${EIGHTSYNC_COMMIT} -b ${EIGHTSYNC_COMMIT}
  45. export GUILE_BASE_PATH=/opt/guile-${GUILE_VERSION}
  46. export GUILE_CFLAGS="-I${GUILE_BASE_PATH}/include"
  47. export GUILE_LIBS="-L${GUILE_BASE_PATH}/lib -lguile -lqthreads -ldl -ltermcap -lsocket -lnsl -lm"
  48. ./bootstrap.sh
  49. configure
  50. make
  51. make install
  52. }
  53. function install_guile {
  54. # Currently this only works for x86_64
  55. read_config_param ARCHITECTURE
  56. if [[ ${ARCHITECTURE} != "x86_64" ]]; then
  57. return
  58. fi
  59. GUILE_ARCH='x86_64'
  60. apt-get -qy install flex libunistring-dev libgc-dev autoconf texinfo lzip wget
  61. if [ ! -d $INSTALL_DIR ]; then
  62. mkdir $INSTALL_DIR
  63. fi
  64. cd $INSTALL_DIR
  65. if [ ! -f guile-${GUILE_VERSION}-pack-${GUILE_ARCH}-linux-gnu.tar.lz ]; then
  66. wget https://ftp.gnu.org/gnu/guile/guile-${GUILE_VERSION}-pack-${GUILE_ARCH}-linux-gnu.tar.lz
  67. fi
  68. if [ ! -f guile-${GUILE_VERSION}-pack-${GUILE_ARCH}-linux-gnu.tar.lz ]; then
  69. echo 'Unable to download guile pack'
  70. exit 6735238
  71. fi
  72. CURR_GUILE_HASH=$(sha256sum guile-${GUILE_VERSION}-pack-${GUILE_ARCH}-linux-gnu.tar.lz | awk -F ' ' '{print $1}')
  73. if [[ "$CURR_GUILE_HASH" != "$GUILE_HASH" ]]; then
  74. echo 'Guile hash does not match'
  75. exit 7237625
  76. fi
  77. cd /
  78. tar xvf $INSTALL_DIR/guile-${GUILE_VERSION}-pack-${GUILE_ARCH}-linux-gnu.tar.lz
  79. if [ ! -d /opt/guile-${GUILE_VERSION}/bin ]; then
  80. echo 'Guile was not installed'
  81. exit 825269
  82. fi
  83. echo "export GUILE_PATH=/opt/guile-${GUILE_VERSION}/bin" >> ~/.bashrc
  84. echo 'export PATH=$PATH:$GUILE_PATH' >> ~/.bashrc
  85. }
  86. function install_guix_get_architecture {
  87. read_config_param ARCHITECTURE
  88. if [[ ${ARCHITECTURE} == *"386" || ${ARCHITECTURE} == *"686" ]]; then
  89. CURR_ARCH='i686'
  90. fi
  91. if [[ ${ARCHITECTURE} == *"amd64" || ${ARCHITECTURE} == "x86_64" ]]; then
  92. CURR_ARCH='x86_64'
  93. fi
  94. if [[ ${ARCHITECTURE} == *"arm"* ]]; then
  95. CURR_ARCH='armhf'
  96. fi
  97. if [ ! ${CURR_ARCH} ]; then
  98. echo $'No architecture specified'
  99. ARCHITECTURE=$(uname -m)
  100. if [[ ${ARCHITECTURE} == "arm"* ]]; then
  101. CURR_ARCH='armhf'
  102. echo $"Using $CURR_ARCH"
  103. fi
  104. if [[ ${ARCHITECTURE} == "amd"* || ${ARCHITECTURE} == "x86_64" ]]; then
  105. CURR_ARCH='x86_64'
  106. echo $"Using $CURR_ARCH"
  107. fi
  108. if [[ ${ARCHITECTURE} == *"386" || ${ARCHITECTURE} == *"686" ]]; then
  109. CURR_ARCH='i686'
  110. echo $"Using $CURR_ARCH"
  111. fi
  112. fi
  113. }
  114. function install_guix {
  115. if [[ $(app_is_installed install_guix) == "1" ]]; then
  116. return
  117. fi
  118. apt-get -qy install wget xz-utils
  119. read_config_param MY_USERNAME
  120. install_guix_get_architecture
  121. if [ ! -d $INSTALL_DIR/guix ]; then
  122. mkdir -p $INSTALL_DIR/guix
  123. fi
  124. cd $INSTALL_DIR/guix
  125. if [ ! -f guix-binary-${GUIX_VERSION}.${CURR_ARCH}-linux.tar.xz ]; then
  126. wget $GUIX_DOWNLOAD_URL/guix-binary-${GUIX_VERSION}.${CURR_ARCH}-linux.tar.xz
  127. fi
  128. if [ ! -f guix-binary-${GUIX_VERSION}.${CURR_ARCH}-linux.tar.xz ]; then
  129. echo $"Unable to download guix from $GUIX_DOWNLOAD_URL"
  130. exit 73826
  131. fi
  132. tar --warning=no-timestamp -xf guix-binary-${GUIX_VERSION}.${CURR_ARCH}-linux.tar.xz
  133. if [ ! -d var/guix ]; then
  134. echo $'guix directory var/guix not found'
  135. exit 8726325
  136. fi
  137. mv var/guix /var/
  138. if [ ! -d gnu ]; then
  139. echo $'guix gnu directory not found'
  140. exit 743383235
  141. fi
  142. mv gnu /
  143. ln -sf /var/guix/profiles/per-user/root/guix-profile /root/.guix-profile
  144. export GUIX_PROFILE=$HOME/.guix-profile
  145. source $GUIX_PROFILE/etc/profile
  146. # add build users
  147. groupadd --system guixbuild
  148. for i in `seq -w 1 10`;
  149. do
  150. useradd -g guixbuild -G guixbuild \
  151. -d /var/empty -s `which nologin` \
  152. -c "Guix build user $i" --system \
  153. guixbuilder$i;
  154. done
  155. if [ ! -f /root/.guix-profile/lib/systemd/system/guix-daemon.service ]; then
  156. echo $'No guix systemd daemon found'
  157. exit 78225548
  158. fi
  159. cp /root/.guix-profile/lib/systemd/system/guix-daemon.service \
  160. /etc/systemd/system/
  161. systemctl enable guix-daemon
  162. systemctl start guix-daemon
  163. if [ ! -d /usr/local/bin ]; then
  164. mkdir -p /usr/local/bin
  165. fi
  166. cd /usr/local/bin
  167. ln -s /var/guix/profiles/per-user/root/guix-profile/bin/guix
  168. if [ ! -d /usr/local/share/info ]; then
  169. mkdir -p /usr/local/share/info
  170. fi
  171. cd /usr/local/share/info
  172. if [ ! -d /var/guix/profiles/per-user/root/guix-profile/share/info ]; then
  173. echo $'Directory not found /var/guix/profiles/per-user/root/guix-profile/share/info'
  174. exit 7835202
  175. fi
  176. for i in /var/guix/profiles/per-user/root/guix-profile/share/info/* ;
  177. do ln -s $i ; done
  178. if ! grep -q 'GUIX_LOCPATH' /root/.bashrc; then
  179. echo 'export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale' >> /root/.bashrc
  180. fi
  181. if ! grep -q 'GUIX_LOCPATH' /etc/skel/.bashrc; then
  182. echo 'export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale' >> /etc/skel/.bashrc
  183. fi
  184. if ! grep -q 'GUIX_LOCPATH' /home/$MY_USERNAME/.bashrc; then
  185. echo 'export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale' >> /home/$MY_USERNAME/.bashrc
  186. fi
  187. if ! grep -q 'GUIX_PROFILE' /root/.bashrc; then
  188. echo 'export GUIX_PROFILE=$HOME/.guix-profile' >> /root/.bashrc
  189. echo 'source $GUIX_PROFILE/etc/profile' >> /root/.bashrc
  190. fi
  191. if ! grep -q 'GUIX_PROFILE' /etc/skel/.bashrc; then
  192. echo 'export GUIX_PROFILE=$HOME/.guix-profile' >> /etc/skel/.bashrc
  193. echo 'source $GUIX_PROFILE/etc/profile' >> /etc/skel/.bashrc
  194. fi
  195. if ! grep -q 'GUIX_PROFILE' /home/$MY_USERNAME/.bashrc; then
  196. echo 'export GUIX_PROFILE=$HOME/.guix-profile' >> /home/$MY_USERNAME/.bashrc
  197. echo 'source $GUIX_PROFILE/etc/profile' >> /home/$MY_USERNAME/.bashrc
  198. fi
  199. guix package -i glibc-locales
  200. install_completed install_guix
  201. }
  202. # NOTE: deliberately no exit 0