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