@@ -20,10 +20,12 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # +PATH="${PATH}:$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + appfsd_options=() if [ "$1" == "--cachedir" ]; then appfsd_options=("${appfsd_options[@]}" '--cachedir' "$2") shift; shift; @@ -44,10 +46,45 @@ call_appfsd --sqlite3 'DELETE FROM sites WHERE hostname = '"'$site'"'; DELETE FROM packages WHERE hostname = '"'$site'"';' || return 1 clean } + +function mirror() { + local site destinationDir + local baseURL index + local packageList + + local marker + + site="$1" + destinationDir="$2" + + baseURL="http://${site}/appfs" + index="${baseURL}/index" + + if [ ! -e "${destinationDir}" ]; then + mkdir "${destinationDir}" || return 1 + fi + + marker="$(openssl rand 20 -hex)" + + ( + cd "${destinationDir}" || exit 1 + + # XXX:TODO: This does not validate the signature + curl -sSL "${index}" > "index.${marker}" + + packageListHash="$(cat "index.${marker}" | cut -f 1 -d ,)" + packageListHashMethod="$(cat "index.${marker}" | cut -f 2 -d ,)" + #curl -sSL "${...}" + + mv "index.${marker}" index + ) || return 1 + + return 0 +} function clean() { call_appfsd --tcl "$(cat <<\_EOF_ unset -nocomplain row ::appfs::db eval {SELECT sha1, hostname FROM packages;} row { @@ -125,33 +162,48 @@ done return 0 } -case "$1" in +operation="$1" +shift +case "$operation" in install) - shift install "$@" || exit 1 exit 0 ;; invalidate) invalidate || exit 1 ;; remove-site) - remove_site "$2" || exit 1 + remove_site "$@" || exit 1 ;; clean) clean || exit 1 ;; clear) - clear "$2" || exit 1 + clear "$@" || exit 1 + ;; + hoard) + echo "not implemented" >&2 + exit 1 + + hoard "$@" || exit 1 + exit 0 + ;; + mirror) + echo "not implemented" >&2 + exit 1 + + mirror "$@" || exit 1 + exit 0 ;; *) - echo "Usage: appfs-cache {invalidate|clean|clear|clear |remove-site }" >&2 + echo "Usage: appfs-cache {invalidate|clean|clear|clear |remove-site |hoard |mirror }" >&2 exit 1 ;; esac pkill -HUP appfsd exit 0