install.nimf 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #? stdtmpl(subsChar = '?') | standard
  2. #proc generateInstallScript(c: ConfigData): string =
  3. # result = "#!/bin/sh\n# Generated by niminst\n"
  4. # var proj = c.name.toLowerAscii
  5. set -e
  6. if [ $# -eq 1 ] ; then
  7. #if c.cat[fcUnixBin].len > 0:
  8. if [ -f "?{c.cat[fcUnixBin][0].toUnix}" ]
  9. then
  10. echo "?c.displayName build detected"
  11. else
  12. echo "Please build ?c.displayName before installing it"
  13. exit 1
  14. fi
  15. #end if
  16. case $1 in
  17. "--help"|"-h"|"help"|"h")
  18. echo "?c.displayName installation script"
  19. echo "Usage: [sudo] [env DESTDIR=...] sh install.sh DIR"
  20. echo "Where DIR may be:"
  21. echo " /usr/bin"
  22. echo " /usr/local/bin"
  23. echo " /opt"
  24. echo " <some other dir> (treated similar to '/opt')"
  25. echo "To deinstall, use the command:"
  26. echo "sh deinstall.sh DIR"
  27. exit 1
  28. ;;
  29. "/usr/bin")
  30. bindir=$1
  31. configdir="/etc/?proj"
  32. libdir="/usr/lib/?proj"
  33. docdir="/usr/share/?proj/doc"
  34. datadir="/usr/share/?proj/data"
  35. nimbleDir="/opt/nimble/pkgs/?c.nimblePkgName-?c.version"
  36. ;;
  37. "/usr/local/bin")
  38. bindir=$1
  39. configdir="/etc/?proj"
  40. libdir="/usr/local/lib/?proj"
  41. docdir="/usr/local/share/?proj/doc"
  42. datadir="/usr/local/share/?proj/data"
  43. nimbleDir="/opt/nimble/pkgs/?c.nimblePkgName-?c.version"
  44. ;;
  45. "/opt")
  46. bindir="/opt/?proj/bin"
  47. configdir="/opt/?proj/config"
  48. libdir="/opt/?proj/lib"
  49. docdir="/opt/?proj/doc"
  50. datadir="/opt/?proj/data"
  51. nimbleDir="/opt/nimble/pkgs/?c.nimblePkgName-?c.version"
  52. ;;
  53. *)
  54. bindir="$1/?proj/bin"
  55. configdir="$1/?proj/config"
  56. libdir="$1/?proj/lib"
  57. docdir="$1/?proj/doc"
  58. datadir="$1/?proj/data"
  59. nimbleDir="$1/?proj"
  60. ;;
  61. esac
  62. bindir="${DESTDIR}${bindir}"
  63. configdir="${DESTDIR}${configdir}"
  64. libdir="${DESTDIR}${libdir}"
  65. docdir="${DESTDIR}${docdir}"
  66. datadir="${DESTDIR}${datadir}"
  67. nimbleDir="${DESTDIR}${nimbleDir}"
  68. mkdir -p "$bindir"
  69. mkdir -p "$configdir"
  70. mkdir -p "$libdir"
  71. mkdir -p "$docdir"
  72. mkdir -p "$datadir"
  73. mkdir -p "$nimbleDir"
  74. echo "copying files..."
  75. #var createdDirs = newStringTable()
  76. #for cat in {fcConfig..fcLib, fcNimble}:
  77. # for f in items(c.cat[cat]):
  78. # var mk = splitFile(f.skipRoot).dir
  79. # if cat != fcNimble:
  80. # mk = unixDirVars[cat] & "/" & mk
  81. # else:
  82. # mk = "$nimbleDir" / splitFile(f).dir
  83. # end if
  84. # if mk.len > 0 and not createdDirs.hasKey(mk):
  85. # createdDirs[mk] = "true"
  86. mkdir -p "?{mk.toUnix}"
  87. # end if
  88. # end for
  89. #end for
  90. #for f in items(c.cat[fcUnixBin]):
  91. cp "?f.toUnix" "$bindir/?f.skipRoot.toUnix"
  92. chmod 755 "$bindir/?f.skipRoot.toUnix"
  93. #end for
  94. #for f in items(c.cat[fcConfig]):
  95. cp "?f.toUnix" "$configdir/?f.skipRoot.toUnix"
  96. chmod 644 "$configdir/?f.skipRoot.toUnix"
  97. #end for
  98. #for f in items(c.cat[fcData]):
  99. if [ -f "?f.toUnix" ]; then
  100. cp "?f.toUnix" "$datadir/?f.skipRoot.toUnix"
  101. chmod 644 "$datadir/?f.skipRoot.toUnix"
  102. fi
  103. #end for
  104. #for f in items(c.cat[fcDoc]):
  105. if [ -f "?f.toUnix" ]; then
  106. cp "?f.toUnix" "$docdir/?f.skipRoot.toUnix"
  107. chmod 644 "$docdir/?f.skipRoot.toUnix"
  108. fi
  109. #end for
  110. #for f in items(c.cat[fcLib]):
  111. cp "?f.toUnix" "$libdir/?f.skipRoot.toUnix"
  112. chmod 644 "$libdir/?f.skipRoot.toUnix"
  113. #end for
  114. #for f in items(c.cat[fcNimble]):
  115. cp "?f.toUnix" "$nimbleDir/?f.toUnix"
  116. chmod 644 "$nimbleDir/?f.toUnix"
  117. #end for
  118. cp "?{c.nimblePkgName}.nimble" "$nimbleDir/?{c.nimblePkgName}.nimble"
  119. chmod 644 "$nimbleDir/?{c.nimblePkgName}.nimble"
  120. echo "installation successful"
  121. else
  122. echo "?c.displayName installation script"
  123. echo "Usage: [sudo] [env DESTDIR=...] sh install.sh DIR"
  124. echo "Where DIR may be:"
  125. echo " /usr/bin"
  126. echo " /usr/local/bin"
  127. echo " /opt"
  128. echo " <some other dir> (treated similar to '/opt')"
  129. echo "To deinstall, use the command:"
  130. echo "sh deinstall.sh DIR"
  131. exit 1
  132. fi