diff options
-rw-r--r-- | .SRCINFO | 35 | ||||
-rw-r--r-- | PKGBUILD | 94 | ||||
-rw-r--r-- | database-tweak.diff | 13 | ||||
-rw-r--r-- | database.json | 16 | ||||
-rwxr-xr-x | install.sh | 137 | ||||
-rw-r--r-- | karaokemugen.install | 10 | ||||
-rwxr-xr-x | run.sh | 36 |
7 files changed, 341 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..c01cc8d49a0f --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,35 @@ +pkgbase = karaokemugen-git + pkgdesc = Karaoke playlist manager/player app used in parties or events. + pkgver = 3.2.0.rc1.r15.g1a01c9c8 + pkgrel = 1 + url = https://mugen.karaokes.moe/ + install = karaokemugen.install + arch = x86_64 + arch = i686 + license = MIT + makedepends = git + makedepends = npm + makedepends = typescript + makedepends = yarn + makedepends = nodejs>=12 + depends = mpv + depends = ffmpeg + depends = postgresql + depends = electron + provides = karaokemugen + conflicts = karaokemugen + source = karaokemugen::git+https://lab.shelter.moe/karaokemugen/karaokemugen-app.git + source = karaokemugen-lib::git+https://lab.shelter.moe/karaokemugen/lib.git + source = install.sh + source = run.sh + source = database-tweak.diff + source = database.json + md5sums = SKIP + md5sums = SKIP + md5sums = 1673054cbeb6b80097dae4601cf35959 + md5sums = 6efac0086021d7a7abcf637aae17cc99 + md5sums = c1807f76ea2d800999910fe66e56fe73 + md5sums = 0f887855e641ec949ce7c6b69d79ad1e + +pkgname = karaokemugen-git + diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..417984cc4307 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,94 @@ +# Maintainer: leonekmi <usingarchbtw@leonekmi.fr> +pkgname=karaokemugen-git +pkgver=3.2.0.rc1.r15.g1a01c9c8 +pkgrel=1 +pkgdesc="Karaoke playlist manager/player app used in parties or events." +arch=(x86_64 i686) +url="https://mugen.karaokes.moe/" +license=('MIT') +groups=() +depends=('mpv' 'ffmpeg' 'postgresql' 'electron') +makedepends=('git' 'npm' 'typescript' 'yarn' 'nodejs>=12') +provides=("${pkgname%-git}") +conflicts=("${pkgname%-git}") +replaces=() +backup=() +options=() +install=${pkgname%-git}.install +source=('karaokemugen::git+https://lab.shelter.moe/karaokemugen/karaokemugen-app.git' + 'karaokemugen-lib::git+https://lab.shelter.moe/karaokemugen/lib.git' + 'install.sh' + 'run.sh' + 'database-tweak.diff' + 'database.json') +noextract=() +md5sums=('SKIP' + 'SKIP' + '1673054cbeb6b80097dae4601cf35959' + '6efac0086021d7a7abcf637aae17cc99' + 'c1807f76ea2d800999910fe66e56fe73' + '0f887855e641ec949ce7c6b69d79ad1e') + +# Please refer to the 'USING VCS SOURCES' section of the PKGBUILD man page for +# a description of each element in the source array. + +pkgver() { + cd "$srcdir/${pkgname%-git}" + # Git, tags available + git describe --long --tags | sed -e 's/^v//' -e 's/\([^-]*-g\)/r\1/;s/-/./g' +} + +prepare() { + cd "$srcdir/${pkgname%-git}" + git submodule init + git config submodule.src/lib.url $srcdir/${pkgname%-git}-lib + git submodule update + patch --forward -p1 -i '../database-tweak.diff' +} + +build() { + cd "$srcdir/${pkgname%-git}" + + # Prepare dependencies + export HOME="$srcdir/$pkgname-home" + export XDG_CACHE_HOME="$srcdir/$pkgname-cache" + export npm_config_devdir="$srcdir/$pkgname-npm-dev" + export npm_config_cache="$srcdir/$pkgname-npm-cache" + yarn global add electron-builder + yarn install + yarn installFrontend + yarn installSystemPanel + # Build and package with electron-builder + export NODE_ENV='production' + yarn build + yarn buildFrontend + yarn buildSystemPanel + "$(yarn global dir)/node_modules/.bin/electron-builder" --dir +} + +package() { + cd "$srcdir/${pkgname%-git}" + + # Application itself + install -dm775 "$pkgdir/opt/${pkgname%-git}" + cp -r --no-preserve=ownership,mode packages/linux-unpacked/* "$pkgdir/opt/${pkgname%-git}/" + install -dm775 "$pkgdir/opt/${pkgname%-git}/app" + chmod -R 775 "$pkgdir/opt/${pkgname%-git}/" + + # Symlinks for configuration + install -dm775 "$pkgdir/etc/${pkgname%-git}" + cp "config.sample.yml" "$pkgdir/opt/${pkgname%-git}/app/config.sample.yml" + cp "$srcdir/database.json" "$pkgdir/opt/${pkgname%-git}/app/database.json" + ln -s "$pkgdir/opt/${pkgname%-git}/app/database.json" "$pkgdir/etc/${pkgname%-git}/database.json" + ln -s "$pkgdir/opt/${pkgname%-git}/app/config.yml" "$pkgdir/etc/${pkgname%-git}/config.yml" + + # License + install -dm755 "$pkgdir/usr/share/licenses/${pkgname%-git}" + cp --no-preserve=ownership,mode LICENSE.md "$pkgdir/usr/share/licenses/${pkgname%-git}/LICENSE" + + # Runtimes + install -dm755 "$pkgdir/usr/bin/" + cp "$srcdir/run.sh" "$pkgdir/usr/bin/karaokemugen" + cp "$srcdir/install.sh" "$pkgdir/usr/bin/karaokemugen-install" + chmod 755 "$pkgdir/usr/bin/karaokemugen" "$pkgdir/usr/bin/karaokemugen-install" +}
\ No newline at end of file diff --git a/database-tweak.diff b/database-tweak.diff new file mode 100644 index 000000000000..a2f45ce46b08 --- /dev/null +++ b/database-tweak.diff @@ -0,0 +1,13 @@ +diff --git a/config.sample.yml b/config.sample.yml +index 4dcd6cef..570333a1 100644 +--- a/config.sample.yml ++++ b/config.sample.yml +@@ -214,7 +214,7 @@ System: + Postgres: + Windows: app/bin/postgres/bin/ + OSX: app/bin/postgres/bin/ +- Linux: app/bin/postgres/bin/ ++ Linux: /usr/bin/ + Repositories: + - Name: kara.moe + Online: true diff --git a/database.json b/database.json new file mode 100644 index 000000000000..a77d8602b152 --- /dev/null +++ b/database.json @@ -0,0 +1,16 @@ +{ + "sql-file": true, + "defaultEnv": "prod", + "prod": { + "driver": "pg", + "user": "karaokemugen_app", + "password": "musubi", + "host": "localhost", + "database": "karaokemugen_app", + "port": 5432, + "schema": "public", + "superuser": "postgres", + "superuserPassword": null, + "bundledPostgresBinary": false + } +}
\ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 000000000000..af2598a483bd --- /dev/null +++ b/install.sh @@ -0,0 +1,137 @@ +#!/usr/bin/env bash + +# _ __ _ __ __ +# | |/ /__ _ _ _ __ _ ___| |_____ | \/ |_ _ __ _ ___ _ _ +# | ' </ _` | '_/ _` / _ \ / / -_) | |\/| | || / _` / -_) ' \ +# |_|\_\__,_|_| \__,_\___/_\_\___| |_| |_|\_,_\__, \___|_||_| +# |___/ + +# This script creates the database and do some checks to make +# Karaoke Mugen App working. +# From AUR package karaokemugen-git + +check_postgres() { + sudo -u postgres -g postgres pg_ctl status -D /var/lib/postgres/data &> /dev/null + if [ $? -eq 4 ]; then + echo -e "${_COL_YELLOW_}Postgres is not initialized, initializing..." + sudo -H -u postgres -g postgres initdb -D /var/lib/postgres/data + check_postgres + elif [ $? -eq 3 ]; then + echo -e "${_COL_YELLOW_}Postgres is not running, starting..." + sudo systemctl restart postgresql + check_postgres + else + echo -e "${_COL_GREEN_}Postgres seems OK." + fi +} + +check_mugen() { + if [ -f "/opt/karaokemugen/karaokemugen" ]; then + echo -e "${_COL_GREEN_}Karaoke Mugen is installed in /opt/karaokemugen." + else + echo -e "${_COL_BRED_}Karaoke Mugen is not installed in /opt/karaokemugen. Exiting." + exit 1 + fi +} + +setup_postgres() { + echo -e "${_BEGIN_}Creating the karaokemugen_app database..." + # Create the DB for Mugen + # Check if the DB already exists + sudo -u postgres -g postgres -H -- psql -d karaokemugen_app -c "" + if [ $? -eq 0 ]; then + echo -e "${_COL_YELLOW_}karaokemugen_app database is existing, do you want to keep its content or reset it?" + select dbch in "Keep data" "Reset database"; do + case $dbch in + "Keep data" ) echo -e "${_COL_GREEN_}karaokemugen_app database will be used." ; return 0;; # TODO : maybe do some integrity checks + "Reset database" ) sudo -u postgres -g postgres -G -- psql -c "DROP DATABASE karaokemugen_app; DROP ROLE IF EXISTS karaokemugen_app;";; + esac + done + fi + # Creating the database + sudo -u postgres -g postgres -H -- psql -c "CREATE DATABASE karaokemugen_app ENCODING 'UTF8';" + sudo -u postgres -g postgres -H -- psql -c "CREATE USER karaokemugen_app WITH ENCRYPTED PASSWORD 'musubi'; GRANT ALL PRIVILEGES ON DATABASE karaokemugen_app TO karaokemugen_app;" + sudo -u postgres -g postgres -H -- psql -d karaokemugen_app -c "CREATE EXTENSION unaccent;" + echo -e "${_COL_GREEN_}karaokemugen_app database created!" +} + +apply_config() { + # TODO : interactively ask for some options (location of medias, etc...) + sudo tee /opt/karaokemugen/config.yml > /dev/null <<EOT +App: + JwtSecret: $(uuid) +System: + Binaries: + Postgres: + Linux: /usr/bin/ +EOT +} + +create_system_group() { + if grep -q "^karaokemugen:" /etc/group; then + echo -e "${_BEGIN_}Using the existing ${_COL_YELLOW_}karaokemugen${_COL_BBLUE_} system group..." + else + echo -e "${_BEGIN_}Creating ${_COL_YELLOW_}karaokemugen${_COL_BBLUE_} system group..." + sudo groupadd karaokemugen + fi +} + +add_user_to_group() { + echo -e "${_BEGIN_}Adding you (${_COL_YELLOW_}$USER${_COL_BBLUE_}) to ${_COL_YELLOW_}karaokemugen${_COL_BBLUE_} group..." + if grep -q "^karaokemugen:" /etc/group; then + sudo usermod -a -G karaokemugen $USER + echo -e "${_COL_GREEN_}Successfully added ${_COL_YELLOW_}$USER${_COL_GREEN_} to ${_COL_YELLOW_}karaokemugen${_COL_GREEN_} group" + else + echo -e "${_BEGIN_}You need first to install Karaoke Mugen by executing ${_COL_YELLOW_}\`karaokemugen-install\`${_COL_BBLUE_}." + exit 1 + fi +} + +# use colors only if we have them +if [[ $(which tput > /dev/null 2>&1 && tput -T "${TERM}" colors || echo -n '0') -ge 8 ]] ; then + _COL_YELLOW_='\e[0;33m' + _COL_GREEN_='\e[0;32m' + _COL_LIGHTGREY_='\e[0;37m' + _COL_BRED_='\e[1;31m' + _COL_BBLUE_='\e[1;34m' + _COL_BWHITE_='\e[1;37m' + _COL_DEFAULT_='\e[0m' + _BEGIN_="${_COL_BRED_}-> ${_COL_BBLUE_}" +fi + +while getopts ":g" opt; do + case ${opt} in + g ) + #target=$OPTARG + echo -e "${_COL_YELLOW_}You may have to enter your sudo password" + add_user_to_group + echo -e "${_BEGIN_}Done! You need to restart your session to apply these changes." + exit 0 + ;; + \? ) + echo "Invalid option: $OPTARG" 1>&2 + exit 1 + ;; + esac +done +shift $((OPTIND -1)) + +echo -e "${_BEGIN_}Welcome to the Karaoke Mugen installer!" +echo -e "${_COL_YELLOW_}⚠️ You may have to enter your sudo password a couple times during this installation." +echo -e "${_COL_YELLOW_}This script may not work if you tweaked your PostgreSQL configuration." +echo -e "${_COL_YELLOW_}If you encounter any problems during installation, contact the package maintainer." +echo -e "${_COL_YELLOW_}The installation will begin in 5 seconds." +sleep 5 + +echo -e "${_BEGIN_}Doing some initial checks..." +check_postgres +check_mugen + +setup_postgres + +create_system_group +add_user_to_group +sudo chown -R root:karaokemugen /opt/karaokemugen + +apply_config + diff --git a/karaokemugen.install b/karaokemugen.install new file mode 100644 index 000000000000..d1aefa87b931 --- /dev/null +++ b/karaokemugen.install @@ -0,0 +1,10 @@ +post_install() { + echo "TIP: This package ships with tools to help you with Karaoke Mugen installation" + echo "- karaokemugen-install interactively creates the initial configuration and helps you with database setup." + echo "- karaokemugen launches the app with Electron UI." +} + +post_remove() { + # Eventually make the user think of resources directories + echo +}
\ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 000000000000..5640ca9d501e --- /dev/null +++ b/run.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +# _ __ _ __ __ +# | |/ /__ _ _ _ __ _ ___| |_____ | \/ |_ _ __ _ ___ _ _ +# | ' </ _` | '_/ _` / _ \ / / -_) | |\/| | || / _` / -_) ' \ +# |_|\_\__,_|_| \__,_\___/_\_\___| |_| |_|\_,_\__, \___|_||_| +# |___/ + +# This script runs Karaoke Mugen app (with some check to avoid some disasters) +# From AUR package karaokemugen-git + +# use colors only if we have them +if [[ $(which tput > /dev/null 2>&1 && tput -T "${TERM}" colors || echo -n '0') -ge 8 ]] ; then + _COL_YELLOW_='\e[0;33m' + _COL_LIGHTGREY_='\e[0;37m' + _COL_BRED_='\e[1;31m' + _COL_BBLUE_='\e[1;34m' + _COL_BWHITE_='\e[1;37m' + _COL_DEFAULT_='\e[0m' +fi + +# Check if the user is in the karaokemugen group +if groups | grep -q '\bkaraokemugen\b'; then + # Check if postgres is running + if lsof -Pi :5432 -sTCP:LISTEN -t >/dev/null ; then + echo "Starting Karaoke Mugen..." + else + echo -e "${_COL_YELLOW_}Postgres seems down... Trying to start Karaoke Mugen anyway." + fi + # Launch Karaoke Mugen + cd /opt/karaokemugen/ + PORTABLE_EXECUTABLE_DIR=/opt/karaokemugen /opt/karaokemugen/karaokemugen +else + echo -e "${_COL_BRED_}->${_COL_DEFAULT_} ${_COL_YELLOW_}WARNING:${_COL_DEFAULT_} You don't have the rights to access the Karaoke Mugen app" + echo -e "${_COL_BBLUE_}You can grant yourself the access to Karaoke Mugen by executing the ${_COL_YELLOW_}\`karaokemugen-install -g\`${_COL_BBLUE_} command" +fi |