Skip to content

Instantly share code, notes, and snippets.

@Darkhogg
Created January 23, 2015 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Darkhogg/d4f45cc4f2a390ad4222 to your computer and use it in GitHub Desktop.
Save Darkhogg/d4f45cc4f2a390ad4222 to your computer and use it in GitHub Desktop.
A small script to update the factorio-experimental AUR package automatically without any manual intervention
#!/bin/bash
function msg () {
local FMT="$1"
shift
printf "\x1B[1;35m==> \x1B[;1m${FMT}\x1B[m\n" "$@"
}
function msg2 () {
local FMT="$1"
shift
printf "\x1B[1;36m -> \x1B[;1m${FMT}\x1B[m\n" "$@"
}
function ask () {
local OPTIND
local OPTARG
local OPTERR
local NoEcho=
while getopts ':p' OPT; do
case $OPT in
p) NoEcho='-s'
esac
done
shift $(( OPTIND - 1 ))
local Var="$1"
shift
printf "\x1B[1;33m > \x1B[;1m%s\x1B[m: " "$*"
read $NoEcho $Var
if [ -n "$NoEcho" ]; then
printf '\n'
fi
}
if [ -z "$1" ]; then
VER_AUR="$(package-query -A -f "%v" factorio-experimental)"
else
VER_AUR="$1"
fi
VER_LOCAL="$(package-query -A -f "%l" factorio-experimental)"
VER_FACTORIO="${VER_AUR%%-*}"
TARNAME="factorio_alpha_x64_${VER_FACTORIO}.tar.gz"
mkdir -p ~/.factorio/build
cd ~/.factorio/build
if [ "$VER_AUR" != "$VER_LOCAL" ]; then
msg "Updating Factorio: [%s] -> [%s]" "$VER_LOCAL" "$VER_AUR"
msg2 "Downloading PKGBUILD..."
yaourt -G factorio-experimental --nocolor --noconfirm
cd factorio-experimental
sed -i PKGBUILD -e "s/^pkgver=.*$/pkgver=$VER_FACTORIO/"
Login=
if [ -f ../cookies ]; then
msg2 "Found Cookie file, checking access..."
if curl -L "https://www.factorio.com" -b ../cookies | grep "log out" >/dev/null; then
Login=yes
fi
fi
if [ -z "$Login" ]; then
msg2 "Enter your credentials for Factorio:"
ask USER 'Username'
ask -p PASS 'Password'
curl -L "https://www.factorio.com/login" \
-X POST -d "username-or-email=$USER&password=$PASS" \
-c ../cookies \
>/dev/null
fi
msg2 "Downloading Factorio $VER_FACTORIO..."
curl -L "https://www.factorio.com/get-download/direct/$VER_FACTORIO/alpha/linux64" \
-C - -o "../$TARNAME" \
-b ../cookies -c ../cookies
ln -sf "../$TARNAME" .
makepkg -cfi --noconfirm </dev/null
cd ..
rm -rf factorio-experimental
else
msg "Factorio is up to date: %s" "$VER_AUR"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment