Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Last active March 25, 2022 17:57
Show Gist options
  • Save mohemohe/fe31d52d36575e1e4416d6edffe92f84 to your computer and use it in GitHub Desktop.
Save mohemohe/fe31d52d36575e1e4416d6edffe92f84 to your computer and use it in GitHub Desktop.
Linode ArchLinux
#!/bin/bash -x
TARGET_USER=mohemohe
YAY_VERSION=11.1.2
SLACK_INCOMING_WEBHOOK_URL=https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/slack
exec &>/var/log/stackscript.log
cat << EOS | curl -d @- -X POST "$SLACK_INCOMING_WEBHOOK_URL"
{
"text": "StackScript start",
"attachments": [{
"fields": [{
"title": "URL",
"value": "https://cloud.linode.com/linodes/${LINODE_ID}",
"short": true
}]
}]
}
EOS
groupadd -f wheel
useradd -G wheel -m -s /bin/bash ${TARGET_USER}
mkdir -p /home/${TARGET_USER}/.ssh
chmod 700 /home/${TARGET_USER}/.ssh
curl https://github.com/${TARGET_USER}.keys > /home/${TARGET_USER}/.ssh/authorized_keys
chmod 600 /home/${TARGET_USER}/.ssh/authorized_keys
chown ${TARGET_USER}: -R /home/${TARGET_USER}
sed -i 's|PasswordAuthentication yes|PasswordAuthentication no|' /etc/ssh/sshd_config
sed -i 's|PermitRootLogin yes|PermitRootLogin no|' /etc/ssh/sshd_config
systemctl restart sshd
echo '%wheel ALL=(ALL:ALL) NOPASSWD:ALL' >> /etc/sudoers
timedatectl set-timezone Asia/Tokyo
PUBLIC_IP="$(curl http://checkip.amazonaws.com/)"
hostnamectl set-hostname $(echo $PUBLIC_IP | sed 's|\.|-|g')
sed -i 's|#Color|Color|' /etc/pacman.conf
sed -i 's|#ParallelDownloads|ParallelDownloads|' /etc/pacman.conf
pacman-key --populate
pacman -Syy
curl -L https://github.com/Jguer/yay/releases/download/v${YAY_VERSION}/yay_${YAY_VERSION}_$(uname -m).tar.gz > ./yay_${YAY_VERSION}_$(uname -m).tar.gz
tar xvf ./yay_${YAY_VERSION}_$(uname -m).tar.gz
./yay_${YAY_VERSION}_$(uname -m)/yay -S --noconfirm git base-devel yay-bin
cat << EOS | curl -d @- -X POST "${SLACK_INCOMING_WEBHOOK_URL}"
{
"text": "StackScript complete",
"attachments": [{
"color": "#27b927",
"fields": [{
"title": "URL",
"value": "https://cloud.linode.com/linodes/${LINODE_ID}",
"short": true
}, {
"title": "Public IP",
"value": "${PUBLIC_IP}",
"short": true
}]
}]
}
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment