sup rev 6

Add sup and libsup.sh (for beta testing/playing)
author Christophe Lincoln <pankso@slitaz.org>
date Fri Feb 24 07:10:28 2017 +0100 (2017-02-24)
parents d8f9120afde5
children 358ce73c7e58
files libsup.sh sup
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libsup.sh	Fri Feb 24 07:10:28 2017 +0100
     1.3 @@ -0,0 +1,118 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# libsup.sh - Shared SHell functions between sup cmdline/gtk+ tools
     1.7 +#
     1.8 +# Copyright (C) 2017 SliTaz GNU/Linux - BSD License
     1.9 +# Author: Christophe Lincoln <pankso@slitaz.org>
    1.10 +#
    1.11 +. /lib/libtaz.sh
    1.12 +
    1.13 +bin="$HOME/.local/bin"
    1.14 +config="$HOME/.config"
    1.15 +cache="$HOME/.cache/sup"
    1.16 +data="$HOME/.local/share"
    1.17 +supdb="$data/sup"
    1.18 +installed="$supdb/installed"
    1.19 +activity="$cache/activity.log"
    1.20 +
    1.21 +mirror="http://scn.slitaz.org/content/sup/packages"
    1.22 +md5list="$supdb/packages.md5"
    1.23 +pkgsdb="$supdb/packages.db"
    1.24 +
    1.25 +wok="$supdb/wok"
    1.26 +supcook="$HOME/sup-cook"
    1.27 +cooked="$supcook/packages"
    1.28 +
    1.29 +#
    1.30 +# Functions
    1.31 +#
    1.32 +
    1.33 +get() {
    1.34 +	busybox wget "$1"
    1.35 +}
    1.36 +
    1.37 +# Extract a sup package: extract_sup "/path/to/pkg.sup"
    1.38 +extract_sup() {
    1.39 +	pkg="$(basename ${1%.sup})"
    1.40 +	supfile="$(readlink -f ${1%.sup}.sup)"
    1.41 +		
    1.42 +	gettext "Uncompressing package tree..."
    1.43 +	rm -rf ${pkg} && mkdir -p ${pkg} && cd ${pkg}
    1.44 +	
    1.45 +	cpio -idm --quiet < "$supfile"
    1.46 +	unlzma -c files.lzma | cpio -idm --quiet
    1.47 +	
    1.48 +	rm files.lzma
    1.49 +	size="$(du -sh $dest | cut -d "	" -f 1)"
    1.50 +	status
    1.51 +}
    1.52 +
    1.53 +# Install a sup package
    1.54 +install_sup() {
    1.55 +	pkg="$(basename ${1%.sup})"
    1.56 +	supfile="$(readlink -f ${1%.sup}.sup)"
    1.57 +	cache="$cache/install"
    1.58 +	
    1.59 +	rm -rf ${cache} && mkdir ${cache} 
    1.60 +	cp ${supfile} ${cache} && cd ${cache}
    1.61 +	
    1.62 +	# Get receip for deps
    1.63 +	cpio -i receip --quiet < ${supfile}
    1.64 +	. receip
    1.65 +	
    1.66 +	# Install sup deps || exit on missing system deps ?
    1.67 +	newline
    1.68 +	gettext "Checking dependencies for"; echo " $PACKAGE..."
    1.69 +	for dep in ${SUP_DEPS}; do
    1.70 +		if [ ! "$installed/$dep" ]; then
    1.71 +			echo "Missing dependency:"; colorize 35 " $dep"
    1.72 +		fi
    1.73 +	done
    1.74 +	. /etc/slitaz/slitaz.conf
    1.75 +	for dep in ${DEPENDS}; do
    1.76 +		if [ ! "$PKGS_DB/installed/$dep" ]; then
    1.77 +			echo "Missing dependency:"; colorize 35 " $dep"
    1.78 +		fi
    1.79 +	done
    1.80 +	
    1.81 +	newline
    1.82 +	gettext "Installing package:"; colorize 36 " $PACKAGE $VERSION"
    1.83 +	log "$(gettext 'Installing package:') $pkg"
    1.84 +	separator
    1.85 +	
    1.86 +	# Extract and source receip first to check deps
    1.87 +	extract_sup "$supfile"
    1.88 +	
    1.89 +	# Execute sup_install() in files/ tree so packages maintainers just
    1.90 +	# have to dl and move files has they wher in $HOME
    1.91 +	cd files
    1.92 +	if grep -q "^sup_install" ../receip; then
    1.93 +		gettext "Executing install function:"; colorize 33 " sup_install"
    1.94 +		sup_install
    1.95 +	fi
    1.96 +	
    1.97 +	# Create files.list
    1.98 +	if [ "$verbose" ]; then
    1.99 +		gettext "Creating the list of installed files..."; echo
   1.100 +	fi
   1.101 +	files_list="${cache}/${PACKAGE}-${VERSION}/files.list"
   1.102 +	find . -type f -print > ${files_list}
   1.103 +	find . -type l -print >> ${files_list}
   1.104 +	sed -i s/'^.'/''/g ${files_list}
   1.105 +	
   1.106 +	# Back to pkg tree
   1.107 +	cd ${cache}/${PACKAGE}-${VERSION}
   1.108 +	echo "sup_size=\"$(du -sh files | cut -d "	" -f 1)\"" >> receip
   1.109 +	
   1.110 +	# Now we need a place to store package data and set $sup_size
   1.111 +	gettext "Installing files to $HOME..."
   1.112 +	data="${installed}/${PACKAGE}"
   1.113 +	mkdir -p ${data}
   1.114 +	for file in receip README files.list; do
   1.115 +		[ -f "$file" ] && cp -f ${file} ${data}
   1.116 +	done
   1.117 +	for file in $(ls -A files); do
   1.118 +		cp -rf files/${file} ${HOME}
   1.119 +	done && status
   1.120 +	rm -rf ${cache} && separator && newline
   1.121 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/sup	Fri Feb 24 07:10:28 2017 +0100
     2.3 @@ -0,0 +1,219 @@
     2.4 +#!/bin/sh
     2.5 +#
     2.6 +# SliTaz Users Package - Minimal cmdline tools - README for devel info
     2.7 +#
     2.8 +# Copyright (C) 2017 SliTaz GNU/Linux - BSD License
     2.9 +# Author: Christophe Lincoln <pankso@slitaz.org>
    2.10 +#
    2.11 +if [ -f "/usr/lib/slitaz/libsup.sh" ]; then
    2.12 +	. /usr/lib/slitaz/libsup.sh
    2.13 +else
    2.14 +	. ./libsup.sh
    2.15 +fi
    2.16 +
    2.17 +# Sanity check
    2.18 +if [ ! "/home/$USER" ]; then
    2.19 +	gettext "Not a valid user: "; echo "id $(id -u)" && exit 1
    2.20 +fi
    2.21 +mkdir -p ${cache} ${installed}
    2.22 +
    2.23 +#
    2.24 +# Functions
    2.25 +#
    2.26 +
    2.27 +help() {
    2.28 +	cat << EOT
    2.29 +
    2.30 +$(boldify $(gettext "Usage:")) $(basename $0) [command] [package]
    2.31 +
    2.32 +$(boldify $(gettext "Commands:"))
    2.33 +  -c  cook
    2.34 +  -e  extract
    2.35 +  -i  install
    2.36 +  -l  list
    2.37 +
    2.38 +$(boldify $(gettext "Options:"))
    2.39 +  --init     cook    $(gettext "Initialize sup build environment")
    2.40 +  --verbose  all     $(gettext "Display more output message")
    2.41 +
    2.42 +EOT
    2.43 +	exit 0
    2.44 +}
    2.45 +
    2.46 +cook_init() {
    2.47 +	mkdir -p ${wok} ${cooked}
    2.48 +	if [ ! -d "$supcook/wok" ]; then
    2.49 +		ln -s ${wok} ${supcook}/wok
    2.50 +	fi
    2.51 +}
    2.52 +
    2.53 +#
    2.54 +# Commands
    2.55 +#
    2.56 +
    2.57 +case "$1" in
    2.58 +
    2.59 +	-c|cook)
    2.60 +		# Cook in $cache/cook amd mv pkg to a visible dir
    2.61 +		pkg="$2"
    2.62 +		receip="$wok/$pkg/receip"
    2.63 +		cache="$cache/cook"
    2.64 +		
    2.65 +		# Handle --init
    2.66 +		if [ "$init" ]; then
    2.67 +			gettext "Initializing sup cook environment..."
    2.68 +			cook_init
    2.69 +			status && exit 0
    2.70 +		fi
    2.71 +		
    2.72 +		# Sanity check
    2.73 +		if [ ! "$pkg" ]; then
    2.74 +			gettext "You must specify a package to cook:"
    2.75 +			boldify " sup cook [package]" && exit 1
    2.76 +		fi
    2.77 +		if [ ! -f "$receip" ]; then
    2.78 +			gettext "Can't find receip in wok for:"
    2.79 +			colorize 31 " $pkg" && exit 1
    2.80 +		fi
    2.81 +		
    2.82 +		newline
    2.83 +		gettext "Building package:"; colorize 36 " $pkg"
    2.84 +		separator
    2.85 +		rm -rf ${cache} && mkdir -p ${cache} ${cooked}
    2.86 +		
    2.87 +		# Check receip
    2.88 +		[ "$verbose" ] && gettext "Checking receip variables..."
    2.89 +		. ${receip}
    2.90 +		for var in PACKAGE VERSION SHORT_DESC MAINTAINER LICENSE WEB_SITE
    2.91 +		do
    2.92 +			value="$(. $receip; eval echo \$$var)"
    2.93 +			case "$var" in
    2.94 +				PACKAGE|VERSION|SHORT_DESC|MAINTAINER|LICENSE)
    2.95 +					if [ ! "$value" ]; then
    2.96 +						gettext "Empty variable:"; colorize 31 " $var=\"\""
    2.97 +						exit 1
    2.98 +					fi ;;
    2.99 +				WEB_SITE)
   2.100 +					if [ ! "$value" ]; then
   2.101 +						gettext "Empty variable:"; colorize 31 " $var=\"\""
   2.102 +						gettext "You can use:"
   2.103 +						boldify " http://scn.slitaz.org/?sup&pkg=$PACKAGE"
   2.104 +						exit 1
   2.105 +					fi ;;
   2.106 +			esac
   2.107 +		done
   2.108 +		[ "$verbose" ] && status
   2.109 +		
   2.110 +		# Set $PACKAGE-$VERSION.sup and copy pkg to cache
   2.111 +		supfile="$PACKAGE-$VERSION.sup"
   2.112 +		cp -rf ${wok}/${pkg} ${cache}/${supfile%.sup}
   2.113 +		cd ${cache}/${supfile%.sup}
   2.114 +		
   2.115 +		# Mouve to hidden dir: ~/.local and ~/.config
   2.116 +		for dir in local config; do
   2.117 +			mv files/${dir} files/.${dir}
   2.118 +		done
   2.119 +		
   2.120 +		# Add $build_date
   2.121 +		echo "build_date=\"$(date "+%Y-%m-%d %H:%M")\"" >> ${receip}
   2.122 +		
   2.123 +		gettext "Creating compressed archive..."
   2.124 +		find files | cpio -o -H newc --quiet | lzma e files.lzma -si
   2.125 +		rm -rf files
   2.126 +		find . -print | cpio -o -H newc --quiet > ${cooked}/${supfile}
   2.127 +		status
   2.128 +		
   2.129 +		size="$(du -sh $cooked/$supfile | cut -d "	" -f 1)"
   2.130 +		echo "$(gettext 'Packages:') $(colorize 33 $supfile) ($size)"
   2.131 +		sed -i "/^build_date=/"d ${receip}
   2.132 +		rm -rf ${cache} && newline ;;
   2.133 +	
   2.134 +	-e|extract)
   2.135 +		# Extract package.sup to current dir
   2.136 +		pkg="$2"
   2.137 +		
   2.138 +		# Sanity check
   2.139 +		if [ ! "$pkg" ]; then
   2.140 +			gettext "Missing package in argument:"
   2.141 +			colorize 35 " sup extract [package.sup]" && exit 1
   2.142 +		fi
   2.143 +		if [ ! -f "$pkg" ]; then
   2.144 +			gettext "Can't find package file:"; colorize 35 " $pkg" && exit 1
   2.145 +		fi
   2.146 +		
   2.147 +		newline
   2.148 +		gettext "Extract package:"; colorize 36 " $(basename $pkg)"
   2.149 +		separator
   2.150 +
   2.151 +		extract_sup "$pkg"
   2.152 +		
   2.153 +		echo "$(gettext 'Packages:') $(colorize 33 $pkg) ($size)"
   2.154 +		newline ;;
   2.155 +		 
   2.156 +	-i|install)
   2.157 +		# Download/extract run install() in $cache/install
   2.158 +		pkg="$2"
   2.159 +		
   2.160 +		if [ ! "$pkg" ]; then
   2.161 +			gettext "Missing package in argument:"
   2.162 +			boldify " sup install [name|pkg.sup]" && exit 1
   2.163 +		fi
   2.164 +		
   2.165 +		# Sup pkg in current dir
   2.166 +		if [ -f "$pkg" ]; then
   2.167 +			install_sup "$pkg" && exit 0
   2.168 +		fi
   2.169 +		
   2.170 +		# Sup cooked
   2.171 +		if [ -f "$cooked/$pkg" ]; then
   2.172 +			install_sup "$cooked/$pkg" && exit 0
   2.173 +		fi 
   2.174 +		
   2.175 +		gettext "Can't find sup package:"; colorize 31 " $pkg" ;;
   2.176 +	
   2.177 +	-l|list)
   2.178 +		installed_nb=$(ls ${installed} | wc -l)
   2.179 +		newline
   2.180 +		echo -n "$(colorize 36 $(gettext 'Installed sup packages:'))"
   2.181 +		boldify " $installed_nb"
   2.182 +		separator
   2.183 +		for pkg in $(ls ${installed}); do
   2.184 +			. ${wok}/${pkg}/receip
   2.185 +			echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
   2.186 +		done
   2.187 +		if [ "$installed_nb" == 0 ]; then
   2.188 +			gettext "No sup packages installed"; echo
   2.189 +		fi
   2.190 +		newline
   2.191 +		if [ -d "$wok" ]; then
   2.192 +			echo -n "$(colorize 35 $(gettext 'Sup packages in your wok:'))"
   2.193 +			boldify " $(ls ${wok} | wc -l)"
   2.194 +			separator
   2.195 +			for pkg in $(ls ${wok}); do
   2.196 +				. ${wok}/${pkg}/receip
   2.197 +				echo "$pkg $(indent 26 $VERSION) $(indent 42 $MAINTAINER)"
   2.198 +			done
   2.199 +			newline 
   2.200 +		fi ;;
   2.201 +	
   2.202 +	""|-h|help) help ;;
   2.203 +		
   2.204 +	*)
   2.205 +		# Display pkg info if installed
   2.206 +		pkg="$1"
   2.207 +		if [ -f "$installed/$pkg/receip" ]; then
   2.208 +			. ${installed}/${pkg}/receip
   2.209 +			newline
   2.210 +			gettext "Installed package:"; colorize 32 " $PACKAGE $VERSION"
   2.211 +			separator
   2.212 +			echo "Short desc: $SHORT_DESC"
   2.213 +			echo ""
   2.214 +			boldify "Installed files size: $sup_size"
   2.215 +			#
   2.216 +			cat ${installed}/${pkg}/files.list
   2.217 +			newline
   2.218 +		else
   2.219 +			gettext "Can't find installed package:"; colorize 31 " $pkg"
   2.220 +		fi ;;
   2.221 +
   2.222 +esac && exit 0