|
|
|
@ -34,20 +34,27 @@ for arg in "$@"; do
|
|
|
|
|
substitution_cmd="${substitution_cmd}s|\\\$${arg%%=*}|${arg#*=}|g;" |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
# Perform substitutions |
|
|
|
|
sudo sh -c "sed \"$substitution_cmd\" \"$template_path\" > \"$service_path\"" |
|
|
|
|
# Perform substitutions into a temporary file in /tmp |
|
|
|
|
tmp_file="/tmp/tmp_service" |
|
|
|
|
sed "$substitution_cmd" "$template_path" > "$tmp_file" |
|
|
|
|
|
|
|
|
|
# Ask for missing variables |
|
|
|
|
while IFS= read -r line; do |
|
|
|
|
if echo "$line" | grep -q '\$'; then |
|
|
|
|
var=$(echo "$line" | sed -n -e 's/^.*\$\([A-Z_]*\).*$/\1/p') |
|
|
|
|
if [ -n "$var" ]; then |
|
|
|
|
echo "Enter a value for $var: " |
|
|
|
|
read -r value |
|
|
|
|
sed -i "s|\$$var|$value|g" "$service_path" |
|
|
|
|
value="${!var}" |
|
|
|
|
if [ -z "$value" ]; then |
|
|
|
|
echo "Enter a value for $var: " |
|
|
|
|
read -r value |
|
|
|
|
fi |
|
|
|
|
sed -i "s|\$$var|$value|g" "$tmp_file" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
done < "$service_path" |
|
|
|
|
done < "$tmp_file" |
|
|
|
|
|
|
|
|
|
# Move the temporary file to the final destination |
|
|
|
|
sudo mv "$tmp_file" "$service_path" |
|
|
|
|
|
|
|
|
|
# Set permissions |
|
|
|
|
sudo chmod 644 "$service_path" |
|
|
|
|