59 lines
1.8 KiB
Bash
59 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
||
# csv2cards.sh → html with guaranteed colour styling
|
||
|
||
CSV=${1:-credentials.csv}
|
||
OUT=${2:-cards.html}
|
||
|
||
# --------------------------------------------------------------
|
||
# 1️⃣ Write the full HTML header (including the colour CSS)
|
||
cat >"$OUT" <<'EOF'
|
||
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<title>Credentials cards</title>
|
||
<style>
|
||
@page { size: A4 portrait; margin: 1cm; }
|
||
body { font-family: monospace; display: flex; flex-wrap: wrap; gap: 0.5cm; }
|
||
.card {
|
||
width: 9cm;
|
||
border: 1px solid #333;
|
||
padding: 0.3cm;
|
||
box-sizing: border-box;
|
||
page-break-inside: avoid;
|
||
}
|
||
.field { margin: 0.1cm 0; }
|
||
.label { font-weight: bold; }
|
||
|
||
/* ---- 6‑colour palette (exactly as you requested) ---- */
|
||
.bg0 { background:#eeff90; } /* light lime */
|
||
.bg1 { background:#b9ffbf; } /* pastel green */
|
||
.bg2 { background:#b6e1ff; } /* soft blue */
|
||
.bg3 { background:#ffd795; } /* peach */
|
||
.bg4 { background:#f0a6fc; } /* lavender */
|
||
.bg5 { background:#f397a5; } /* coral */
|
||
</style>
|
||
</head>
|
||
<body>
|
||
EOF
|
||
|
||
# --------------------------------------------------------------
|
||
# 2️⃣ Convert each CSV row into a coloured card
|
||
awk -F',' '
|
||
NR>1{
|
||
col = (NR-2) % 6 # 0‑5 cycle
|
||
printf "<div class=\"card bg%d\">\n", col
|
||
printf " <div class=\"field\"><span class=\"label\">IP:</span> %s</div>\n", $1
|
||
printf " <div class=\"field\"><span class=\"label\">Host:</span> %s</div>\n", $2
|
||
printf " <div class=\"field\"><span class=\"label\">User:</span> %s</div>\n", $3
|
||
printf " <div class=\"field\"><span class=\"label\">Pass:</span> %s</div>\n", $4
|
||
printf "</div>\n"
|
||
}' "$CSV" >>"$OUT"
|
||
|
||
# --------------------------------------------------------------
|
||
# 3️⃣ Close the HTML document
|
||
cat >>"$OUT" <<'EOF'
|
||
</body>
|
||
</html>
|
||
EOF
|