#!/bin/sh # shmake_license.sh - License processing for shmake # Author: Emilia Marigold process_license() { project_name="$1" license_name="$2" script_dir=$(get_script_dir) licenses_dir="$script_dir/licenses" printf "Processing license: %s...\n" "$license_name" if [ ! -d "$licenses_dir" ]; then printf "Error: Licenses directory not found at '%s'.\n" "$licenses_dir" printf "Ensure 'shmake' is installed with its 'licenses' folder alongside it.\n" exit 1 fi if [ ! -f "$licenses_dir/$license_name" ]; then printf "Warning: License file '%s' not found in script directory. Creating stub.\n" "$license_name" cat > "LICENSE" << EOF $license_name License Copyright (c) $(date +%Y) $project_name Permission is hereby granted... (See full text for $license_name) EOF return 0 fi cp "$licenses_dir/$license_name" "LICENSE" printf "\nEnter your name (for copyright): " read -r user_name [ -z "$user_name" ] && user_name="Your Name" printf "Enter organization (optional, press Enter to skip): " read -r user_org [ -z "$user_org" ] && user_org="None" printf "Enter project start year: " read -r project_year [ -z "$project_year" ] && project_year=$(date +%Y) current_year=$(date +%Y) escaped_name=$(printf "%s" "$user_name" | sed 's/[&/\]/\\&/g') escaped_org=$(printf "%s" "$user_org" | sed 's/[&/\]/\\&/g') tmp_file=$(mktemp) sed \ -e "s|(name)|$escaped_name|g" \ -e "s|(year)|$current_year|g" \ -e "s|(year1)|$project_year|g" \ -e "s|(year2)|$current_year|g" \ -e "s|(project_name)|$project_name|g" \ -e "s|(org)|$escaped_org|g" \ "LICENSE" > "$tmp_file" mv "$tmp_file" "LICENSE" printf "License '%s' applied successfully!\n" "$license_name" }