Skip to content

Instantly share code, notes, and snippets.

@federicociro
Last active March 28, 2024 13:47
Show Gist options
  • Save federicociro/3b0792254aa7f08cb6931766573055c9 to your computer and use it in GitHub Desktop.
Save federicociro/3b0792254aa7f08cb6931766573055c9 to your computer and use it in GitHub Desktop.
Fresh LxC actions
# Common aliases
alias la='LS_COLORS="mh=1;37" ls -A'
alias l='LS_COLORS="mh=1;37" ls -CF'
alias ll='LC_COLLATE=C LS_COLORS="mh=1;37" ls -la --si --group-directories-first'
alias cls='clear'
alias ..='cd ..'
alias ...='cd ../..'
alias nano='nano -lS'
alias ss='systemctl status'
# Nginx aliases
alias nt='nginx -t'
alias nr='systemctl reload nginx'
# Net tools
alias ports='netstat -tulpn'
# Docker Aliases
alias d='docker'
alias di='docker images'
alias dps='docker ps'
alias dpa='docker ps -a'
alias dl='docker logs'
alias drm='docker rm'
alias drmi='docker rmi'
alias dexec='docker exec -it'
alias dstop='docker stop'
alias drun='docker run'
# Docker Compose Aliases
alias dc='docker-compose'
alias dcu='docker-compose up'
alias dcud='docker-compose up -d'
alias dcd='docker-compose down'
alias dcps='docker-compose ps'
alias dclogs='docker-compose logs'
alias dcrestart='docker-compose restart'
#!/bin/sh
# Execute as root!
# To use it, pipe sh it!
# wget -O - https://gist.githubusercontent.com/federicociro/3b0792254aa7f08cb6931766573055c9/raw/442a1d341378e1f7f46958b0abb742c5a098d601/fresh-lxc.sh | sh
SSH_KEYS="https://github.com/federicociro.keys"
AUTHORIZED_KEYS="/root/.ssh/authorized_keys"
BASHRC_URL="https://gist.githubusercontent.com/federicociro/3b0792254aa7f08cb6931766573055c9/raw/d5e08b99cb264b2251bc16fa1bf1c54a2d7646d2/rc"
BASH_ALIASES_URL="https://gist.githubusercontent.com/federicociro/3b0792254aa7f08cb6931766573055c9/raw/d5e08b99cb264b2251bc16fa1bf1c54a2d7646d2/alias"
# Detect Operating System
OS=$(awk -F= '/^ID=/{print $2}' /etc/os-release)
update_and_install_packages() {
if [ "$OS" = '"debian"' ]; then
apt update
apt -y upgrade
apt -y install curl
elif [ "$OS" = '"alpine"' ]; then
apk update
apk upgrade
apk add curl openssh
rc-update add sshd
service sshd start
else
echo "Unsupported operating system."
exit 1
fi
}
# Update and upgrade the system and install packages
update_and_install_packages
# Check and create ~/.ssh directory if it doesn't exist
mkdir -p /root/.ssh
# 1. Download SSH public keys and copy to .ssh/authorized_keys
curl -s $SSH_KEYS >> /tmp/new_keys
# Check if the keys are not already in authorized_keys and append them
while read -r key; do
if ! grep -qF "$key" "$AUTHORIZED_KEYS"; then
echo "$key" >> "$AUTHORIZED_KEYS"
fi
done < /tmp/new_keys
chmod 600 /root/.ssh/authorized_keys
# Clean up temporary file
rm /tmp/new_keys
# 2. Add alias sourcing to .bashrc
wget -O - $BASHRC_URL >> /root/.bashrc
# 3. Add common aliases to .bash_aliases
wget -O - $BASH_ALIASES_URL >> /root/.bash_aliases
# 4. Source .bashrc to see changes immediately.
echo "Run 'source ~/.bashrc' manually to source the changes."
echo ""
echo "SSH keys added and aliases updated. Please source your .bash_aliases or restart your session."
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment