Check required commands are installed.
Use dynamic temporary directory.
@@ -27,8 +27,18 @@ function die()
exit 1
}
+function tmpdir()
+{
+ local out=$(mktemp -d)
+ echo $out
+}
+
function check_args()
{
+ for req_cmd in curl docker docker-compose jq wget xxx ; do
+ $($req_cmd --help > /dev/null) || die "$req_cmd must be installed"
+ done
+
while :; do
case $1 in
-a|api)
@@ -57,17 +67,18 @@ function check_args()
exit
;;
-i|install)
- # TODO check for docker, curl, jq
+ tardir=$(tmpdir)
+ tarfile=$tardir/poseidon.tar.gz
if [ -z "$2" ]; then
- curl -s https://api.github.com/repos/cyberreboot/poseidon/releases/latest | jq '.["tarball_url"]' | xargs curl -L > /tmp/poseidon.tar.gz
+ curl -s https://api.github.com/repos/cyberreboot/poseidon/releases/latest | jq '.["tarball_url"]' | xargs curl -L > $tarfile
else
- curl -L https://github.com/cyberreboot/poseidon/tarball/"$2" > /tmp/poseidon.tar.gz
+ curl -L https://github.com/cyberreboot/poseidon/tarball/"$2" > $tarfile
fi
sudo mkdir -p "$POSEIDON_PREFIX"/opt/poseidon
sudo tar -C "$POSEIDON_PREFIX"/opt/poseidon -xvf /tmp/poseidon.tar.gz --strip=1
sudo chmod -R 755 "$POSEIDON_PREFIX"/opt/poseidon
sudo cp -n "$POSEIDON_PREFIX"/opt/poseidon/config/poseidon.config "$POSEIDON_PREFIX"/opt/poseidon/poseidon.config
- rm -f /tmp/poseidon.tar.gz
+ rm -rf $tardir
exit
;;
-l|logs)
@@ -135,7 +146,6 @@ function check_args()
sleep 0.3
done
if [ "$2" = "--grafana" ]; then
- # TODO check for wget
wget -O- --auth-no-challenge --post-data='{"name":"${DS_PROMETHEUS}","type":"prometheus","access":"proxy","url":"http://prometheus:9090","basicAuth":false,"isDefault":true}' --header="Content-Type: application/json;charset=UTF-8charset=UTF-8" 'http://admin:admin@0.0.0.0:3000/api/datasources'
fi
echo "Poseidon successfully started."
@@ -152,8 +162,8 @@ function check_args()
exit
;;
-u|update)
- # TODO update this script
- cp "$POSEIDON_PREFIX"/opt/poseidon/poseidon.config /tmp/poseidon.config || true
+ configdir=$(tmpdir)
+ cp "$POSEIDON_PREFIX"/opt/poseidon/poseidon.config $configdir || true
sudo rm -rf "$POSEIDON_PREFIX"/opt/poseidon
if [ -z "$2" ]; then
echo "Updating to latest release..."
@@ -162,7 +172,8 @@ function check_args()
echo "Updating to $2..."
poseidon install "$2"
fi
- sudo mv /tmp/poseidon.config "$POSEIDON_PREFIX"/opt/poseidon/poseidon.config || true
+ sudo mv $configdir/poseidon.config "$POSEIDON_PREFIX"/opt/poseidon/poseidon.config || true
+ rm -rf $configdir
echo "Done updating."
exit
;;
