From f762850bbfe329f474c034160bae839f124dcfbf Mon Sep 17 00:00:00 2001 From: jugeeya Date: Wed, 1 Feb 2023 11:27:28 -0800 Subject: [PATCH] Cleanup Devcontainer Specification (#465) * Update devcontainer.json * Delete .devcontainer/library-scripts directory * Delete full_build.sh * Update README.md --- .devcontainer/devcontainer.json | 15 +- .../library-scripts/common-debian.sh | 195 ------------------ .../library-scripts/docker-debian.sh | 153 -------------- README.md | 2 +- full_build.sh | 40 ---- 5 files changed, 4 insertions(+), 401 deletions(-) delete mode 100644 .devcontainer/library-scripts/common-debian.sh delete mode 100644 .devcontainer/library-scripts/docker-debian.sh delete mode 100644 full_build.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2a653ea..4bf91a6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -14,20 +14,11 @@ "customizations": { "vscode": { "extensions": [ - "matklad.rust-analyzer", + "rust-lang.rust-analyzer", "bungcip.better-toml", "serayuzgur.crates", "statiolake.vscode-rustfmt" ] } - }, - - // // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "ms-azuretools.vscode-docker", - "matklad.rust-analyzer", - "bungcip.better-toml", - "serayuzgur.crates", - "statiolake.vscode-rustfmt" - ] -} \ No newline at end of file + } +} diff --git a/.devcontainer/library-scripts/common-debian.sh b/.devcontainer/library-scripts/common-debian.sh deleted file mode 100644 index a94a5fe..0000000 --- a/.devcontainer/library-scripts/common-debian.sh +++ /dev/null @@ -1,195 +0,0 @@ -#!/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] [upgrade packages flag] - -INSTALL_ZSH=${1:-"true"} -USERNAME=${2:-"vscode"} -USER_UID=${3:-1000} -USER_GID=${4:-1000} -UPGRADE_PACKAGES=${5:-"true"} - -set -e - -if [ "$(id -u)" -ne 0 ]; then - echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' - exit 1 -fi - -# Treat a user name of "none" as root -if [ "${USERNAME}" = "none" ] || [ "${USERNAME}" = "root" ]; then - USERNAME=root - USER_UID=0 - USER_GID=0 -fi - -# Load markers to see which steps have already run -MARKER_FILE="/usr/local/etc/vscode-dev-containers/common" -if [ -f "${MARKER_FILE}" ]; then - echo "Marker file found:" - cat "${MARKER_FILE}" - source "${MARKER_FILE}" -fi - -# Ensure apt is in non-interactive to avoid prompts -export DEBIAN_FRONTEND=noninteractive - -# Function to call apt-get if needed -apt-get-update-if-needed() -{ - if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then - echo "Running apt-get update..." - apt-get update - else - echo "Skipping apt-get update." - fi -} - -# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies -if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then - apt-get-update-if-needed - - PACKAGE_LIST="apt-utils \ - git \ - openssh-client \ - gnupg2 \ - iproute2 \ - procps \ - lsof \ - htop \ - net-tools \ - psmisc \ - curl \ - wget \ - rsync \ - ca-certificates \ - unzip \ - zip \ - nano \ - vim-tiny \ - less \ - jq \ - lsb-release \ - apt-transport-https \ - dialog \ - libc6 \ - libgcc1 \ - libgssapi-krb5-2 \ - libicu[0-9][0-9] \ - liblttng-ust0 \ - libstdc++6 \ - zlib1g \ - locales \ - sudo \ - ncdu \ - man-db" - - # Install libssl1.1 if available - if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then - PACKAGE_LIST="${PACKAGE_LIST} 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 - PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.2" - elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then - # Ubuntu 18.04, 16.04, earlier - PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.0" - fi - fi - - echo "Packages to verify are installed: ${PACKAGE_LIST}" - apt-get -y install --no-install-recommends ${PACKAGE_LIST} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 ) - - PACKAGES_ALREADY_INSTALLED="true" -fi - -# Get to latest versions of all packages -if [ "${UPGRADE_PACKAGES}" = "true" ]; then - apt-get-update-if-needed - apt-get -y upgrade --no-install-recommends - apt-get autoremove -y -fi - -# Ensure at least the en_US.UTF-8 UTF-8 locale is available. -# Common need for both applications and things like the agnoster ZSH theme. -if [ "${LOCALE_ALREADY_SET}" != "true" ]; then - echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen - locale-gen - LOCALE_ALREADY_SET="true" -fi - -# Create or update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user. -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 -if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then - echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME - chmod 0440 /etc/sudoers.d/$USERNAME - EXISTING_NON_ROOT_USER="${USERNAME}" -fi - -# .bashrc/.zshrc snippet -RC_SNIPPET="$(cat << EOF -export USER=\$(whoami) - -export PATH=\$PATH:\$HOME/.local/bin - -if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then - alias code=code-insiders -fi -EOF -)" - -# Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later) -if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then - echo "${RC_SNIPPET}" >> /etc/bash.bashrc - RC_SNIPPET_ALREADY_ADDED="true" -fi - -# Optionally install and configure zsh -if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then - apt-get-update-if-needed - apt-get install -y zsh - curl -fsSLo- https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash 2>&1 - echo "${RC_SNIPPET}" >> /etc/zsh/zshrc - echo -e "DEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc - cp -fR /root/.oh-my-zsh /etc/skel - cp -f /root/.zshrc /etc/skel - sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc - if [ "${USERNAME}" != "root" ]; then - cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME - chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc - fi - ZSH_ALREADY_INSTALLED="true" -fi - -# Write marker file -mkdir -p "$(dirname "${MARKER_FILE}")" -echo -e "\ - PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\ - LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ - EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ - RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ - ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" - -echo "Done!" \ No newline at end of file diff --git a/.devcontainer/library-scripts/docker-debian.sh b/.devcontainer/library-scripts/docker-debian.sh deleted file mode 100644 index e711dbd..0000000 --- a/.devcontainer/library-scripts/docker-debian.sh +++ /dev/null @@ -1,153 +0,0 @@ -#!/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: ./docker-debian.sh [enable non-root docker socket access flag] [source socket] [target socket] [non-root user] - -ENABLE_NONROOT_DOCKER=${1:-"true"} -SOURCE_SOCKET=${2:-"/var/run/docker-host.sock"} -TARGET_SOCKET=${3:-"/var/run/docker.sock"} -USERNAME=${4:-"vscode"} - -set -e - -if [ "$(id -u)" -ne 0 ]; then - echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' - exit 1 -fi - -# Function to run apt-get if needed -apt-get-update-if-needed() -{ - if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then - echo "Running apt-get update..." - apt-get update - else - echo "Skipping apt-get update." - fi -} - -# Ensure apt is in non-interactive to avoid prompts -export DEBIAN_FRONTEND=noninteractive - -# Install apt-transport-https, curl, lsb-release, gpg if missing -if ! dpkg -s apt-transport-https curl ca-certificates lsb-release > /dev/null 2>&1 || ! type gpg > /dev/null 2>&1; then - apt-get-update-if-needed - apt-get -y install --no-install-recommends apt-transport-https curl ca-certificates lsb-release gnupg2 -fi - -# Install Docker CLI if not already installed -if type docker > /dev/null 2>&1; then - echo "Docker CLI already installed." -else - curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT) - echo "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list - apt-get update - apt-get -y install --no-install-recommends docker-ce-cli -fi - -# Install Docker Compose if not already installed -if type docker-compose > /dev/null 2>&1; then - echo "Docker Compose already installed." -else - - LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/compose/releases/latest" | grep -o -P '(?<="tag_name": ").+(?=")') - curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose - chmod +x /usr/local/bin/docker-compose -fi - -# If init file already exists, exit -if [ -f "/usr/local/share/docker-init.sh" ]; then - exit 0 -fi - -# By default, make the source and target sockets the same -if [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ]; then - touch "${SOURCE_SOCKET}" - ln -s "${SOURCE_SOCKET}" "${TARGET_SOCKET}" -fi - -# Add a stub if not adding non-root user access, user is root, or the specified user does not exist -if [ "${ENABLE_NONROOT_DOCKER}" = "false" ] || [ "${USERNAME}" = "root" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then - echo '/usr/bin/env bash -c "\$@"' > /usr/local/share/docker-init.sh - chmod +x /usr/local/share/docker-init.sh - exit 0 -fi - -# If enabling non-root access and specified user is found, setup socat and add script -chown -h "${USERNAME}":root "${TARGET_SOCKET}" -if ! dpkg -s socat > /dev/null 2>&1; then - apt-get-update-if-needed - apt-get -y install socat -fi -tee /usr/local/share/docker-init.sh > /dev/null \ -<< EOF -#!/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. -#------------------------------------------------------------------------------------------------------------- - -set -e - -SOCAT_PATH_BASE=/tmp/vscr-dind-socat -SOCAT_LOG=\${SOCAT_PATH_BASE}.log -SOCAT_PID=\${SOCAT_PATH_BASE}.pid - -# Wrapper function to only use sudo if not already root -sudoIf() -{ - if [ "\$(id -u)" -ne 0 ]; then - sudo "\$@" - else - "\$@" - fi -} - -# Log messages -log() -{ - echo -e "[\$(date)] \$@" | sudoIf tee -a \${SOCAT_LOG} > /dev/null -} - -echo -e "\n** \$(date) **" | sudoIf tee -a \${SOCAT_LOG} > /dev/null -log "Ensuring ${USERNAME} has access to ${SOURCE_SOCKET} via ${TARGET_SOCKET}" - -# If enabled, try to add a docker group with the right GID. If the group is root, -# fall back on using socat to forward the docker socket to another unix socket so -# that we can set permissions on it without affecting the host. -if [ "${ENABLE_NONROOT_DOCKER}" = "true" ] && [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ] && [ "${USERNAME}" != "root" ] && [ "${USERNAME}" != "0" ]; then - SOCKET_GID=\$(stat -c '%g' ${SOURCE_SOCKET}) - if [ "\${SOCKET_GID}" != "0" ]; then - log "Adding user to group with GID \${SOCKET_GID}." - if [ "\$(cat /etc/group | grep :\${SOCKET_GID}:)" = "" ]; then - sudoIf groupadd --gid \${SOCKET_GID} docker-host - fi - # Add user to group if not already in it - if [ "\$(id ${USERNAME} | grep -E 'groups=.+\${SOCKET_GID}\(')" = "" ]; then - sudoIf usermod -aG \${SOCKET_GID} ${USERNAME} - fi - else - # Enable proxy if not already running - if [ ! -f "\${SOCAT_PID}" ] || ! ps -p \$(cat \${SOCAT_PID}) > /dev/null; then - log "Enabling socket proxy." - log "Proxying ${SOURCE_SOCKET} to ${TARGET_SOCKET} for vscode" - sudoIf rm -rf ${TARGET_SOCKET} - (sudoIf socat UNIX-LISTEN:${TARGET_SOCKET},fork,mode=660,user=${USERNAME} UNIX-CONNECT:${SOURCE_SOCKET} 2>&1 | sudoIf tee -a \${SOCAT_LOG} > /dev/null & echo "\$!" | sudoIf tee \${SOCAT_PID} > /dev/null) - else - log "Socket proxy already running." - fi - fi - log "Success" -fi - -# Execute whatever commands were passed in (if any). This allows us -# to set this script to ENTRYPOINT while still executing the default CMD. -set +e -exec "\$@" -EOF -chmod +x /usr/local/share/docker-init.sh -chown ${USERNAME}:root /usr/local/share/docker-init.sh -echo "Done!" \ No newline at end of file diff --git a/README.md b/README.md index 26e2b34..1dabd56 100644 --- a/README.md +++ b/README.md @@ -392,7 +392,7 @@ If you'd like to build the modpack starting from the source code, you can build cargo skyline build --release ``` -To build the entire modpack including supporting files, use the steps in [`full_build.sh`](full_build.sh) or in the [Github Actions specification file](https://github.com/jugeeya/UltimateTrainingModpack/blob/master/.github/workflows/rust.yml). +To build the entire modpack including supporting files, use the steps in the [Github Actions specification file](https://github.com/jugeeya/UltimateTrainingModpack/blob/main/.github/workflows/rust.yml). ## Prerequisites - Stable Rust environment with [cargo-skyline](https://github.com/jam1garner/cargo-skyline) diff --git a/full_build.sh b/full_build.sh deleted file mode 100644 index 7815b00..0000000 --- a/full_build.sh +++ /dev/null @@ -1,40 +0,0 @@ -# Clone the repository -git clone --recursive - -# Build the training modpack Skyline Plugin -# The resulting build is found in target/aarch64-skyline-switch/release/libtraining_modpack.nro -cargo skyline build --release - -# Make directories -rm -r release -mkdir -p release -mkdir -p release/atmosphere/contents/01006A800016E000 -mkdir -p release/atmosphere/contents/01006A800016E000/romfs/skyline/plugins -mkdir -p release/atmosphere/contents/01006A800016E000/manual_html/html-document/contents.htdocs - -# Download additional files -## Skyline -wget https://github.com/skyline-dev/skyline/releases/download/beta/skyline.zip -unzip skyline.zip -rm skyline.zip -## Params-hook plugin -wget https://github.com/ultimate-research/params-hook-plugin/releases/download/v0.1.1/libparam_hook.nro -## NRO hook plugin -wget https://github.com/ultimate-research/nro-hook-plugin/releases/download/v0.1.1/libnro_hook.nro -## NN HID hook plugin -wget https://github.com/jugeeya/nn-hid-hook/releases/download/beta/libnn_hid_hook.nro -## Smash visualizer plugin -wget https://github.com/blu-dev/smash-visualizer/releases/download/0.1.0/Smash-Visualizer-0.1.0.zip -unzip -o Smash-Visualizer-0.1.0.zip -rm Smash-Visualizer-0.1.0.zip - -# Move files to release -mv atmosphere/contents/01006A800016E000/romfs/skyline/plugins release/atmosphere/contents/01006A800016E000/romfs/skyline -rm -r atmosphere -rm -r exefs -mv libparam_hook.nro release/atmosphere/contents/01006A800016E000/romfs/skyline/plugins/libparam_hook.nro -mv libnro_hook.nro release/atmosphere/contents/01006A800016E000/romfs/skyline/plugins/libnro_hook.nro -mv libnn_hid_hook.nro release/atmosphere/contents/01006A800016E000/romfs/skyline/plugins/libnn_hid_hook.nro -cp target/aarch64-skyline-switch/release/libtraining_modpack.nro release/atmosphere/contents/01006A800016E000/romfs/skyline/plugins/libtraining_modpack.nro -ls -1 src/templates | xargs -n 1 basename | xargs -L1 -I{} cp src/templates/{} release/atmosphere/contents/01006A800016E000/manual_html/html-document/contents.htdocs/{} -mv colors.json release/colors.json \ No newline at end of file