Skip to content

Instantly share code, notes, and snippets.

@mickael9
Created June 29, 2016 20:37
Show Gist options
  • Save mickael9/448314d47bc72827a74335d58ac94ce0 to your computer and use it in GitHub Desktop.
Save mickael9/448314d47bc72827a74335d58ac94ce0 to your computer and use it in GitHub Desktop.
# Maintainer: Sebastien Duthil <duthils@free.fr>
pkgname=factorio
pkgver=0.12.35
pkgrel=2
pkgdesc="A 2D game about building and maintaining factories."
arch=('i686' 'x86_64')
url="http://www.factorio.com/"
license=('custom: commercial')
conflicts=('factorio-demo')
depends=('libxcursor' 'alsa-lib' 'libxrandr' 'libxinerama' 'mesa')
source=(factorio.desktop
LICENSE)
sha256sums=('5f62aa7763f9ad367a051371bc16f3c174022bb3380eb221ba06bac395bf9815'
'67ec2f88afff5d7e0ca5fd3301b5d98655269c161a394368fa0ec49fbc0c0e21')
if test "$CARCH" == i686; then
__factorio_arch=i386
elif test "$CARCH" == x86_64; then
__factorio_arch=x64
fi
_gamepkg=factorio_alpha_${__factorio_arch}_$pkgver.tar.gz
_url=https://www.factorio.com/get-download/${pkgver}/alpha/linux64
build() {
local pkgpaths_tries=(
"$startdir"
"$srcdir"
"${XDG_DOWNLOAD_DIR:-$HOME/Downloads}"
)
[[ $SRCDEST != $startdir ]] && pkgpath_tries+=("$SRCDEST")
msg "You need a full copy of this game in order to install it"
# look for game tarball
for pkgpath_try in "${pkgpaths_tries[@]}" ; do
msg "Searching for ${_gamepkg} in dir: \"${pkgpath_try}\""
if [[ -f "${pkgpath_try}/${_gamepkg}" ]]; then
pkgpath=${pkgpath_try}
break
fi
done
# not found: download via user-supplied credentials
if [[ ! -f "${pkgpath}/${_gamepkg}" ]]; then
read -s -n1 -p "Do you want to use your factorio credentials to download the game ? (y/N)" ; echo
if [[ $REPLY == y ]]; then
_download && pkgpath=$srcdir || true
fi
fi
# not found: ask for path to game tarball
if [[ ! -f "${pkgpath}/${_gamepkg}" ]]; then
error "Game package not found, please type absolute path to ${_gamepkg} (/home/joe):"
read pkgpath
if [[ ! -f "${pkgpath}/${_gamepkg}" ]]; then
error "Unable to find game package."
return 1
fi
fi
# unpack game tarball
msg "Found game package, unpacking..."
tar xzf "${pkgpath}/${_gamepkg}" -C "${srcdir}"
}
# no modifications needed, the executable looks for:
# - data in /usr/share/factorio
# - config in ~/.factorio
package() {
cd "$srcdir/factorio"
install -d "${pkgdir}/usr/bin"
install -d "${pkgdir}/usr/share/applications"
install -g games -m 775 -d "${pkgdir}/usr/share/factorio"
install -d "${pkgdir}/usr/share/licenses/factorio"
install -m755 "bin/${__factorio_arch}/factorio" "$pkgdir/usr/bin/factorio"
cp -r data/* "$pkgdir/usr/share/factorio"
install -m644 "${srcdir}/factorio.desktop" "${pkgdir}/usr/share/applications/factorio.desktop"
install -m644 "${srcdir}/LICENSE" "${pkgdir}/usr/share/licenses/factorio/LICENSE"
}
_download() {
local cookie=$(mktemp)
local ret=1
while true; do
local login
local password
local file="${srcdir}/${_gamepkg}"
read -p "Username or email: " login
[[ -n $login ]] && read -sp "Password: " password ; echo
if [[ -n $login && -n $password ]]; then
msg "Logging in..."
if curl -D - -o /dev/null -s -f -c "$cookie" https://www.factorio.com/login -d username-or-email="$login" -d password="$password" | grep -q '^Location: /'; then
msg2 "Logged in"
msg "Downloading ${_gamepkg} from $_url ..."
curl -f -b "$cookie" -L -o "${file}.part" "$_url" || rm -f "${file}.part"
if [[ -f "${file}.part" ]]; then
ret=0
msg2 "Download successful"
mv "${file}"{.part,}
else
error "Download failed"
fi
break
else
error "Login failed"
read -s -n1 -p "Try again? (y/N)" ; echo
[[ $REPLY != y ]] && break
fi
else
break
fi
done
rm $cookie
return $ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment