Last active
April 3, 2025 19:15
-
-
Save KROSF/769bc854c00f0f16613f2a901f66e2c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- common-debian.sh 2020-04-16 13:47:08.000000000 +0200 | |
+++ common.sh 2020-04-16 13:57:17.000000000 +0200 | |
@@ -99,11 +99,15 @@ | |
# Optionally install and configure zsh | |
if [ "$INSTALL_ZSH" = "true" ]; then | |
apt-get install -y zsh | |
- sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | |
+ curl -fsSL https://starship.rs/install.sh | bash | |
+ curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh | |
echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.zshrc | |
- cp -R /root/.oh-my-zsh /home/$USERNAME | |
+ echo 'eval "$(starship init zsh)' | tee -a /root/.zshrc | |
+ cp -R /root/.zim /home/$USERNAME | |
cp /root/.zshrc /home/$USERNAME | |
- sed -i -e "s/\/root\/.oh-my-zsh/\/home\/$USERNAME\/.oh-my-zsh/g" /home/$USERNAME/.zshrc | |
- chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc | |
+ cp /root/.zshenv /home/$USERNAME | |
+ cp /root/.zshlogin /home/$USERNAME | |
+ cp /root/.zimrc /home/$USERNAME | |
+ chown -R $USER_UID:$USER_GID /home/$USERNAME/.zim /home/$USERNAME/.zshrc /home/$USERNAME/.zshenv /home/$USERNAME/.zshlogin /home/$USERNAME/.zimrc | |
fi | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#------------------------------------------------------------------------------------------------------------- | |
# Copyright (c) Microsoft Corporation. All rights reserved. | |
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | |
#------------------------------------------------------------------------------------------------------------- | |
# Syntax: ./common-debian.sh <install zsh flag> <username> <user UID> <user GID> | |
INSTALL_ZSH=$1 | |
USERNAME=$2 | |
USER_UID=$3 | |
USER_GID=$4 | |
set -e | |
if [ "$(id -u)" -ne 0 ]; then | |
echo 'Script must be run a root. Use sudo or set "USER root" before running the script.' | |
exit 1 | |
fi | |
# Get to latest versions of all packages | |
apt-get -y upgrade | |
# Install common dependencies | |
apt-get -y install --no-install-recommends \ | |
git \ | |
openssh-client \ | |
less \ | |
iproute2 \ | |
procps \ | |
curl \ | |
wget \ | |
unzip \ | |
lsb-release \ | |
ca-certificates \ | |
apt-transport-https \ | |
libc6 \ | |
libgcc1 \ | |
libgssapi-krb5-2 \ | |
libicu[0-9][0-9] \ | |
liblttng-ust0 \ | |
libstdc++6 \ | |
zlib1g | |
# Install libssl1.1 if available | |
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then | |
apt-get -y install --no-install-recommends libssl1.1 | |
fi | |
# Install appropriate version of libssl1.0.x if available | |
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') | |
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then | |
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then | |
# Debian 9 | |
apt-get -y install --no-install-recommends libssl1.0.2 | |
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then | |
# Ubuntu 18.04, 16.04, earlier | |
apt-get -y install --no-install-recommends libssl1.0.0 | |
fi | |
fi | |
# Create or update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user. | |
if [ "$USER_UID" = "" ]; then | |
USER_UID=1000 | |
fi | |
if [ "$USER_GID" = "" ]; then | |
USER_GID=1000 | |
fi | |
if [ "$USERNAME" = "" ]; then | |
USERNAME=$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd) | |
fi | |
if id -u $USERNAME > /dev/null 2>&1; then | |
# User exists, update if needed | |
if [ "$USER_GID" != "$(id -G $USERNAME)" ]; then | |
groupmod --gid $USER_GID $USERNAME | |
usermod --gid $USER_GID $USERNAME | |
fi | |
if [ "$USER_UID" != "$(id -u $USERNAME)" ]; then | |
usermod --uid $USER_UID $USERNAME | |
fi | |
else | |
# Create user | |
groupadd --gid $USER_GID $USERNAME | |
useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME | |
fi | |
# Add add sudo support for non-root user | |
apt-get install -y sudo | |
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME | |
chmod 0440 /etc/sudoers.d/$USERNAME | |
# Ensure ~/.local/bin is in the PATH for root and non-root users for bash | |
echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.bashrc >> /home/$USERNAME/.bashrc | |
chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc | |
# Optionally install and configure zsh | |
if [ "$INSTALL_ZSH" = "true" ]; then | |
apt-get install -y zsh | |
curl -fsSL https://starship.rs/install.sh | bash -s -- --yes | |
curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh | |
echo "export PATH=\$PATH:\$HOME/.local/bin" | tee -a /root/.zshrc | |
echo 'eval "$(starship init zsh)"' | tee -a /root/.zshrc | |
cp -R /root/.zim /home/$USERNAME | |
cp /root/.zshrc /home/$USERNAME | |
cp /root/.zshenv /home/$USERNAME | |
cp /root/.zlogin /home/$USERNAME | |
cp /root/.zimrc /home/$USERNAME | |
sed -i -e "s/root/home\/$USERNAME/g" /home/$USERNAME/.zim/init.zsh | |
chown -R $USER_UID:$USER_GID /home/$USERNAME/.zim /home/$USERNAME/.zshrc /home/$USERNAME/.zshenv /home/$USERNAME/.zlogin /home/$USERNAME/.zimrc | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment