environment.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. #make sure lsb release is installed
  3. apt-get install lsb-release
  4. #operating system details
  5. os_name=$(lsb_release -is)
  6. os_codename=$(lsb_release -cs)
  7. os_mode='unknown'
  8. #cpu details
  9. cpu_name=$(uname -m)
  10. cpu_architecture='unknown'
  11. cpu_mode='unknown'
  12. #set the environment path
  13. export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  14. #check what the CPU and OS are
  15. if [ .$cpu_name = .'armv6l' ]; then
  16. # RaspberryPi Zero
  17. os_mode='32'
  18. cpu_mode='32'
  19. cpu_architecture='arm'
  20. elif [ .$cpu_name = .'armv7l' ]; then
  21. # RaspberryPi 3 is actually armv8l but current Raspbian reports the cpu as armv7l and no Raspbian 64Bit has been released at this time
  22. os_mode='32'
  23. cpu_mode='32'
  24. cpu_architecture='arm'
  25. elif [ .$cpu_name = .'armv8l' ]; then
  26. # No test case for armv8l
  27. os_mode='unknown'
  28. cpu_mode='64'
  29. cpu_architecture='arm'
  30. elif [ .$cpu_name = .'aarch64' ]; then
  31. os_mode='64'
  32. cpu_mode='64'
  33. cpu_architecture='arm'
  34. elif [ .$cpu_name = .'i386' ]; then
  35. os_mode='32'
  36. if [ .$(grep -o -w 'lm' /proc/cpuinfo | head -n 1) = .'lm' ]; then
  37. cpu_mode='64'
  38. else
  39. cpu_mode='32'
  40. fi
  41. cpu_architecture='x86'
  42. elif [ .$cpu_name = .'i686' ]; then
  43. os_mode='32'
  44. if [ .$(grep -o -w 'lm' /proc/cpuinfo | head -n 1) = .'lm' ]; then
  45. cpu_mode='64'
  46. else
  47. cpu_mode='32'
  48. fi
  49. cpu_architecture='x86'
  50. elif [ .$cpu_name = .'x86_64' ]; then
  51. os_mode='64'
  52. if [ .$(grep -o -w 'lm' /proc/cpuinfo | head -n 1) = .'lm' ]; then
  53. cpu_mode='64'
  54. else
  55. cpu_mode='32'
  56. fi
  57. cpu_architecture='x86'
  58. else
  59. error "You are using an unsupported cpu '$cpu_name'"
  60. exit 3
  61. fi
  62. if [ .$cpu_architecture = .'arm' ]; then
  63. if [ .$os_mode = .'32' ]; then
  64. verbose "Correct CPU and Operating System detected, using the ARM repo"
  65. elif [ .$os_mode = .'64' ]; then
  66. switch_source=true
  67. switch_package=false
  68. else
  69. error "Unknown OS mode $os_mode this is unsupported"
  70. switch_source=true
  71. switch_package=false
  72. fi
  73. elif [ .$cpu_architecture = .'x86' ]; then
  74. if [ .$os_mode = .'32' ]; then
  75. error "You are using a 32bit OS this is unsupported"
  76. if [ .$cpu_mode = .'64' ]; then
  77. warning " Your CPU is 64bit you should consider reinstalling with a 64bit OS"
  78. fi
  79. switch_source=true
  80. switch_package=false
  81. elif [ .$os_mode = .'64' ]; then
  82. verbose "Correct CPU and Operating System detected"
  83. else
  84. error "Unknown Operating System mode '$os_mode' is unsupported"
  85. switch_source=true
  86. switch_package=false
  87. fi
  88. else
  89. error "You are using an unsupported architecture '$cpu_architecture'"
  90. warning "Detected environment was :-"
  91. warning "os_name:'$os_name'"
  92. warning "os_codename:'$os_codename'"
  93. warning "os_mode:'$os_mode'"
  94. warning "cpu_name:'$cpu_name'"
  95. exit 3
  96. fi