Quick Start
Quick start manuel to developing or testing.
MacOS
-
Install Rust on your macOS machine.
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Clone mega repository and build it.
$ git clone https://github.com/web3infra-foundation/mega.git $ cd mega $ git submodule update --init --recursive $ cargo build
-
Install PostgreSQL and init database. (You can skip this step if using SQLite in
config.toml
)- Install PostgreSQL 16 with
brew
command.
$ brew install postgresql@16 $ echo 'export PATH="/opt/homebrew/opt/postgresql@16/bin:$PATH"' >> ~/.zshrc $ brew services start postgresql@16 $ initdb /Volumes/Data/postgres -E utf8 # /Volumes/Data is path store data
- Create a database, then find the dump file in the SQL directory of the Mega repository and import it into the database.
$ psql postgres
postgres=# \l postgres=# DROP DATABASE IF EXISTS mega; postgres=# CREATE DATABASE mega; postgres=# \q
$ cd mega/sql/postgres $ psql mega < pg_YYYYMMDD_init.sql
- Create user and grant privileges.
postgres=# DROP USER IF EXISTS mega; postgres=# CREATE USER mega WITH ENCRYPTED PASSWORD 'mega'; postgres=# GRANT ALL PRIVILEGES ON DATABASE mega TO mega;
$ psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;" $ psql mega -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to mega;" $ psql mega -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to mega;"
- Install PostgreSQL 16 with
-
Update config file for local test. For local testing, Mega uses the
config.toml
file to configure the required parameters. See Configuration. -
Init the Mega
$ cd mega $ cargo run init
-
Start the Mega server for testing.
# Starting a single http server $ cargo run service http # Or Starting multiple server $ cargo run service multi http ssh
-
Test the
git push
andgit clone
$ cd mega $ git remote add local http://localhost:8000/projects/mega.git $ git push local main $ cd /tmp $ git clone http://localhost:8000/projects/mega.git
Arch Linux
-
Install Rust.
$ pacman -S rustup $ rustup default stable
-
Clone mega repository and build.
$ git clone https://github.com/web3infra-foundation/mega.git $ cd mega $ git submodule update --init --recursive $ cargo build
-
Install PostgreSQL and initialize database. (You can skip this step if using SQLite in
config.toml
)1.Install PostgreSQL.
$ pacman -S postgresql # Switch to `postgres` user $ sudo -i -u postgres postgres $ initdb -D /var/lib/postgres/data -E utf8 # /Volumes/Data is where data will be stored postgres $ exit $ systemctl enable --now postgresql
2.Create database.
$ sudo -u postgres psql postgres
postgres=# \l postgres=# DROP DATABASE IF EXISTS mega; postgres=# CREATE DATABASE mega; postgres=# \q
3.Import
mega/sql/postgres/pg_<time>_init.sql
tomega
.$ cd mega/sql/postgres $ sudo -u postgres psql mega < pg_YYYYMMDD__init.sql
4.Create user and grant privileges.
$ sudo -u postgres psql postgres postgres=# DROP USER IF EXISTS mega; postgres=# CREATE USER mega WITH ENCRYPTED PASSWORD 'mega'; postgres=# GRANT ALL PRIVILEGES ON DATABASE mega TO mega;
$ sudo -u postgres psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;" $ sudo -u postgres psql mega -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to mega;" $ sudo -u postgres psql mega -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to mega;"
-
Config
confg.toml
. See Configuration. -
Init Mega.
$ cd mega $ cargo run init
-
Start Mega server.
# Start a single https server $ cargo run service http # Or Start multiple server $ cargo run service multi http ssh
-
Test
git push
andgit clone
$ cd /tmp $ git clone https://github.com/Rust-for-Linux/linux.git $ cd linux $ git remote add mega http://localhost:8000/third-part/linux.git $ git push --all mega $ sudo rm -r /tmp/linux $ cd /tmp $ git clone http://localhost:8000/third-part/linux.git
GitHub Codespace
If you are using GitHub codespaces, you can follow the steps below to set up the Mega project. When you create a new Codespace, the Mega project will be cloned automatically. You can then follow the steps below to set up the project.
You can skip this step (PostgreSQL setup) if using SQLite in config.toml
.
When the codespace is ready, the PostgreSQL will be installed and started automatically. You can then follow the steps below to set up the database with below steps.
# Start PostgreSQL
/etc/init.d/postgresql start
sudo -u postgres psql mega -c "CREATE DATABASE mega;"
sudo -u postgres psql mega < /workspaces/mega/sql/pg_YYYYMMDD__init.sql
sudo -u postgres psql mega -c "CREATE USER mega WITH ENCRYPTED PASSWORD 'mega';"
sudo -u postgres psql mega -c "GRANT ALL PRIVILEGES ON DATABASE mega TO mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL TABLES IN SCHEMA public to mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL SEQUENCES IN SCHEMA public to mega;"
sudo -u postgres psql mega -c "GRANT ALL ON ALL FUNCTIONS IN SCHEMA public to mega;"
Config confg.toml
file for the Mega project.