PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.3 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "PackageManager/Client/Database"
  7. "PackageManager/Client/Filesystem"
  8. "PackageManager/Client/Package"
  9. "PackageManager/Color"
  10. "PackageManager/Helper"
  11. "PackageManager/Variables"
  12. )
  13. func init() {
  14. var (
  15. e error
  16. )
  17. _, e = os.Stat(Variables.ConfigDir)
  18. if os.IsNotExist(e) {
  19. os.MkdirAll(Variables.ConfigDir, 0644)
  20. } else if e != nil {
  21. panic(e)
  22. }
  23. }
  24. func HelpMsg() {
  25. var helpMsg string
  26. helpMsg = `Usage of %s:
  27. General:
  28. -V | -verbose
  29. Verbose output
  30. Filesystem diff:
  31. -Af | -add-files
  32. Add files
  33. -Cf | -commit
  34. Add files
  35. -Fd | -fs-diff
  36. Filesystem diff
  37. -Rf | -reset
  38. Reset added files
  39. -Cp | -create-pkg
  40. Create package from fs diff
  41. -Il | -install-local
  42. Install package from local tarball
  43. -ignore-deps-check
  44. Skip dependancies check
  45. `
  46. helpMsg = fmt.Sprintf(helpMsg, os.Args[0])
  47. fmt.Println(helpMsg)
  48. }
  49. func main() {
  50. var (
  51. getFilesystemDiffFlag bool
  52. getFilesystemDiffFlagLong bool
  53. addFileDiffFlag bool
  54. addFileDiffFlagLong bool
  55. commitAddedFilesFlag bool
  56. commitAddedFilesFlagLong bool
  57. resetAddedFilesFlag bool
  58. resetAddedFilesFlagLong bool
  59. createPackageFlag bool
  60. createPackageFlagLong bool
  61. installLocalPackageFlag bool
  62. installLocalPackageFlagLong bool
  63. ignoreDepsCheckFlag bool
  64. verboseOutputFlag bool
  65. verboseOutputFlagLong bool
  66. e error
  67. )
  68. flag.Usage = HelpMsg
  69. e = Helper.CheckRoot()
  70. if e != nil {
  71. fmt.Println(Color.Fatal(e))
  72. return
  73. }
  74. e = Database.InitDB()
  75. if e != nil {
  76. panic(e)
  77. }
  78. defer Database.DB.Close()
  79. defer Database.FsDB.Close()
  80. // TODO: Rework usage function
  81. // Initialise flags
  82. flag.BoolVar(&verboseOutputFlag, "V", false, "Verbose output")
  83. flag.BoolVar(&verboseOutputFlagLong, "verbose", false, "Verbose output")
  84. flag.BoolVar(&getFilesystemDiffFlag, "Fd", false, "Filesystem diff")
  85. flag.BoolVar(&getFilesystemDiffFlagLong, "fs-diff", false, "Filesystem diff")
  86. flag.BoolVar(&addFileDiffFlag, "Af", false, "Add files")
  87. flag.BoolVar(&addFileDiffFlagLong, "add-files", false, "Add files")
  88. flag.BoolVar(&commitAddedFilesFlag, "Cf", false, "Commit files")
  89. flag.BoolVar(&commitAddedFilesFlagLong, "commit", false, "Commit files")
  90. flag.BoolVar(&resetAddedFilesFlag, "Rf", false, "Reset added files")
  91. flag.BoolVar(&resetAddedFilesFlagLong, "reset", false, "Reset added files")
  92. flag.BoolVar(&createPackageFlag, "Cp", false, "Create package from fs diff")
  93. flag.BoolVar(&createPackageFlagLong, "create-pkg", false, "Create package from fs diff")
  94. flag.BoolVar(&installLocalPackageFlag, "Il", false, "Install package from local tarball")
  95. flag.BoolVar(&installLocalPackageFlagLong, "install-local", false, "Install package from local tarball")
  96. flag.BoolVar(&ignoreDepsCheckFlag, "ignore-deps-check", false, "Ignore dependancies check")
  97. flag.Parse()
  98. Variables.VerboseOutput = verboseOutputFlag || verboseOutputFlagLong
  99. Variables.IgnoreDepsCheck = ignoreDepsCheckFlag
  100. if getFilesystemDiffFlag || getFilesystemDiffFlagLong {
  101. var rootPath string = Variables.RootDir
  102. if len(flag.Args()) > 1 {
  103. flag.Usage()
  104. fmt.Println(Color.Fatal("Option takes one optional argument"))
  105. return
  106. }
  107. if len(flag.Args()) == 1 {
  108. rootPath = flag.Arg(0)
  109. }
  110. e = Filesystem.ShowFilesystemDiff(rootPath)
  111. if e != nil {
  112. panic(e)
  113. }
  114. return
  115. }
  116. if addFileDiffFlag || addFileDiffFlagLong {
  117. if len(flag.Args()) > 1 || len(flag.Args()) < 1 {
  118. fmt.Println(Color.Fatal("Must supply one argument"))
  119. flag.Usage()
  120. return
  121. }
  122. e = Filesystem.PickFiles(flag.Arg(0))
  123. if e != nil {
  124. panic(e)
  125. }
  126. return
  127. }
  128. if commitAddedFilesFlag || commitAddedFilesFlagLong {
  129. e = Filesystem.CommitFiles()
  130. if e != nil {
  131. panic(e)
  132. }
  133. return
  134. }
  135. if resetAddedFilesFlag || resetAddedFilesFlagLong {
  136. e = Filesystem.ResetAllPickedFiles()
  137. if e != nil {
  138. panic(e)
  139. }
  140. return
  141. }
  142. if createPackageFlag || createPackageFlagLong {
  143. e = Package.CreatePackage()
  144. if e != nil {
  145. panic(e)
  146. }
  147. return
  148. }
  149. if installLocalPackageFlag || installLocalPackageFlagLong {
  150. e = Package.InstallPackage(flag.Args())
  151. if e != nil {
  152. panic(e)
  153. }
  154. return
  155. }
  156. flag.Usage()
  157. fmt.Println(Color.Fatal("Nothing to do"))
  158. //e := Archive.TarGzip("/tmp/test", "/tmp/test.tar.gz")
  159. //e := Archive.UntarGzip("/tmp/test.tar.gz", "/tmp/test")
  160. //fmt.Println(e)
  161. }