Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install VSCodium and make host .application file #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 152 additions & 4 deletions scripts/container-only/wkdev-setup-vscode
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ else
echo "Please set \${WKDEV_SDK} to point to the root of the wkdev-sdk checkout."
exit 1
fi
if [[ -z ${WKDEV_SDK_HOST} ]]; then
echo "Please set \${WKDEV_SDK_HOST} to point to the the wkdev-sdk checkout (from the host perspective). This is used when creating .desktop entries."
exit 1
fi
if [[ ! -d /host/${HOME} ]]; then
echo "Host and container home must have the same path: /host/${HOME}"
exit 1
fi
source "${WKDEV_SDK}/utilities/prerequisites.sh"

init_application "${0}" "Configures Visual Studio Code." container-only
Expand All @@ -17,8 +25,10 @@ verify_executables_exist curl
argsparse_allow_no_argument true
argsparse_use_option "=yes" "Assume yes for all prompts."
argsparse_use_option "no-extensions" "Don't install extensions."
argsparse_use_option "no-proprietary" "Use VSCodium instead of VSCode."

install_vscode() {
CODE_EXEC=code

_log_ ""
_log_ "Installing Visual Studio Code..."
Expand All @@ -40,7 +50,7 @@ install_vscode() {
exit 1
fi

if ! sudo apt install /tmp/code.deb; then
if ! sudo apt install -y /tmp/code.deb; then
_log_ "Failed to install Visual Studio Code."
rm /tmp/code.deb
exit 1
Expand All @@ -51,15 +61,50 @@ install_vscode() {
_log_ "Visual Studio Code has been installed."
}

install_vscodium() {
CODE_EXEC=codium

_log_ ""
_log_ "Installing Visual Studio Code (oss)..."
_log_ ""

if which codium > /dev/null; then
_log_ "Visual Studio Code (oss) is already installed."
return
fi

wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg \
| gpg --dearmor \
| sudo dd of=/usr/share/keyrings/vscodium-archive-keyring.gpg

echo 'deb [ signed-by=/usr/share/keyrings/vscodium-archive-keyring.gpg ] https://download.vscodium.com/debs vscodium main' \
| sudo tee /etc/apt/sources.list.d/vscodium.list

if ! sudo apt update; then
_log_ "Failed to install Visual Studio Code (oss) repo."
exit 1
fi

if ! sudo apt install -y codium; then
_log_ "Failed to install Visual Studio Code (oss)."
exit 1
fi

_log_ ""
_log_ "Visual Studio Code (oss) has been installed."
}

install_extension() {

sudo chown "${USER}" "${HOME}/.config"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would .config be owned by a different user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this was an idiosyncrasy of my setup, let's remove it and see if it comes up again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed if you run this script from your firstrun script. It seems it runs as root. I guess I can change my firstrun script to run as the container user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I said makes no sense, since we use $USER here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like systemd makes the config path? At the very least, some files in ~/.config/systemd appear to be owned by root.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed if you run this script from your firstrun script. It seems it runs as root. I guess I can change my firstrun script to run as the container user

It very explicitly runs as your user:

su "${container_user_name}" --group="${container_group_name}" --command="${user_home}/.wkdev-firstrun"

Copy link
Member

@TingPing TingPing Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like systemd makes the config path?

While podman supports systemd, we don't use it, and I'd expect systemd knows nothing at all about the containers home.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is confusing to me, although .config is definitely owned by root. In particular, so is .config/systemd, which seems to come from nowhere. Do you have any ideas how I can start debugging this?


local extension_name="${1}"
local description="${2}"
local ask="${3:-false}"
local response
local installed_extensions

readarray installed_extensions < <(code --list-extensions)
readarray installed_extensions < <($CODE_EXEC --list-extensions)

if [[ "${installed_extensions[*]}" =~ "${extension_name}" ]]; then
_log_ "VSCode extension already installed: ${extension_name}"
Expand All @@ -75,7 +120,7 @@ install_extension() {
_log_ "Installing VSCode extension: ${extension_name} (${description})..."
fi

if ! code --install-extension "${extension_name}" &>/dev/null; then
if ! ${CODE_EXEC} --install-extension "${extension_name}" &>/dev/null; then
_log_ "Failed to install VSCode extension: ${extension_name}"
exit 1
fi
Expand All @@ -96,15 +141,118 @@ install_extensions() {
install_extension ms-python.python "Python support" true
}

# These are VERY helpful for WebKit development, but we won't override existing settings if the user already has them.
default_settings() {
if argsparse_is_option_set "no-proprietary"; then
VSCODE_CONFIG_PATH=${HOME}/.config/VSCodium/User/
else
VSCODE_CONFIG_PATH=${HOME}/.config/Code/User/
fi
if [[ ! -e "${VSCODE_CONFIG_PATH}/settings.json" ]]; then
mkdir -p "${VSCODE_CONFIG_PATH}"
tee "${VSCODE_CONFIG_PATH}/settings.json" << HERE
{
"clangd.arguments": [
"-header-insertion=never"
],
"editor.renderWhitespace": "trailing",
"workbench.colorCustomizations": {
"editorWhitespace.foreground": "#FF0000",
"editorWhitespace.background": "#FF0000"
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these are pretty arbitrary. I like the clangd.arguments but maybe lets move this to a different PR to discuss.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clangd and fg/bg colours are important for our style guidelines, but I removed the rest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh you just mean to more easily visualize whitespace.

I've never needed that and don't think I'd want it by default. I'll check how it looks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to vote no on this, I think it would annoy most people.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot, it doesn't look like that for me. It is only supposed to display trailing whitespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2025-01-27T13:27:24,752795531-07:00

Copy link
Member

@TingPing TingPing Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some other setting is involved. It would be best to keep these PRs small, I'd remove this change here and it can be discussed on its own.

HERE
echo "Installed default VSCode settings to ${VSCODE_CONFIG_PATH}."
else
echo "There was already a VSCode settings.json (${VSCODE_CONFIG_PATH}), skipping."
fi
}

install_xdg() {
tee "/host/${HOME}/.local/share/applications/code-wkdev.desktop" << HERE
[Desktop Entry]
Name=VSCode WKDev
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC %F
Icon=vscode-wkdev
Type=Application
StartupNotify=false
StartupWMClass=VSCode
Categories=TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;application/x-codium-workspace;
Keywords=vscode;code;vscode;
Actions=new-empty-window;

[Desktop Action new-empty-window]
Name=New Empty Window
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC --new-window %F
Icon=vscode-wkdev
HERE
chmod +x "/host/${HOME}/.local/share/applications/code-wkdev.desktop"
echo "Installed VSCode host launcher"
}

install_xdg_oss() {
tee "/host/${HOME}/.local/share/applications/codium-wkdev.desktop" << HERE
[Desktop Entry]
Name=VSCodium WKDev
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC %F
Icon=vscodium-wkdev
Type=Application
StartupNotify=false
StartupWMClass=VSCodium
justinmichaud marked this conversation as resolved.
Show resolved Hide resolved
Categories=TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;application/x-codium-workspace;
Keywords=vscodium;codium;vscode;
Actions=new-empty-window;

justinmichaud marked this conversation as resolved.
Show resolved Hide resolved
[Desktop Action new-empty-window]
Name=New Empty Window
Exec="${WKDEV_SDK_HOST}/scripts/host-only/wkdev-enter" --exec --no-interactive -- $CODE_EXEC --new-window %F
Icon=vscodium-wkdev
HERE
chmod +x "/host/${HOME}/.local/share/applications/codium-wkdev.desktop"
echo "Installed VSCodium host launcher"
}

install_icon() {
mkdir -p "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/"
cp /usr/share/pixmaps/vscode.png "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/vscode-wkdev.png"
echo "Installed VSCode host icon."
}

install_icon_oss() {
mkdir -p "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/"
cp /usr/share/pixmaps/vscodium.png "/host/${HOME}/.local/share/icons/hicolor/256x256/apps/vscodium-wkdev.png"
echo "Installed VSCodium host icon."
}

run() {

argsparse_parse_options "${@}"

install_vscode
if argsparse_is_option_set "no-proprietary"; then
install_vscodium
else
install_vscode
fi

if ! argsparse_is_option_set "no-extensions"; then
install_extensions
fi

if argsparse_is_option_set "no-proprietary"; then
install_xdg_oss
install_icon_oss
else
install_xdg
install_icon
fi

default_settings
}

run "${@}"
3 changes: 3 additions & 0 deletions scripts/host-only/wkdev-create
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ build_podman_create_arguments() {
# Always set XDG_RUNTIME_DIR to the same value.
arguments+=("--env" "XDG_RUNTIME_DIR=/run/user/${host_user_id}")

# This is needed for some scripts like wkdev-setup-vscode
arguments+=("--env" "WKDEV_SDK_HOST=${WKDEV_SDK}")

if argsparse_is_option_set "no-pull"; then
arguments+=("--pull=never")
else
Expand Down
3 changes: 3 additions & 0 deletions scripts/host-only/wkdev-enter
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ run() {
# Ensure WKDEV_SDK is set. It is done here and not creation to support older containers.
podman_exec_arguments+=("--env" "WKDEV_SDK=/wkdev-sdk")

# This is needed for some scripts like wkdev-setup-vscode
podman_exec_arguments+=("--env" "WKDEV_SDK_HOST=${WKDEV_SDK}")

# Choose root or regular user.
if argsparse_is_option_set "root"; then
podman_exec_arguments+=("--user" "0:0")
Expand Down