mng_pip 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/bin/bash
  2. #set -x
  3. clear
  4. ###
  5. #
  6. # @author: Stéphane HUC
  7. # @mail: devs@stephane-huc.net
  8. # @gpg:fingerprint: CE2C CF7C AB68 0329 0D20 5F49 6135 D440 4D44 BD58
  9. #
  10. # @licence: GNU/GPL 3
  11. #
  12. # Git: https://framagit.org/hucste/tools
  13. #
  14. # Date: 2017/03/16
  15. #
  16. ###
  17. ###
  18. #
  19. # pip install, update
  20. #
  21. ###
  22. arg="$1"
  23. cmd="$2"
  24. RACINE="$(dirname $(readlink -f -- "$0"))"
  25. #mounts=('/usr' '/usr/local')
  26. echo_help() {
  27. echo "Usage: ${0##*/} {install|uninstall|update} [option]" >&2
  28. echo "Option possible: package_name" >&2
  29. exit 1
  30. }
  31. install() {
  32. printf "%s \n" "*** Install: $1"
  33. pip install "$1"
  34. }
  35. launcher() {
  36. echo "Votre choix : ${arg}"
  37. case "${arg}" in
  38. -i|ins|install) install "${cmd}" ;;
  39. -u|uninstall) uninstall "${cmd}" ;;
  40. -up|upd|update) update ;;
  41. *) echo_help ;;
  42. esac
  43. }
  44. test_args() {
  45. if [ -z "${arg}" ]; then
  46. printf "[ \\33[1;31m %s \\33[0;39m ] %s \n" "KO" "Need args!"
  47. echo_help
  48. fi
  49. }
  50. test_mount() {
  51. printf "%s \n" "*** Essai de montage en écriture des partitions nécessaires ! "
  52. while IFS=" " read -r fs info; do
  53. IFS="," read -r access _ <<< "$info"
  54. if [ "${access}" == "ro" ]; then
  55. if mount -o remount,rw ${fs}; then
  56. printf "[ \\33[1;32m %s \\33[0;39m ] %s \n" "OK" "Mount rw ${fs}!"
  57. else
  58. printf "[ \\33[1;31m %s \\33[0;39m ] %s \n" "KO" "Mount rw ${fs}!"
  59. exit 1
  60. fi
  61. fi
  62. done < <(awk '/\/usr/ { print $2" "$4 }' /proc/mounts)
  63. }
  64. test_umount() {
  65. printf "%s \n" "*** Essai de montage en lecture des partitions nécessaires !"
  66. while IFS=" " read -r fs info; do
  67. IFS="," read -r access _ <<< "$info"
  68. if [ "${access}" == "rw" ]; then
  69. if mount -o remount,ro ${fs}; then
  70. printf "[ \\33[1;32m %s \\33[0;39m ] %s \n" "OK" "Mount ro ${fs}!"
  71. else
  72. printf "[ \\33[1;31m %s \\33[0;39m ] %s \n" "KO" "Mount ro ${fs}!"
  73. fi
  74. fi
  75. done < <(awk '/\/usr/ { print $2" "$4 }' /proc/mounts)
  76. }
  77. uninstall() {
  78. printf "%s \n" "*** Uninstall: $1"
  79. pip uninstall "$1"
  80. }
  81. update() {
  82. printf "%s \n" "*** Essai de mise-à-jour de pip (himself!) :"
  83. pip install -U pip
  84. printf "%s \n" "*** Essai de mise-à-jour des modules python :"
  85. pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
  86. #pip freeze | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
  87. sleep 1
  88. }
  89. verify_uid() {
  90. if [ $(id -u) -ne 0 ]; then
  91. printf "[ \\33[1;31m %s \\33[0;39m ] %s \n" "KO" "Need to get rights admins!"
  92. exit 1
  93. fi
  94. }
  95. verify_uid
  96. test_args
  97. [ -x "$RACINE/chattr_sys" ] && $RACINE/chattr_sys false
  98. test_mount
  99. launcher
  100. test_umount
  101. [ -x "$RACINE/chattr_sys" ] && $RACINE/chattr_sys true