<?php
	if (!isset($argv[1])) {
		die('No version set, please use ' . PHP_EOL .'make deploy version=' . PHP_EOL);
	}
	$file = file_get_contents(dirname(__FILE__) . '/info.json.tpl');
	$file = str_replace('%version%', $argv[1], $file);
	$file = str_replace('%date%', date('d.m.Y H:i:00'), $file);
	$file = str_replace('%changelog%', parseChangeLog(), $file);

	$ptr = fopen('info.json', 'w');
	fwrite($ptr, $file);
	fclose($ptr);


	system('lftp -e "put -O / info.json; bye" -u "lv-sachsen-main_ftp3,sE&xDXc8za#S" bdp.mein-verein.online');
	function parseChangeLog()
	{
		$return = '';
		foreach (file(dirname(__FILE__) . '/../changelog') as $line) {
			$line = trim($line);
			if ($line !== '') {
				$return .= $line;
			}
		};

		return $return;
	}