#!/bin/bash
#This script builds luapam module for the appropriate lua version
#Lua-pam is needed by the lock screen widget
doasroot() {
    nohup which sudo > /dev/null
    if [ "$?" != "0" ]; then
        doas $@  
    else
        sudo $@
    fi
}
LUA_VERSION=$(awesome --version | \
    grep -Po "(?<=Compiled against Lua )5\.\d")
if [ "$LUA_VERSION" == "" ]; then
    echo "Unable to detect the lua version which awesome uses"
    exit 1
fi
echo "Target version: $LUA_VERSION"
git clone --recursive https://github.com/devurandom/lua-pam ~/.config/awesome/lua-pam
cd ~/.config/awesome/lua-pam
make LUA_VERSION="$LUA_VERSION"
mkdir -p ~/.config/awesome/libs/pam/
cp LICENSE ~/.config/awesome/libs/pam/
echo "https://github.com/devurandom/lua-pam" > ~/.config/awesome/libs/pam/README
cp pam.so ~/.config/awesome/libs/
rm -rf ~/.config/awesome/lua-pam

