#!/bin/awk -f################################################################################# Database Import Script for Auth Redux Mod# ------------------------------------------# This script will convert the specified 'auth.txt' file into a database format # required by the Auth Redux Mod. The output file will be generated in the same # world directory as the original 'auth.txt' file (which will be unchanged).## EXAMPLE:# awk -f convert.awk ~/.minetest/worlds/world/auth.txt################################################################################functionerror(msg){skipped++;printmsg" at line "NR" in "FILENAME". Skipping.";}BEGIN{FS=":";OFS=":";checked=0;skipped=0;# determine output file name from argumentsoutput_file=ARGV[1]if(sub(/[-_A-Za-z0-9]+\.txt$/,"auth.db",output_file)==0){# sanity check for nonstandard input fileoutput_file="auth.db";}print"Converting "ARGV[1]"...";# set default values for new database fieldsapproved_addrs="";oldlogin=-1;lifetime=0;total_failures=0;total_attempts=0;total_sessions=0;# print database headline to the output fileprint"auth_rx/2.1 @0">output_file;}NF!=4{error("Malformed record");next;}{username=$1;password=$2;assigned_privs=$3;newlogin=$4;if(!match(username,"^[a-zA-Z0-9_-]+$")){error("Invalid username field");next;}if(!match(newlogin,"^[0-9]+$")&&newlogin!=-1){error("Invalid last_login field");next;}# Database File Format# --------------------# username# password# oldlogin# newlogin# lifetime# total_sessions# total_attempts# total_failures# approved_addrs# assigned_privsprintusername,password,oldlogin,newlogin,lifetime,total_sessions,total_attempts,total_failures,approved_addrs,assigned_privs>output_file;checked++;}END{print"Done! "checked" records were imported to "output_file" ("skipped" records skipped)."}
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.