sup view libsup.sh @ rev 20

Add remove command nd improve install
author Christophe Lincoln <pankso@slitaz.org>
date Sun Feb 26 21:05:33 2017 +0100 (2017-02-26)
parents 6e287a70e3d7
children a5e4d133589a
line source
1 #!/bin/sh
2 #
3 # libsup.sh - Shared SHell functions between sup cmdline/gtk+ tools
4 #
5 # Copyright (C) 2017 SliTaz GNU/Linux - BSD License
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
8 . /lib/libtaz.sh
10 bin="$HOME/.local/bin"
11 config="$HOME/.config"
12 cache="$HOME/.cache/sup"
13 data="$HOME/.local/share"
14 supdb="$data/sup"
15 installed="$supdb/installed"
16 activity="$cache/activity.log"
18 mirror="http://scn.slitaz.org/content/sup/packages"
19 md5list="$supdb/packages.md5"
20 pkgsdb="$supdb/packages.db"
22 wok="$supdb/wok"
23 supcook="$HOME/sup-cook"
24 cooked="$supcook/packages"
26 export TEXTDOMAIN='sup-clients'
27 alias wget="busybox wget"
29 #
30 # Functions
31 #
33 # Set ttysize= # stty will not work if called from GTK box or CGI script
34 tty_size() {
35 local size=$(stty size | cut -d " " -f 2)
36 [ "$size" ] && local size=80
37 echo ${size}
38 }
40 # Extract a sup package: extract_sup "/path/to/pkg.sup"
41 extract_sup() {
42 pkg="$(basename ${1%.sup})"
43 supfile="$(readlink -f ${1%.sup}.sup)"
45 gettext "Uncompressing package tree..."
46 rm -rf ${pkg} && mkdir -p ${pkg} && cd ${pkg}
48 cpio -idm --quiet < "$supfile"
49 unlzma -c files.lzma | cpio -idm --quiet
51 rm files.lzma
52 size="$(du -sh $dest | cut -d " " -f 1)"
53 status
54 }
56 # Install a sup package
57 install_sup() {
58 pkg="$(basename ${1%.sup})"
59 supfile="$(readlink -f ${1%.sup}.sup)"
60 cache="$cache/install"
62 rm -rf ${cache} && mkdir ${cache}
63 cp ${supfile} ${cache} && cd ${cache}
65 # Get receip for deps
66 cpio -i receip --quiet < ${supfile}
67 . receip
69 # Install sup deps || exit on missing system deps ?
70 newline
71 gettext "Checking dependencies for"; echo " $PACKAGE..."
72 for dep in ${SUP_DEPS}; do
73 if [ ! "$installed/$dep" ]; then
74 echo "Missing dependency:"; colorize 35 " $dep"
75 fi
76 done
77 . /etc/slitaz/slitaz.conf
78 for dep in ${DEPENDS}; do
79 if [ ! "$PKGS_DB/installed/$dep" ]; then
80 echo "Missing dependency:"; colorize 35 " $dep"
81 fi
82 done
84 newline
85 gettext "Installing package:"; colorize 36 " $PACKAGE $VERSION"
86 log "$(gettext 'Installing package:') $PACKAGE $VERSION"
87 separator
89 # Extract and source receip first to check deps
90 extract_sup "$supfile"
92 # Execute sup_install() in files/ tree so packages maintainers just
93 # have to dl and move files where they were in $HOME
94 cd files
95 if grep -q "^sup_install" ../receip; then
96 gettext "Executing install function:"
97 indent $(($(tty_size) - 18)) "[ $(colorize 33 sup_install) ]"
98 sup_install
99 fi
101 # Create files.list
102 if [ "$verbose" ]; then
103 gettext "Creating the list of installed files..."; echo
104 fi
105 files_list="${cache}/${PACKAGE}-${VERSION}/files.list"
106 find . -type f -print > ${files_list}
107 find . -type l -print >> ${files_list}
108 sed -i s/'^.'/''/g ${files_list}
110 # Back to pkg tree
111 cd ${cache}/${PACKAGE}-${VERSION}
112 echo "sup_size=\"$(du -sh files | cut -d " " -f 1)\"" >> receip
114 # Now we need a place to store package data and set $sup_size
116 gettext "Installing files:"
117 echo -n "$(colorize 35 " $(wc -l files.list | cut -d " " -f 1)")"
118 data="${installed}/${PACKAGE}"
119 mkdir -p ${data}
120 for file in receip README files.list; do
121 [ -f "$file" ] && cp -f ${file} ${data}
122 done
123 for file in $(ls -A files); do
124 cp -rf files/${file} ${HOME}
125 done && status
126 newline && rm -rf ${cache}
127 }
129 # Remove a sup package
130 remove_sup() {
131 pkg="$1"
132 files_list="$installed/$pkg/files.list"
133 . ${installed}/${pkg}/receip
135 newline
136 gettext "Removing package:"; colorize 36 " $PACKAGE $VERSION"
137 log "$(gettext 'Removing package:') $PACKAGE $VERSION"
138 separator
140 gettext "Files to remove :"
141 indent $(($(tty_size) - 8)) \
142 "[ $(colorize 33 $(wc -l ${files_list} | cut -d ' ' -f 1)) ]"
144 # Remove all files
145 for file in $(cat $files_list)
146 do
147 # --verbose
148 if [ "$verbose" ]; then
149 gettext "Removing file :"; echo -n " ${file#/}"
150 rm -f "${HOME}${file}"; status
151 # Empty folder ?
152 if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then
153 path="$(dirname $file)"
154 gettext "Removing folder :"; echo -n " ${path#/}"
155 rmdir "${HOME}$(dirname $file)"; status
156 fi
157 else
158 rm -f "${HOME}${file}"
159 # Empty folder ?
160 if [ ! "$(ls -A ${HOME}$(dirname $file))" ]; then
161 rmdir "${HOME}$(dirname $file)"
162 fi
163 fi
164 done
165 gettext "Removing packages from local database..."
166 rm -rf ${installed}/${pkg}; status
167 newline
168 }