Skip to content

Instantly share code, notes, and snippets.

@adlerweb
Last active June 25, 2022 11:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adlerweb/031472145bcba78d2e7b1e1b3a41298d to your computer and use it in GitHub Desktop.
Save adlerweb/031472145bcba78d2e7b1e1b3a41298d to your computer and use it in GitHub Desktop.
Unattended deployment of yay on a system. Useful when generating VMs on the fly.
#!/bin/bash
version=$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags https://github.com/Jguer/yay.git '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3 | tr -d 'v')
url="https://github.com/Jguer/yay/releases/download/v${version}/yay_${version}_x86_64.tar.gz"
tmp=$(mktemp -d)
if [ -d "$tmp" ]
then
if [ "$(ls -A $tmp)" ]; then
echo "Oops. Temporary directory $tmp is not empty"
exit 1
fi
else
echo "Oops. Temporary directory $tmp not found"
exit 1
fi
pushd "$tmp"
wget $url && \
tar xvaf yay_*.tar.* && \
rm yay_*.tar.* && \
cd yay_* && \
./yay -Y --gendb && \
./yay -Syu --devel --noconfirm && \
./yay -Y --devel --save && \
./yay -S yay --noconfirm
popd
if compgen -G "$tmp/yay_*" > /dev/null ; then
rm -Rv "$tmp"/yay_*
fi
rmdir "$tmp"
- name: Deploy yay
ansible.builtin.shell: |
if ! command -v yay &> /dev/null ;then
version=$(git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags https://github.com/Jguer/yay.git '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3 | tr -d 'v')
url="https://github.com/Jguer/yay/releases/download/v${version}/yay_${version}_x86_64.tar.gz"
tmp=$(mktemp -d)
if [ -d "$tmp" ]
then
if [ "$(ls -A $tmp)" ]; then
echo "Oops. Temporary directory $tmp is not empty"
exit 1
fi
else
echo "Oops. Temporary directory $tmp not found"
exit 1
fi
pushd "$tmp"
wget $url && \
tar xvaf yay_*.tar.* && \
rm yay_*.tar.* && \
cd yay_* && \
./yay -Y --gendb && \
./yay -Syu --devel --noconfirm && \
./yay -Y --devel --save && \
./yay -S yay --noconfirm
popd
if compgen -G "$tmp/yay_*" > /dev/null ; then
rm -Rv "$tmp"/yay_*
fi
rmdir "$tmp"
fi
args:
executable: /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment