Skip to content

Commit eca958d

Browse files
authored
Merge pull request #1073 from somewatson/code-server-bat
Create mod to include bat in code-server
2 parents 6360fcf + 759dee2 commit eca958d

File tree

24 files changed

+103
-102
lines changed

24 files changed

+103
-102
lines changed

.github/workflows/BuildImage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ on:
1212
env:
1313
GITHUB_REPO: "linuxserver/docker-mods" #don't modify
1414
ENDPOINT: "linuxserver/mods" #don't modify
15-
BASEIMAGE: "replace_baseimage" #replace
16-
MODNAME: "replace_modname" #replace
15+
BASEIMAGE: "code-server" #replaced
16+
MODNAME: "bat" #replaced
1717
MOD_VERSION: ${{ inputs.mod_version }} #don't modify
18-
MULTI_ARCH: "true" #set to false if not needed
18+
MULTI_ARCH: "false" #set to false if not needed
1919

2020
jobs:
2121
set-vars:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
FROM scratch
44

5-
LABEL maintainer="username"
5+
LABEL maintainer="somewatson"
66

77
# copy local files
88
COPY root/ /

Dockerfile.complex

Lines changed: 0 additions & 33 deletions
This file was deleted.

README.md

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
# Rsync - Docker mod for openssh-server
1+
# Bat - Docker mod for code-server
22

3-
This mod adds rsync to openssh-server, to be installed/updated during container start.
3+
This mod adds [bat](https://github.com/sharkdp/bat) to code-server, to be installed/updated during container start.
44

5-
In openssh-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:openssh-server-rsync`
5+
Bat is a cat(1) clone with syntax highlighting and Git integration.
66

7-
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:openssh-server-rsync|linuxserver/mods:openssh-server-mod2`
7+
In code-server docker arguments, set an environment variable `DOCKER_MODS=linuxserver/mods:code-server-bat`
88

9-
# Mod creation instructions
9+
If adding multiple mods, enter them in an array separated by `|`, such as `DOCKER_MODS=linuxserver/mods:code-server-bat|linuxserver/mods:openssh-server-mod2`
1010

11-
* Fork the repo, create a new branch based on the branch `template`.
12-
* Edit the `Dockerfile` for the mod. `Dockerfile.complex` is only an example and included for reference; it should be deleted when done.
13-
* Inspect the `root` folder contents. Edit, add and remove as necessary.
14-
* After all init scripts and services are created, run `find ./ -path "./.git" -prune -o \( -name "run" -o -name "finish" -o -name "check" \) -not -perm -u=x,g=x,o=x -print -exec chmod +x {} +` to fix permissions.
15-
* Edit this readme with pertinent info, delete these instructions.
16-
* Finally edit the `.github/workflows/BuildImage.yml`. Customize the vars for `BASEIMAGE` and `MODNAME`. Set the versioning logic and `MULTI_ARCH` if needed.
17-
* Ask the team to create a new branch named `<baseimagename>-<modname>`. Baseimage should be the name of the image the mod will be applied to. The new branch will be based on the `template` branch.
18-
* Submit PR against the branch created by the team.
11+
### Bat-extras and Ripgrep
1912

13+
This mod also includes [bat-extras](https://github.com/eth-p/bat-extras) which has a dependency of [ripgrep](https://github.com/BurntSushi/ripgrep). Ripgrep has also been included because it is a requirment of bat-extras.
2014

21-
## Tips and tricks
15+
### Aliases
2216

23-
* Some images have helpers built in, these images are currently:
24-
* [Openvscode-server](https://github.com/linuxserver/docker-openvscode-server/pull/10/files)
25-
* [Code-server](https://github.com/linuxserver/docker-code-server/pull/95)
17+
This mod includes aliases for `bat` in `bash` and `zsh`. Under Ubuntu `bat` gets installed as `batcat` to avoid a name collision. So, for convenience, an alias to set `bat="batcat"` is included for both `bash` and `zsh`.

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-add-package/dependencies.d/init-mods renamed to root/etc/s6-overlay/s6-rc.d/init-mod-code-server-bat-add-package/dependencies.d/init-mods

File renamed without changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# This is the init file used for adding os or pip packages to install lists.
4+
# It takes advantage of the built-in init-mods-package-install init script that comes with the baseimages.
5+
# If using this, we need to make sure we set this init as a dependency of init-mods-package-install so this one runs first
6+
#!/usr/bin/with-contenv bash
7+
8+
if ! dpkg -s ripgrep >/dev/null 2>&1; then
9+
echo "**** Adding ripgrep to package install list ****"
10+
echo "ripgrep" >> /mod-repo-packages-to-install.list
11+
else
12+
echo "**** ripgrep already installed, skipping ****"
13+
fi
14+
15+
if ! dpkg -s bat >/dev/null 2>&1; then
16+
echo "**** Adding bat to package install list ****"
17+
echo "bat" >> /mod-repo-packages-to-install.list
18+
else
19+
echo "**** bat already installed, skipping ****"
20+
fi
21+
22+
if ! dpkg -s git >/dev/null 2>&1; then
23+
echo "**** Adding git to package install list ****"
24+
echo "git" >> /mod-repo-packages-to-install.list
25+
else
26+
echo "**** git already installed, skipping ****"
27+
fi

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-add-package/type renamed to root/etc/s6-overlay/s6-rc.d/init-mod-code-server-bat-add-package/type

File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/etc/s6-overlay/s6-rc.d/init-mod-code-server-bat-add-package/run

root/etc/s6-overlay/s6-rc.d/init-mod-imagename-modname-install/dependencies.d/init-mods-package-install renamed to root/etc/s6-overlay/s6-rc.d/init-mod-code-server-bat-install/dependencies.d/init-mods-package-install

File renamed without changes.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/with-contenv bash
2+
3+
# This is an install script that is designed to run after init-mods-package-install
4+
# so it can take advantage of packages installed
5+
# init-mods-end depends on this script so that later init and services wait until this script exits
6+
7+
if ! command -v zsh >/dev/null 2>&1; then
8+
echo "**** zsh not installed, skipping alias setup ****"
9+
else
10+
if [ -f /config/.zshrc ]; then
11+
if ! grep -q 'alias bat="batcat"' /config/.zshrc; then
12+
echo 'Adding alias to zsh for bat'
13+
echo 'alias bat="batcat"' >> /config/.zshrc
14+
else
15+
echo 'Alias already exists in zsh, skipping'
16+
fi
17+
else
18+
echo '/config/.zshrc not found, creating one with the alias'
19+
echo 'alias bat="batcat"' > /config/.zshrc
20+
fi
21+
fi
22+
23+
if ! command -v bash >/dev/null 2>&1; then
24+
echo "**** bash not installed, skipping alias setup ****"
25+
else
26+
if [ -f /config/.bash_profile ]; then
27+
if ! grep -q 'alias bat="batcat"' /config/.bash_profile; then
28+
echo 'Adding alias to /config/.bash_profile for bat'
29+
echo 'alias bat="batcat"' >> /config/.bash_profile
30+
else
31+
echo 'Alias already exists in /config/.bash_profile, skipping'
32+
fi
33+
elif [ -f /config/.bashrc ]; then
34+
if ! grep -q 'alias bat="batcat"' /config/.bashrc; then
35+
echo 'Adding alias to /config/.bashrc for bat'
36+
echo 'alias bat="batcat"' >> /config/.bashrc
37+
else
38+
echo 'Alias already exists in /config/.bashrc, skipping'
39+
fi
40+
else
41+
echo '/config/.bash_profile or /config/.bashrc not found, creating one with the alias'
42+
echo 'alias bat="batcat"' > /config/.bash_profile
43+
fi
44+
fi
45+
46+
if [ -d /config/.bat-extras ]; then
47+
echo 'Bat-extras already cloned, updating'
48+
git config --global --add safe.directory /config/.bat-extras
49+
git -C /config/.bat-extras pull
50+
else
51+
echo 'Cloning bat-extras repo'
52+
git clone https://github.com/eth-p/bat-extras.git /config/.bat-extras
53+
fi
54+
55+
echo 'Installing bat-extras'
56+
ln -sf /config/.bat-extras/src/*.sh /usr/local/bin
57+
58+
echo 'Setting permissions for bat-extras'
59+
chmod +x /config/.bat-extras/src/*.sh
60+
lsiown -R abc:abc \
61+
/config/.bat-extras

0 commit comments

Comments
 (0)