#!/bin/bash

if [ "x$1" = "x" ]; then
	echo "Usage: $0 <port>"
	exit 1
fi

port=$1

curl -c login.txt -s \
        "http://localhost:$port/crx/login.jsp?UserId=admin&Password=die2ood>ei6E&Workspace=crx.default"

echo -n "Do you want to upload a file (y/n): "
read answer
if [ "$answer" = "y" ]; then
	echo -n "Which file do you want to upload: "
	read package
	if [ ! -f $package ]; then
		echo "Sorry your file doesn't exist. Aborting."
		exit 1
	fi
	curl -v -o progress.txt -b login.txt -F "file=@$package" "http://localhost:$port/crx/packmgr/list.jsp"
fi

echo -n "Do you want to install a package (y/n): "
read answer
if [ "$answer" = "y" ]; then
	echo -n "Please provide the correct package name, check the CRX package manager: "
	read name
	if [ -z $name ]; then
		echo "No name given. Aborting"
		exit 1
	fi
	curl -v -o progress.txt -b login.txt "http://localhost:$port/crx/packmgr/service.jsp?cmd=inst&name=$name"
fi

rm -f login.txt
cat progress.txt

