diff --git a/README.md b/README.md new file mode 100644 index 0000000..96e74e9 --- /dev/null +++ b/README.md @@ -0,0 +1,280 @@ +# Community Hass.io Add-ons: Visual Studio Code + +[![GitHub Release][releases-shield]][releases] +![Project Stage][project-stage-shield] +[![License][license-shield]](LICENSE.md) + +![Supports aarch64 Architecture][aarch64-shield] +![Supports amd64 Architecture][amd64-shield] +![Supports armhf Architecture][armhf-shield] +![Supports armv7 Architecture][armv7-shield] +![Supports i386 Architecture][i386-shield] + +[![GitLab CI][gitlabci-shield]][gitlabci] +![Project Maintenance][maintenance-shield] +[![GitHub Activity][commits-shield]][commits] + +[![Discord][discord-shield]][discord] +[![Community Forum][forum-shield]][forum] + +[![Buy me a coffee][buymeacoffee-shield]][buymeacoffee] + +[![Support my work on Patreon][patreon-shield]][patreon] + +Visual Studio Code, accessible through the browser. + +## About + +This add-on runs Visual Studio Code, allowing you to edit your Home Assistant +configuration straight from the web browser and can be embeded straight +into the Home Assistant frontend UI. + +Visual Studio Code runs as a remote server using `code-server`, and is a +fully fletched VSCode experience. + +The add-on has the Home Assistant and MDI icons extensions pre-installed +and pre-configured right out of the box. This mean that auto completion works +instantly, without the need for configuring anything. + +![Visual Studio Code in the Home Assistant Frontend](images/screenshot.png) + +## Installation + +The installation of this add-on is pretty straightforward and not different in +comparison to installing any other Hass.io add-on. + +1. [Add our Hass.io add-ons repository][repository] to your Hass.io instance. +1. Install the "Visual Studio Code" add-on. +1. Configure a "password". +1. Start the "Visual Studio Code" add-on. +1. Check the logs of the "Visual Studio Code" add-on to see if everything went + well. + +**NOTE**: Do not add this repository to Hass.io, please use: +`https://github.com/hassio-addons/repository`. + +## Configuration + +**Note**: _Remember to restart the add-on when the configuration is changed._ + +Example add-on configuration: + +```json +{ + "log_level": "info", + "password": "ChooChooHomie", + "ssl": false, + "certfile": "fullchain.pem", + "keyfile": "privkey.pem", + "packages": [ + "mariadb-client" + ], + "init_commands": [ + "pip3 install yamllint" + ] +} +``` + +**Note**: _This is just an example, don't copy and past it! Create your own!_ + +### Option: `log_level` + +The `log_level` option controls the level of log output by the addon and can +be changed to be more or less verbose, which might be useful when you are +dealing with an unknown issue. Possible values are: + +- `trace`: Show every detail, like all called internal functions. +- `debug`: Shows detailed debug information. +- `info`: Normal (usually) interesting events. +- `warning`: Exceptional occurrences that are not errors. +- `error`: Runtime errors that do not require immediate action. +- `fatal`: Something went terribly wrong. Add-on becomes unusable. + +Please note that each level automatically includes log messages from a +more severe level, e.g., `debug` also shows `info` messages. By default, +the `log_level` is set to `info`, which is the recommended setting unless +you are troubleshooting. + +### Option: `password` + +Password needed to login into the Visual Studio Code. + +**Note**: _This option support secrets, e.g., `!secret vscode_password`._ + +### Option: `ssl` + +Enables/Disables SSL (HTTPS). Set it `true` to enable it, `false` otherwise. + +### Option: `certfile` + +The certificate file to use for SSL. + +**Note**: _The file MUST be stored in `/ssl/`, which is default for Hass.io_ + +### Option: `keyfile` + +The private key file to use for SSL. + +**Note**: _The file MUST be stored in `/ssl/`, which is default for Hass.io_ + +### Option: `packages` + +Allows you to specify additional [Ubuntu packages][ubuntu-packages] to be +installed in your shell environment (e.g., Python, PHP, Go). + +**Note**: _Adding many packages will result in a longer start-up +time for the add-on._ + +### Option: `init_commands` + +Customize your IDE environment even more with the `init_commands` option. +Add one or more shell commands to the list, and they will be executed every +single time this add-on starts. + +### Option: `leave_front_door_open` + +Adding this option to the add-on configuration allows you to disable +authentication on the IDE by setting it to `true`. + +**Note**: _We STRONGLY suggest, not to use this, even if this add-on is +only exposed to your internal network. USE AT YOUR OWN RISK!_ + +#### Option: `i_like_to_be_pwned` + +Adding this option to the add-on configuration allows to you bypass the +HaveIBeenPwned password requirement by setting it to `true`. + +**Note**: _We STRONGLY suggest picking a stronger/safer password instead of +using this option! USE AT YOUR OWN RISK!_ + +## Embedding into Home Assistant + +It is possible to embed the IDE directly into Home Assistant, allowing +you to access your IDE through the Home Assistant frontend. + +Home Assistant provides the `panel_iframe` component, for these purposes. + +Example configuration: + +```yaml +panel_iframe: + vscode: + title: Visual Studio Code + icon: mdi:visual-studio-code + url: https://addres.to.your.hass.io:1337 +``` + +## Known issues and limitations + +- This add-on currently only supports AMD64 machines, we hope to be able + to ship other architectures soon! + +## Changelog & Releases + +This repository keeps a change log using [GitHub's releases][releases] +functionality. The format of the log is based on +[Keep a Changelog][keepchangelog]. + +Releases are based on [Semantic Versioning][semver], and use the format +of ``MAJOR.MINOR.PATCH``. In a nutshell, the version will be incremented +based on the following: + +- ``MAJOR``: Incompatible or major changes. +- ``MINOR``: Backwards-compatible new features and enhancements. +- ``PATCH``: Backwards-compatible bugfixes and package updates. + +## Support + +Got questions? + +You have several options to get them answered: + +- The [Community Hass.io Add-ons Discord chat server][discord] for add-on + support and feature requests. +- The [Home Assistant Discord chat server][discord-ha] for general Home + Assistant discussions and questions. +- The Home Assistant [Community Forum][forum]. +- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit] + +You could also [open an issue here][issue] GitHub. + +## Contributing + +This is an active open-source project. We are always open to people who want to +use the code or contribute to it. + +We have set up a separate document containing our +[contribution guidelines](CONTRIBUTING.md). + +Thank you for being involved! :heart_eyes: + +## Authors & contributors + +The original setup of this repository is by [Franck Nijhof][frenck]. + +For a full list of all authors and contributors, +check [the contributor's page][contributors]. + +## We have got some Hass.io add-ons for you + +Want some more functionality to your Hass.io Home Assistant instance? + +We have created multiple add-ons for Hass.io. For a full list, check out +our [GitHub Repository][repository]. + +## License + +MIT License + +Copyright (c) 2019 Franck Nijhof + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +[aarch64-shield]: https://img.shields.io/badge/aarch64-no-red.svg +[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg +[armhf-shield]: https://img.shields.io/badge/armhf-no-red.svg +[armv7-shield]: https://img.shields.io/badge/armv7-no-red.svg +[buymeacoffee-shield]: https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg +[buymeacoffee]: https://www.buymeacoffee.com/frenck +[commits-shield]: https://img.shields.io/github/commit-activity/y/hassio-addons/addon-vscode.svg +[commits]: https://github.com/hassio-addons/addon-vscode/commits/master +[contributors]: https://github.com/hassio-addons/addon-vscode/graphs/contributors +[discord-ha]: https://discord.gg/c5DvZ4e +[discord-shield]: https://img.shields.io/discord/478094546522079232.svg +[discord]: https://discord.me/hassioaddons +[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg +[forum]: https://community.home-assistant.io/?u=frenck +[frenck]: https://github.com/frenck +[gitlabci-shield]: https://gitlab.com/hassio-addons/addon-vscode/badges/master/pipeline.svg +[gitlabci]: https://gitlab.com/hassio-addons/addon-vscode/pipelines +[home-assistant]: https://home-assistant.io +[i386-shield]: https://img.shields.io/badge/i386-no-red.svg +[issue]: https://github.com/hassio-addons/addon-vscode/issues +[keepchangelog]: http://keepachangelog.com/en/1.0.0/ +[license-shield]: https://img.shields.io/github/license/hassio-addons/addon-vscode.svg +[maintenance-shield]: https://img.shields.io/maintenance/yes/2019.svg +[patreon-shield]: https://www.frenck.nl/images/patreon.png +[patreon]: https://www.patreon.com/frenck +[project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg +[reddit]: https://reddit.com/r/homeassistant +[releases-shield]: https://img.shields.io/github/release/hassio-addons/addon-vscode.svg +[releases]: https://github.com/hassio-addons/addon-vscode/releases +[repository]: https://github.com/hassio-addons/repository +[semver]: http://semver.org/spec/v2.0.0.htm +[ubuntu-packages]: https://packages.ubuntu.com diff --git a/images/screenshot.png b/images/screenshot.png new file mode 100644 index 0000000..cf4dbc7 Binary files /dev/null and b/images/screenshot.png differ diff --git a/vscode/.README.j2 b/vscode/.README.j2 new file mode 100644 index 0000000..f99b6b4 --- /dev/null +++ b/vscode/.README.j2 @@ -0,0 +1,82 @@ +# Community Hass.io Add-ons: Visual Studio Code + +[![Release][release-shield]][release] ![Project Stage][project-stage-shield] ![Project Maintenance][maintenance-shield] + +[![Discord][discord-shield]][discord] [![Community Forum][forum-shield]][forum] + +[![Buy me a coffee][buymeacoffee-shield]][buymeacoffee] + +[![Support my work on Patreon][patreon-shield]][patreon] + +Visual Studio Code, accessible through the browser. + +## About + +This add-on runs Visual Studio Code, allowing you to edit your Home Assistant +configuration straight from the web browser and can be embeded straight +into the Home Assistant frontend UI. + +Visual Studio Code runs as a remote server using `code-server`, and is a +fully fletched VSCode experience. + +The add-on has the Home Assistant and MDI icons extensions pre-installed +and pre-configured right out of the box. This mean that auto completion works +instantly, without the need for configuring anything. + +[Click here for the full documentation][docs] + +![Visual Studio Code in the Home Assistant Frontend][screenshot] + +{% if channel == "edge" %} +## WARNING! THIS IS AN EDGE VERSION! + +This Hass.io Add-ons repository contains edge builds of add-ons. Edge builds +add-ons are based upon the latest development version. + +- They may not work at all. +- They might stop working at any time. +- They could have a negative impact on your system. + +This repository was created for: + +- Anybody willing to test. +- Anybody interested in trying out upcoming add-ons or add-on features. +- Developers. + +If you are more interested in stable releases of our add-ons: + + + +{% endif %} +{% if channel == "beta" %} +## WARNING! THIS IS A BETA VERSION! + +This Hass.io Add-ons repository contains beta releases of add-ons. + +- They might stop working at any time. +- They could have a negative impact on your system. + +This repository was created for: + +- Anybody willing to test. +- Anybody interested in trying out upcoming add-ons or add-on features. + +If you are more interested in stable releases of our add-ons: + + + +{% endif %} +[buymeacoffee-shield]: https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg +[buymeacoffee]: https://www.buymeacoffee.com/frenck +[discord-shield]: https://img.shields.io/discord/478094546522079232.svg +[discord]: https://discord.me/hassioaddons +[docs]: {{ repo }}/blob/{{ version }}/README.md +[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg +[forum]: https://community.home-assistant.io/?u=frenck +[maintenance-shield]: https://img.shields.io/maintenance/yes/2019.svg +[patreon-shield]: https://www.frenck.nl/images/patreon.png +[patreon]: https://www.patreon.com/frenck +[project-stage-shield]: https://img.shields.io/badge/project%20stage-experimental-yellow.svg +[release-shield]: https://img.shields.io/badge/version-{{ version }}-blue.svg +[release]: {{ repo }}/tree/{{ version }} +[screenshot]: {{ repo }}/raw/master/images/screenshot.png diff --git a/vscode/Dockerfile b/vscode/Dockerfile new file mode 100755 index 0000000..ef96e3a --- /dev/null +++ b/vscode/Dockerfile @@ -0,0 +1,144 @@ +ARG BUILD_FROM=hassioaddons/ubuntu-base:3.0.0 +############################################################################### +# Get the original code-server container. +############################################################################### +FROM codercom/code-server as codeserver + +############################################################################### +# Build container to get custom vscode extensions. +############################################################################### +FROM ${BUILD_FROM} as vscode + +# Copy in extensions list +COPY vscode.extensions /root/vscode.extensions + +# Install the actual VSCode to download configs and extensions +RUN \ + apt-get update \ + \ + && apt-get install -y --no-install-recommends \ + libx11-xcb1 \ + libasound2 \ + \ + && curl \ + -o vscode-amd64.deb \ + -L https://vscode-update.azurewebsites.net/latest/linux-deb-x64/stable \ + \ + && dpkg -i vscode-amd64.deb || true \ + && apt-get install -y -f \ + && rm -f vscode-amd64.deb \ + \ + && code -v --user-data-dir /root/.config/Code + +RUN \ + while read -r ext; do \ + echo "Installing vscode extension: $ext"; \ + code --user-data-dir /root/.config/Code --install-extension $ext; \ + done < /root/vscode.extensions \ + && ls -la /root/.vscode/extensions + +############################################################################### +# Build the actual add-on. +############################################################################### +# hadolint ignore=DL3006 +FROM ${BUILD_FROM} + +# Confiure locale +ENV LANG=en_US.UTF-8 + +# Set shell +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +# Copy Python requirements file +COPY requirements.txt /tmp/requirements.txt + +# Setup base system +ARG BUILD_ARCH +RUN \ + apt-get update \ + \ + && apt-get install -y --no-install-recommends \ + build-essential=12.4ubuntu1 \ + colordiff=1.0.18-1 \ + git=1:2.17.1-1ubuntu0.4 \ + locales=2.27-3ubuntu1 \ + mosquitto-clients=1.4.15-2ubuntu0.18.04.2 \ + net-tools=1.60+git20161116.90da8a0-1ubuntu1 \ + nmap=7.60-1ubuntu5 \ + openssh-client=1:7.6p1-4ubuntu0.3 \ + openssl=1.1.0g-2ubuntu4.3 \ + python3=3.6.7-1~18.04 \ + python3-dev=3.6.7-1~18.04 \ + wget=1.19.4-1ubuntu2.1 \ + zsh=5.4.2-3ubuntu3.1 \ + \ + && curl https://bootstrap.pypa.io/get-pip.py | python3 \ + \ + && locale-gen en_US.UTF-8 \ + \ + && curl -L -s -o /usr/bin/hassio \ + "https://github.com/home-assistant/hassio-cli/releases/download/2.1.0/hassio_${BUILD_ARCH}" \ + && chmod a+x /usr/bin/hassio \ + \ + && git clone --branch master --single-branch --depth 1 \ + "git://github.com/robbyrussell/oh-my-zsh.git" ~/.oh-my-zsh \ + \ + && git clone --branch master --single-branch --depth 1 \ + "git://github.com/zsh-users/zsh-autosuggestions" \ + ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions \ + && git clone --branch master --single-branch --depth 1 \ + "git://github.com/zsh-users/zsh-syntax-highlighting.git" \ + ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \ + \ + && sed -i -e "s#bin/bash#bin/zsh#" /etc/passwd \ + \ + && update-alternatives \ + --install /usr/bin/python python /usr/bin/python3 10 \ + \ + && pip3 install --no-cache-dir -r /tmp/requirements.txt \ + \ + && apt-get purge -y --auto-remove \ + python3-dev \ + build-essential \ + \ + && find /usr/local/lib/python3.6/ -type d -name tests -depth -exec rm -rf {} \; \ + && find /usr/local/lib/python3.6/ -type d -name test -depth -exec rm -rf {} \; \ + && find /usr/local/lib/python3.6/ -name __pycache__ -depth -exec rm -rf {} \; \ + && find /usr/local/lib/python3.6/ -name "*.pyc" -depth -exec rm -f {} \; \ + \ + && rm -fr \ + /tmp/* \ + /var/{cache,log}/* \ + /var/lib/apt/lists/* + +# Copy root filesystem +COPY rootfs / + +# Get the code server binary +COPY --from=codeserver /usr/local/bin/code-server /usr/local/bin/code-server + +# Get the custom extensions +COPY --from=vscode /root/.vscode/extensions /root/.code-server/extensions + +# Build arguments +ARG BUILD_DATE +ARG BUILD_REF +ARG BUILD_VERSION + +# Labels +LABEL \ + io.hass.name="Visual Studio Code" \ + io.hass.description="Visual Studio Code, accessible through the browser." \ + io.hass.arch="${BUILD_ARCH}" \ + io.hass.type="addon" \ + io.hass.version=${BUILD_VERSION} \ + maintainer="Franck Nijhof " \ + org.label-schema.description="Visual Studio Code, accessible through the browser." \ + org.label-schema.build-date=${BUILD_DATE} \ + org.label-schema.name="Visual Studio Code" \ + org.label-schema.schema-version="1.0" \ + org.label-schema.url="https://community.home-assistant.io/?u=frenck" \ + org.label-schema.usage="https://github.com/hassio-addons/addon-vscode/tree/master/README.md" \ + org.label-schema.vcs-ref=${BUILD_REF} \ + org.label-schema.vcs-url="https://github.com/hassio-addons/addon-vscode" \ + org.label-schema.vendor="Community Hass.io Add-ons" diff --git a/vscode/build.json b/vscode/build.json new file mode 100644 index 0000000..1a64553 --- /dev/null +++ b/vscode/build.json @@ -0,0 +1,6 @@ +{ + "build_from": { + "amd64": "hassioaddons/ubuntu-base-amd64:3.0.0" + }, + "args": {} +} diff --git a/vscode/config.json b/vscode/config.json new file mode 100755 index 0000000..6769bb5 --- /dev/null +++ b/vscode/config.json @@ -0,0 +1,47 @@ +{ + "name": "Visual Studio Code", + "version": "dev", + "slug": "vscode", + "description": "Fully feature VSCode experience, to edit your HA config in the browser, including autocompletion!", + "url": "https://github.com/hassio-addons/addon-vscode", + "webui": "[PROTO:ssl]://[HOST]:[PORT:1337]", + "startup": "services", + "arch": [ + "amd64" + ], + "boot": "auto", + "hassio_api": true, + "hassio_role": "default", + "homeassistant_api": true, + "host_network": false, + "auto_uart": true, + "ports": { + "1337/tcp": 1337 + }, + "map": [ + "config:rw", + "ssl:rw", + "addons:rw", + "share:rw", + "backup:rw" + ], + "options": { + "password": "", + "ssl": false, + "certfile": "fullchain.pem", + "keyfile": "privkey.pem", + "packages": [], + "init_commands": [] + }, + "schema": { + "log_level": "match(^(trace|debug|info|notice|warning|error|fatal)$)?", + "password": "str", + "ssl": "bool", + "certfile": "str", + "keyfile": "str", + "packages": ["str"], + "init_commands": ["str"], + "leave_front_door_open": "bool?", + "i_like_to_be_pwned": "bool?" + } +} diff --git a/vscode/icon.png b/vscode/icon.png new file mode 100644 index 0000000..b3225e4 Binary files /dev/null and b/vscode/icon.png differ diff --git a/vscode/logo.png b/vscode/logo.png new file mode 100644 index 0000000..57a2ca2 Binary files /dev/null and b/vscode/logo.png differ diff --git a/vscode/requirements.txt b/vscode/requirements.txt new file mode 100644 index 0000000..b0b1802 --- /dev/null +++ b/vscode/requirements.txt @@ -0,0 +1,2 @@ +homeassistant_cli==0.6.0 +yamllint==1.15.0 diff --git a/vscode/rootfs/etc/cont-init.d/10-requirements.sh b/vscode/rootfs/etc/cont-init.d/10-requirements.sh new file mode 100644 index 0000000..62aad46 --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/10-requirements.sh @@ -0,0 +1,27 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# This files check if all user configuration requirements are met +# ============================================================================== +bashio::config.require.ssl + +if ! bashio::config.true 'leave_front_door_open'; then + if ! bashio::config.true 'i_like_to_be_pwned'; then + bashio::config.require.safe_password + else + bashio::config.require.password + fi +fi + +if bashio::config.true 'leave_front_door_open' \ + && bashio::config.true 'ssl'; +then + bashio::log.fatal + bashio::log.fatal "Due to a bug in code-server (which this add-on uses)," + bashio::log.fatal "it is impossible to disable authentication while" + bashio::log.fatal "using SSL." + bashio::log.fatal + bashio::log.fatal "Please enable authentication and set a password." + bashio::log.fatal + bashio::exit.nok +fi diff --git a/vscode/rootfs/etc/cont-init.d/20-link-common-dirs.sh b/vscode/rootfs/etc/cont-init.d/20-link-common-dirs.sh new file mode 100644 index 0000000..fa66d22 --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/20-link-common-dirs.sh @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# Links some common directories to the user's home folder for convenience +# ============================================================================== +readonly -a directories=(addons backup config share ssl) + +for dir in "${directories[@]}"; do + ln -s "/${dir}" "${HOME}/${dir}" \ + || bashio::log.warning "Failed linking common directory: ${dir}" +done diff --git a/vscode/rootfs/etc/cont-init.d/30-defaults.sh b/vscode/rootfs/etc/cont-init.d/30-defaults.sh new file mode 100644 index 0000000..f399647 --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/30-defaults.sh @@ -0,0 +1,14 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# This files check if all user configuration requirements are met +# ============================================================================== + +# Ensure persistent data folder exists +if ! bashio::fs.directory_exists '/data/vscode'; then + mkdir -p /data/vscode/extensions \ + || bashio::exit.nok "Could not create persistent storage folder." +fi + +# Copy in the extensions we deliver +cp -R /root/.code-server/extensions/* /data/vscode/extensions diff --git a/vscode/rootfs/etc/cont-init.d/50-user-ssh-folder.sh b/vscode/rootfs/etc/cont-init.d/50-user-ssh-folder.sh new file mode 100644 index 0000000..dfb40e9 --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/50-user-ssh-folder.sh @@ -0,0 +1,17 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# Sets up the users .ssh folder to be persistent +# ============================================================================== +readonly SSH_USER_PATH=/data/.ssh + +if ! bashio::fs.directory_exists "${SSH_USER_PATH}"; then + mkdir -p "${SSH_USER_PATH}" \ + || bashio::exit.nok 'Failed to create a persistent .ssh folder' + + chmod 700 "${SSH_USER_PATH}" \ + || bashio::exit.nok \ + 'Failed setting permissions on persistent .ssh folder' +fi + +ln -s "${SSH_USER_PATH}" ~/.ssh diff --git a/vscode/rootfs/etc/cont-init.d/80-user-packages.sh b/vscode/rootfs/etc/cont-init.d/80-user-packages.sh new file mode 100644 index 0000000..c9936fe --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/80-user-packages.sh @@ -0,0 +1,14 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# Install user configured/requested packages +# ============================================================================== +if bashio::config.has_value 'packages'; then + apt update \ + || bashio::exit.nok 'Failed updating Ubuntu packages repository indexes' + + for package in $(bashio::config 'packages'); do + apt add -y "$package" \ + || bashio::exit.nok "Failed installing package ${package}" + done +fi diff --git a/vscode/rootfs/etc/cont-init.d/81-user-scripts.sh b/vscode/rootfs/etc/cont-init.d/81-user-scripts.sh new file mode 100644 index 0000000..c72c425 --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/81-user-scripts.sh @@ -0,0 +1,11 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# Executes user configured/requested commands on startup +# ============================================================================== +if bashio::config.has_value 'init_commands'; then + while read -r cmd; do + eval "${cmd}" \ + || bashio::exit.nok "Failed executing init command: ${cmd}" + done <<< "$(bashio::config 'init_commands')" +fi diff --git a/vscode/rootfs/etc/motd b/vscode/rootfs/etc/motd new file mode 100755 index 0000000..b64ad92 --- /dev/null +++ b/vscode/rootfs/etc/motd @@ -0,0 +1,12 @@ + + _ _ _ + | | | | (_) + | |__| | __ _ ___ ___ _ ___ + | __ |/ _` / __/ __| | |/ _ \ + | | | | (_| \__ \__ \_| | (_) | + |_| |_|\__,_|___/___(_)_|\___/ + + +Our Cli: +$ hassio help + diff --git a/vscode/rootfs/etc/services.d/code/finish b/vscode/rootfs/etc/services.d/code/finish new file mode 100644 index 0000000..eb3f950 --- /dev/null +++ b/vscode/rootfs/etc/services.d/code/finish @@ -0,0 +1,9 @@ +#!/usr/bin/execlineb -S0 +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# Take down the S6 supervision tree when the code server fails +# ============================================================================== +if -n { s6-test $# -ne 0 } +if -n { s6-test ${1} -eq 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/vscode/rootfs/etc/services.d/code/run b/vscode/rootfs/etc/services.d/code/run new file mode 100644 index 0000000..c5c805f --- /dev/null +++ b/vscode/rootfs/etc/services.d/code/run @@ -0,0 +1,32 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Community Hass.io Add-ons: Visual Studio Code +# Runs the code server +# ============================================================================== +declare -a options + +bashio::log.info 'Starting the code server...' + +# Non-interactive +options+=(--port 1337) +options+=(--data-dir "/data/vscode") + +if bashio::config.false 'ssl'; then + options+=(--allow-http) +else + options+=(--cert "/ssl/$(bashio::config 'certfile')") + options+=(--cert-key "/ssl/$(bashio::config 'keyfile')") +fi + +if ! bashio::config.has_value 'password'; then + options+=(--no-auth) +else + options+=(--password "$(bashio::config 'password')") +fi + +# Export env variables for the Home Assistant extension +export HASS_SERVER="http://hassio/homeassistant" +export HASS_TOKEN="${HASSIO_TOKEN:-}" + +# Run the code server +exec code-server "${options[@]}" /config diff --git a/vscode/rootfs/root/.zshrc b/vscode/rootfs/root/.zshrc new file mode 100755 index 0000000..e4721be --- /dev/null +++ b/vscode/rootfs/root/.zshrc @@ -0,0 +1,100 @@ +# If you come from bash you might have to change your $PATH. +# export PATH=$HOME/bin:/usr/local/bin:$PATH + +# Path to your oh-my-zsh installation. +export ZSH=$HOME/.oh-my-zsh + +# Set name of the theme to load. Optionally, if you set this to "random" +# it'll load a random theme each time that oh-my-zsh is loaded. +# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes +ZSH_THEME="robbyrussell" + +# Uncomment the following line to use case-sensitive completion. +# CASE_SENSITIVE="true" + +# Uncomment the following line to use hyphen-insensitive completion. Case +# sensitive completion must be off. _ and - will be interchangeable. +# HYPHEN_INSENSITIVE="true" + +# Uncomment the following line to disable bi-weekly auto-update checks. +DISABLE_AUTO_UPDATE="true" + +# Uncomment the following line to change how often to auto-update (in days). +# export UPDATE_ZSH_DAYS=13 + +# Uncomment the following line to disable colors in ls. +# DISABLE_LS_COLORS="true" + +# Uncomment the following line to disable auto-setting terminal title. +# DISABLE_AUTO_TITLE="true" + +# Uncomment the following line to enable command auto-correction. +# ENABLE_CORRECTION="true" + +# Uncomment the following line to display red dots whilst waiting for completion. +COMPLETION_WAITING_DOTS="true" + +# Uncomment the following line if you want to disable marking untracked files +# under VCS as dirty. This makes repository status check for large repositories +# much, much faster. +# DISABLE_UNTRACKED_FILES_DIRTY="true" + +# Uncomment the following line if you want to change the command execution time +# stamp shown in the history command output. +# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd" +# HIST_STAMPS="mm/dd/yyyy" + +# Would you like to use another custom folder than $ZSH/custom? +# ZSH_CUSTOM=/path/to/new-custom-folder + +# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) +# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ +# Example format: plugins=(rails git textmate ruby lighthouse) +# Add wisely, as too many plugins slow down shell startup. +plugins=( + extract + git + nmap + pip + python + rsync + zsh-autosuggestions + zsh-syntax-highlighting +) + +source $ZSH/oh-my-zsh.sh + +# User configuration + +# export MANPATH="/usr/local/man:$MANPATH" + +# You may need to manually set your language environment +# export LANG=en_US.UTF-8 + +# Preferred editor for local and remote sessions +# if [[ -n $SSH_CONNECTION ]]; then +# export EDITOR='vim' +# else +# export EDITOR='mvim' +# fi + +# Compilation flags +# export ARCHFLAGS="-arch x86_64" + +# ssh +# export SSH_KEY_PATH="~/.ssh/rsa_id" + +# Set personal aliases, overriding those provided by oh-my-zsh libs, +# plugins, and themes. Aliases can be placed here, though oh-my-zsh +# users are encouraged to define aliases within the ZSH_CUSTOM folder. +# For a full list of active aliases, run `alias`. +# +# Example aliases +# alias zshconfig="mate ~/.zshrc" +# alias ohmyzsh="mate ~/.oh-my-zsh" + +# Home Assistant CLI +eval "$(_HASS_CLI_COMPLETE=source_zsh hass-cli)" + +# Show motd on start +cat /etc/motd diff --git a/vscode/vscode.extensions b/vscode/vscode.extensions new file mode 100644 index 0000000..2db10e0 --- /dev/null +++ b/vscode/vscode.extensions @@ -0,0 +1,2 @@ +keesschollaart.vscode-home-assistant +lukas-tr.materialdesignicons-intellisense