thaw 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/bin/sh
  2. ### Thaw ###
  3. #
  4. # Freon Linux package manager
  5. # (C) Chris Dorman, 2017-2020 LGPLv2
  6. #
  7. ### END ####
  8. # Include Freon Linux's config
  9. . /etc/conf.d/main.conf
  10. . /etc/conf.d/status
  11. # Nutrapak root
  12. THAWROOT="/share/thaw"
  13. # Package list
  14. PKGLIST="/share/thaw/package.list"
  15. # Package list name (could change in the future)
  16. PKGLISTNAME="package.list"
  17. # Mirror file
  18. MIRRORFILE="/share/thaw/mirror.txt"
  19. # TCZ mount point
  20. TCZMOUNT="/mnt/pkg"
  21. # Temp path
  22. TMPPATH="/tmp/thaw"
  23. # Installed package dir
  24. INSTALLEDPKG="/share/thaw/installed"
  25. if [ $(id -u) != "0" ]; then
  26. echo "Error: must be root to operate this command."
  27. exit 1
  28. fi
  29. # Check Thaw tmp directory
  30. if [ ! -d "$TMPPATH" ]; then
  31. mkdir $TMPPATH
  32. fi
  33. # Check if any packages are installed, if not fix before break
  34. if [ ! -d "$INSTALLEDPKG" ]; then
  35. mkdir $INSTALLEDPKG
  36. fi
  37. case $1 in
  38. get-install )
  39. echo ""
  40. # check package list
  41. if [ ! -s $PKGLIST ]; then
  42. rm $PKGLIST
  43. echo "Getting package list... "
  44. wget $(cat $MIRRORFILE)/$PKGLISTNAME -P $THAWROOT
  45. fi
  46. # check if package is already installed
  47. if [ -f "$INSTALLEDPKG/$2" ]; then
  48. echo "${2} is already installed."
  49. exit 0
  50. fi
  51. if [ -f $TMPPATH/$2 ]; then
  52. rm $TMPPATH/$2
  53. fi
  54. if [ ! -d $TMPPATH/$2 ]; then
  55. mkdir $TMPPATH/$2
  56. fi
  57. # Check to see if package exists, if so download
  58. echo "Checking ${2}'s existence... "
  59. if grep "$2" $PKGLIST > /dev/null
  60. then
  61. echo ""
  62. echo "Downloading ${2}..."
  63. wget $(cat $MIRRORFILE)/$2.tgz -P $TMPPATH/
  64. wget $(cat $MIRRORFILE)/$2.deps -P $TMPPATH/
  65. if grep -q "CHTTPD Error" $TMPPATH/$2.deps; then
  66. rm $TMPPATH/$2.deps
  67. fi
  68. else
  69. echo "${2} was not found in repository."
  70. exit 1
  71. fi
  72. # Extract the downloaded file
  73. echo -n "Extracting package to tmp... "
  74. tar -xzf $TMPPATH/$2.tgz -C $TMPPATH/$2/
  75. status
  76. # Examine dependencies for package
  77. if [ -f "$TMPPATH/$2.deps" ]; then
  78. i=1
  79. echo ""
  80. echo "++++++++++++++++++++++++++++++++++++++++"
  81. echo "Examining dependencies... "
  82. echo "++++++++++++++++++++++++++++++++++++++++"
  83. while read line; do
  84. if [ -f "$INSTALLEDPKG/$line" ]; then
  85. echo "$line - INSTALLED"
  86. else
  87. echo "$line"
  88. fi
  89. done < $TMPPATH/$2.deps
  90. sleep 1
  91. echo "++++++++++++++++++++++++++++++++++++++++"
  92. echo "Installing dependencies..."
  93. echo "++++++++++++++++++++++++++++++++++++++++"
  94. while read line; do
  95. if [ -f "$INSTALLEDPKG/$line" ]; then
  96. echo "${line} already installed"
  97. else
  98. echo "Installing ${line} for ${2}"
  99. thaw get-install ${line}
  100. fi
  101. done < $TMPPATH/$2.deps
  102. echo "++++++++++++++++++++++++++++++++++++++++"
  103. fi
  104. echo -n "Installing ${2}..."
  105. cp -a $TMPPATH/$2/* /
  106. status_serious
  107. if [ -f "$TMPPATH/$2/execute.sh" ]; then
  108. echo "Running ${2}'s execution script..."
  109. $TMPPATH/$2/execute.sh
  110. fi
  111. echo -n "Cleaning up..."
  112. if [ -f "/execute.sh" ]; then
  113. rm /execute.sh
  114. fi
  115. if [ -f "/$2.deps" ]; then
  116. rm /$2.deps
  117. fi
  118. if [ -f "/$2.tgz" ]; then
  119. rm /$2.tgz
  120. fi
  121. rm $TMPPATH/$2.tgz
  122. status
  123. echo -n "Removing temporary files..."
  124. rm -r $TMPPATH/$2
  125. status
  126. echo -n "Marking ${2} in the installation database..."
  127. touch $INSTALLEDPKG/$2
  128. status
  129. echo "${2} Installed!"
  130. echo ""
  131. ;;
  132. update )
  133. if [ -f $PKGLIST ]; then
  134. rm $PKGLIST
  135. fi
  136. echo "Getting package list... "
  137. wget $(cat $MIRRORFILE)/$PKGLISTNAME -P $THAWROOT
  138. status_serious
  139. ;;
  140. search )
  141. if [ ! -s $PKGLIST ]; then
  142. rm $PKGLIST
  143. echo "Getting package list... "
  144. wget $(cat $MIRRORFILE)/$PKGLISTNAME -P $THAWROOT
  145. status_serious
  146. fi
  147. echo "Searching results..."
  148. echo "++++++++++++++++++++++++++++++++++++++++"
  149. grep -i "$2" $PKGLIST
  150. echo "++++++++++++++++++++++++++++++++++++++++"
  151. ;;
  152. * )
  153. echo "Usage:
  154. thaw get-install <package> : Install a package
  155. thaw update : Update system package list
  156. thaw search <query> : Search for a package in the database
  157. "
  158. ;;
  159. esac