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

DietPi-Software | Lemmy: A link aggregator for the fediverse #6434

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from
195 changes: 195 additions & 0 deletions dietpi/dietpi-software
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,13 @@ Available commands:
aSOFTWARE_CATX[$software_id]=6
aSOFTWARE_DEPS[$software_id]='17'
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#microblogpub'
#-----------------
software_id=210
aSOFTWARE_NAME[$software_id]='lemmy'
aSOFTWARE_DESC[$software_id]='A link aggregator for the fediverse'
aSOFTWARE_CATX[$software_id]=6
aSOFTWARE_DEPS[$software_id]='9 17'
aSOFTWARE_DOCS[$software_id]='https://dietpi.com/docs/software/social/#lemmy'

# Camera & Surveillance
#--------------------------------------------------------------------------------
Expand Down Expand Up @@ -4332,6 +4339,189 @@ _EOF_
G_DIETPI-NOTIFY 0 'microblog.pub installation finished. In order to complete the setup, please run "microblog-pub configure" in a new bash session. Append the port ":8007" to the domain when being asked for it if you do not use a reverse proxy.'
fi

if To_Install 210 # lemmy
then
aDEPS=('make' 'gcc' 'libc6-dev' 'pkg-config' 'libssl-dev' 'protobuf-compiler' 'libprotobuf-dev' 'libpq-dev')
## Install up-to-date rustup (cargo version in debian is too old)
local lemm_user='lemmy'
local lemm_home="/home/$lemm_user"
# User
##Create_User -G dialout,gpio,i2c -d "$lemm_home" "$lemm_user"
G_EXEC mkdir -p "$lemm_home"
Create_User -d "$lemm_home" "$lemm_user"
G_EXEC chown "$lemm_user":"$lemm_user" -R "$lemm_home"

##G_EXEC sudo su -u $lemm_user mkdir -p $lemm_bin

## Install Rust, cargo
## We assume users will want to upload images, so we enable pictrs
G_DIETPI-NOTIFY 0 '[ INFO ] lemmy backend installation started'
mtekman marked this conversation as resolved.
Show resolved Hide resolved
G_EXEC curl -sSf 'https://sh.rustup.rs/' -o rustup-init.sh
G_EXEC chmod +x rustup-init.sh
G_EXEC_OUTPUT=1 G_EXEC ./rustup-init.sh -y --profile minimal
G_EXEC rm rustup-init.sh
export PATH="/root/.cargo/bin:$PATH"
G_EXEC_OUTPUT=1 G_EXEC cargo install lemmy_server --locked --features embed-pictrs
G_DIETPI-NOTIFY 0 '[ INFO ] lemmy backend installation finished'

## Install lemmy front-end server
## Deps
local url='https://dl.yarnpkg.com/debian/pubkey.gpg'
G_CHECK_URL "$url"
G_EXEC eval "curl -sSfL '$url' | gpg --dearmor -o /etc/apt/trusted.gpg.d/dietpi-lemmy.gpg --yes"
G_EXEC eval "echo 'deb https://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/dietpi-yarn.list"
G_AGUP
G_AGI yarn nodejs
Copy link
Owner

@MichaIng MichaIng Jun 16, 2023

Choose a reason for hiding this comment

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

This shouldn't be needed as you defined our up-to-date Node.js implementation as dependency already:

Suggested change
G_EXEC eval "echo 'deb https://dl.yarnpkg.com/debian/ stable main' > /etc/apt/sources.list.d/dietpi-yarn.list"
G_AGUP
G_AGI yarn nodejs
G_EXEC_OUTPUT=1 G_EXEC npm i -g --no-audit yarn

It includes yarn.

EDIT: Ah nope it does not include yarn, but npm to install it.

# ## Installation
G_EXEC mkdir -p /var/lib/lemmy-ui
G_EXEC chown "$lemm_user":"$lemm_user" -R /var/lib/lemmy-ui
# dont compile as admin
G_EXEC cd /var/lib/lemmy-ui
G_DIETPI-NOTIFY 0 '[ INFO ] lemmy UI installation started'
G_EXEC sudo -u "$lemm_user" dash -c '\
git clone https://github.com/LemmyNet/lemmy-ui.git --recursive . && \
git checkout 0.17.3 && \
yarn install --pure-lockfile && \
yarn build:prod'
G_DIETPI-NOTIFY 0 '[ INFO ] lemmy UI installation finished'

# Config Section
local host_bind=127.0.0.1
local host_broadcast=0.0.0.0
local host_domain=dietpi.lemmy.com
local port_database=5432
local port_backend=5433 ## default:8536
local port_pictrs=5434
local port_frontend=5435 ## default:1234

G_DIETPI-NOTIFY 0 "[ INFO ] lemmy will be up and running at https://$host_broadcast:$port_frontend"

cat << _EOF_ > /etc/lemmy/lemmy.hjson
{
database: {
password: "db-passwd"
port: $port_database
}
# replace with your domain
hostname: "$host_domain"
bind: "$host_bind"
port: $port_backend
federation: {
enabled: true
}
# remove this block if you don't require image hosting
pictrs: {
url: "$host_bind:$port_pictrs/"
}
## Disable this if not a federated instance
tls_enabled: true
}
_EOF_
## Backend Service
cat << _EOF_ > /etc/systemd/system/lemmy.service
[Unit]
Description=Lemmy - A link aggregator for the fediverse
After=network.target

[Service]
User=lemmy
ExecStart=/root/.cargo/bin/lemmy_server
Environment=LEMMY_CONFIG_LOCATION=/etc/lemmy/lemmy.hjson
Environment=PICTRS_PATH=/var/lib/pictrs
Environment=PICTRS_ADDR=$host_bind:$port_pictrs
Restart=on-failure

# Hardening
ProtectSystem=yes
PrivateTmp=true
MemoryDenyWriteExecute=true
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
_EOF_
## UI Service - https://github.com/LemmyNet/lemmy-ui#configuration
cat << _EOF_ > /etc/systemd/system/lemmy-ui.service
[Unit]
Description=Lemmy UI - Web frontend for Lemmy
After=lemmy.service
Before=nginx.service ## Hey, do you think this is needed?

[Service]
User=lemmy
WorkingDirectory=/var/lib/lemmy-ui
ExecStart=/usr/bin/node dist/js/server.js
Environment=LEMMY_UI_HOST=$host_broadcast:$port_frontend
Environment=LEMMY_UI_LEMMY_INTERNAL_HOST=$host_bind:$port_backend
Environment=LEMMY_UI_LEMMY_EXTERNAL_HOST="$host_domain"
Environment=LEMMY_UI_HTTPS=true ## Hey, should this be enforced?
Restart=on-failure

# Hardening
ProtectSystem=full
PrivateTmp=true
NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
_EOF_
## TODO: Upgrade Scripts. FIX THIS SO THAT IT WORKS WITH THE GLOBAL CARGO ENV
cat << _EOF_ > /etc/bashrc.d/lemmy.sh
#!/bin/dash
lemmy-update()
{
case \$1 in
l*) ## Lemmy
sudo -u '$lemm_user' dash -c 'source "$lemm_home/.cargo/env"; cargo install lemmy_server --target-dir --features embed-pictrs'
sudo systemctl restart lemmy
;;
ui) ## UI
sudo -u '$lemm_user' dash -c '\
source "$lemm_home/.cargo/env"; \
cd /var/lib/lemmy-ui; \
git checkout main && \
git pull --tags && \
git checkout 0.12.2 && \
git submodule update && \
yarn install --pure-lockfile && \
yarn build:prod;';
sudo systemctl restart lemmy-ui
;;
pic*) ## PictRS
# check docker-compose.yml for pict-rs version used by lemmy
# https://github.com/LemmyNet/lemmy-ansible/blob/main/templates/docker-compose.yml#L40
sudo -u '$lemm_user' dash -c '\
source "$lemm_home/.cargo/env"; \
rustup update && \
cd /var/lib/pictrs-source && \
git checkout main && \
git pull --tags && \
git checkout v0.2.6-r2 &&\
cargo build --release &&
cp target/release/pict-rs "$lemm_bin" '
sudo systemctl restart pictrs
;;
*) echo 'lemmy-update helper script

usage: lemmy-update <lemmy|ui|pictrs>

where:
lemmy update and rebuild the backend server (via cargo)
ui update and rebuilt the ui (via yarn)
pictrs update and rebuild the picture service (via cargo)' && \
return 1;;
esac
}
_EOF_

## Fresh database and upgrade lemmy to sudo
## Hey, maybe a reinstallation shouldn't drop the last database?
G_EXEC systemctl start postgresql
G_EXEC sudo -u postgres psql -c "DROP DATABASE lemmy;"
G_EXEC sudo -u postgres psql -c "CREATE DATABASE lemmy WITH OWNER lemmy ENCODING 'UTF8' TEMPLATE template0 LC_COLLATE 'C' LC_CTYPE 'C';"
G_EXEC sudo -u postgres psql -c "ALTER USER lemmy WITH SUPERUSER;"
fi

if To_Install 2 fahclient # Folding@Home
then
G_DIETPI-NOTIFY 2 'Pre-configuring FAHClient DEB package'
Expand Down Expand Up @@ -13041,6 +13231,11 @@ If no WireGuard (auto)start is included, but you require it, please do the follo
G_DIETPI-NOTIFY 2 'All microblog.pub data and settings are still retained.\n - You can remove these manually: rm -R /mnt/dietpi_userdata/microblog-pub'
fi

if To_Uninstall 210 # lemmy
then
echo hi
fi

if To_Uninstall 98 # HAProxy
then
Remove_Service haproxy
Expand Down