FROM 4tqrgqe5yrgfd/figma-linux-docker-image-ppa:latest

ARG FIGMA_LINUX_VERSION
ARG FIGMA_LINUX_REV

WORKDIR /usr/src/figma-linux

ENV USER=root

COPY ./build ./build
COPY ./gpg ./

RUN apt update &&  apt install xdg-utils -y && cat ./build/figma-linux-${FIGMA_LINUX_VERSION}/debian/changelog && \
  chmod a+x ./build/figma-linux-${FIGMA_LINUX_VERSION}/figma-linux && \
  chmod a+x ./build/figma-linux-${FIGMA_LINUX_VERSION}/chrome-sandbox && \
  chmod a+x ./build/figma-linux-${FIGMA_LINUX_VERSION}/*.sh && \
  gpg --import --no-tty --batch --yes ./pub.key && \
  gpg --import --no-tty --batch --yes ./secret.key && \
  gpg -k && \
  cp -rf ./id_rsa ~/.ssh && \
  chmod 600 ~/.ssh/id_rsa && \
  cd ./build/installers/linux-unpacked && \
  tar cJf ../../figma-linux_${FIGMA_LINUX_VERSION}.orig.tar.xz ./* && \
  cd ../../figma-linux-${FIGMA_LINUX_VERSION} && \
  chmod a+x debian/rules debian/postinst debian/postrm && \
  EDITOR=/bin/true dpkg-source -q --commit . patchsetname && \
  debuild -S -sa -p"gpg --batch --passphrase-file /usr/src/figma-linux/passphrase --pinentry-mode loopback" && \
  dput ppa-figma ../figma-linux_${FIGMA_LINUX_VERSION}-${FIGMA_LINUX_REV}ubuntu0_source.changes
