#!/bin/bash -x
if [ -z "$1" ]; then
    echo "missing parameter"
    exit 1
fi

name="$1"

if [ ! -e /tmp/ss-mount-chroots-$name ]; then
    echo "uh oh, can't read size from /tmp/ss-mount-chroots-$name"
    exit 1
fi

size=$( cat /tmp/ss-mount-chroots-$name )
if [ -z "$size" ]; then
    echo "uh oh, can't read size from /tmp/ss-mount-chroots-$name"
    exit 1
fi

umount /chroot/ss-$name
if [ $? -gt 0 ]; then
    echo "problems with umount"
    exit 1
fi

lvremove -f chroots/ss-$name
if [ $? -gt 0 ]; then
    echo "problems with lvremove"
    exit 1
fi


lvresize -v --size -$size chroots/$name
if [ $? -gt 0 ]; then
    echo "problems with lvresize"
    exit 1
fi

rm /tmp/ss-mount-chroots-$name
