1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/photoview_ynh.git synced 2024-09-03 20:05:55 +02:00

Fix build

This commit is contained in:
Jules Bertholet 2022-01-02 02:53:43 -05:00
parent 1ba884530a
commit 447e4f432f
2 changed files with 152 additions and 157 deletions

View file

@ -1,8 +0,0 @@
{
"markdownlint.config": {
"MD028": false,
"MD025": {
"front_matter_title": ""
}
}
}

View file

@ -25,16 +25,16 @@ function setup_sources {
function build_libheif { function build_libheif {
pushd "$final_path/libheif" || ynh_die pushd "$final_path/libheif" || ynh_die
chown -R $app:$app "$final_path/libheif" chown -R $app:$app "$final_path/libheif"
mkdir -p "$final_path/local" mkdir -p "$final_path/local"
chown -R $app:$app "$final_path/libheif" chown -R $app:$app "$final_path/libheif"
chown -R $app:$app "$final_path/local" chown -R $app:$app "$final_path/local"
sudo -u $app "$final_path/libheif/autogen.sh" 2>&1 sudo -u $app "$final_path/libheif/autogen.sh" 2>&1
sudo -u $app "$final_path/libheif/configure" --prefix="$final_path/local" --disable-gdk-pixbuf 2>&1 sudo -u $app "$final_path/libheif/configure" --prefix="$final_path/local" --disable-gdk-pixbuf 2>&1
make clean 2>&1 make clean 2>&1
make 2>&1 make 2>&1
make install 2>&1 make install 2>&1
make clean 2>&1 make clean 2>&1
popd || ynh_die popd || ynh_die
set_permissions set_permissions
@ -55,13 +55,15 @@ function build_api {
set_go_vars set_go_vars
pushd "$final_path/api" || ynh_die pushd "$final_path/api" || ynh_die
chown -R $app:$app "$final_path" chown -R $app:$app "$final_path"
set +e ; for i in {1..5}; do set +e
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go mod download 2>&1 && break for i in {1..5}; do
sleep 5 sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go mod download 2>&1 && break
done; set -e sleep 5
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go install github.com/mattn/go-sqlite3 github.com/Kagami/go-face 2>&1 done
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version go build -o photoview "$final_path/api" 2>&1 set -e
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version CGO_ENABLED=1 go install github.com/mattn/go-sqlite3 github.com/Kagami/go-face 2>&1
sudo -u $app env "PATH=$go_path_full" "LIBRARY_PATH=$heif_lib_path" "LD_LIBRARY_PATH=$heif_ld_lib_path" "CGO_CFLAGS=$heif_cgo_cflags" GOENV_VERSION=$go_version go build -o photoview "$final_path/api" 2>&1
popd || ynh_die popd || ynh_die
cp -T "$final_path/api/photoview" "$final_path/output/photoview" cp -T "$final_path/api/photoview" "$final_path/output/photoview"
@ -81,17 +83,23 @@ function build_ui {
pushd "$ui_path" || ynh_die pushd "$ui_path" || ynh_die
chown -R $app:$app $final_path chown -R $app:$app $final_path
sudo -u $app touch $ui_path/.yarnrc sudo -u $app touch $ui_path/.yarnrc
sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" import 2>&1
sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add husky 2>&1
sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" install 2>&1 sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" install 2>&1
sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add graphql --ignore-engines 2>&1 sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" add graphql --ignore-engines 2>&1
grep -q "build complete" <((sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" run build -- --public-url "$path_url" 2>&1 & echo $! >&3 ) 3>pid) ; kill "$(<pid)" sudo -u $app env "PATH=$node_path" yarn --cache-folder "$ui_path/yarn-cache" --use-yarnrc "$ui_path/.yarnrc" run build --public-url "$path_url" 2>&1
popd || ynh_die popd || ynh_die
cp -rT "$final_path/ui/dist" "$final_path/output/ui" cp -rT "$final_path/ui/build" "$final_path/output/ui"
set_permissions set_permissions
} }
function set_node_vars { function set_node_vars {
nodejs_version=$(ynh_app_setting_get --app=$app --key=nodejs_version)
if [ $nodejs_version -ne 16 ]; then
ynh_exec_warn_less ynh_remove_nodejs
fi
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=16 ynh_exec_warn_less ynh_install_nodejs --nodejs_version=16
ynh_use_nodejs ynh_use_nodejs
node_path=$nodejs_path:$(sudo -u $app sh -c 'echo $PATH') node_path=$nodejs_path:$(sudo -u $app sh -c 'echo $PATH')
@ -166,30 +174,30 @@ export GOENV_ROOT="$goenv_install_dir"
# usage: ynh_use_go # usage: ynh_use_go
# #
# Requires YunoHost version 3.2.2 or higher. # Requires YunoHost version 3.2.2 or higher.
ynh_use_go () { ynh_use_go() {
go_version=$(ynh_app_setting_get --app=$app --key=go_version) go_version=$(ynh_app_setting_get --app=$app --key=go_version)
# Get the absolute path of this version of Go # Get the absolute path of this version of Go
go_path="$go_version_path/$go_version/bin" go_path="$go_version_path/$go_version/bin"
# Allow alias to be used into bash script # Allow alias to be used into bash script
shopt -s expand_aliases shopt -s expand_aliases
# Create an alias for the specific version of Go and a variable as fallback # Create an alias for the specific version of Go and a variable as fallback
ynh_go="$go_path/go" ynh_go="$go_path/go"
alias ynh_go="$ynh_go" alias ynh_go="$ynh_go"
# Load the path of this version of Go in $PATH # Load the path of this version of Go in $PATH
if [[ :$PATH: != *":$go_path"* ]]; then if [[ :$PATH: != *":$go_path"* ]]; then
PATH="$go_path:$PATH" PATH="$go_path:$PATH"
fi fi
# Create an alias to easily load the PATH # Create an alias to easily load the PATH
ynh_go_load_path="PATH=$PATH" ynh_go_load_path="PATH=$PATH"
# Sets the local application-specific Go version # Sets the local application-specific Go version
pushd $final_path pushd $final_path
$goenv_install_dir/bin/goenv local $go_version $goenv_install_dir/bin/goenv local $go_version
popd popd
} }
# Install a specific version of Go # Install a specific version of Go
@ -208,94 +216,94 @@ ynh_use_go () {
# | arg: -v, --go_version= - Version of go to install. # | arg: -v, --go_version= - Version of go to install.
# #
# Requires YunoHost version 3.2.2 or higher. # Requires YunoHost version 3.2.2 or higher.
ynh_install_go () { ynh_install_go() {
# Declare an array to define the options of this helper. # Declare an array to define the options of this helper.
local legacy_args=v local legacy_args=v
local -A args_array=( [v]=go_version= ) local -A args_array=([v]=go_version=)
local go_version local go_version
# Manage arguments with getopts # Manage arguments with getopts
ynh_handle_getopts_args "$@" ynh_handle_getopts_args "$@"
# Load goenv path in PATH # Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH" local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Go prior installation # Remove /usr/local/bin in PATH in case of Go prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Move an existing Go binary, to avoid to block goenv # Move an existing Go binary, to avoid to block goenv
test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv test -x /usr/bin/go && mv /usr/bin/go /usr/bin/go_goenv
# Install or update goenv # Install or update goenv
goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)" goenv="$(command -v goenv $goenv_install_dir/bin/goenv | head -1)"
if [ -n "$goenv" ]; then if [ -n "$goenv" ]; then
ynh_print_info --message="goenv already seems installed in \`$goenv'." ynh_print_info --message="goenv already seems installed in \`$goenv'."
pushd "${goenv%/*/*}" pushd "${goenv%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then if git remote -v 2>/dev/null | grep "https://github.com/syndbg/goenv.git"; then
echo "Trying to update with git..." echo "Trying to update with git..."
git pull -q --tags origin master git pull -q --tags origin master
cd .. cd ..
ynh_go_try_bash_extension ynh_go_try_bash_extension
fi
popd
else
ynh_print_info --message="Installing goenv with git..."
mkdir -p $goenv_install_dir
pushd $goenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/syndbg/goenv.git > /dev/null 2>&1
git checkout -q -b master origin/master
ynh_go_try_bash_extension
goenv=$goenv_install_dir/bin/goenv
popd
fi fi
popd
else
ynh_print_info --message="Installing goenv with git..."
mkdir -p $goenv_install_dir
pushd $goenv_install_dir
git init -q
git remote add -f -t master origin https://github.com/syndbg/goenv.git >/dev/null 2>&1
git checkout -q -b master origin/master
ynh_go_try_bash_extension
goenv=$goenv_install_dir/bin/goenv
popd
fi
goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)" goenv_latest="$(command -v "$goenv_install_dir"/plugins/*/bin/goenv-latest goenv-latest | head -1)"
if [ -n "$goenv_latest" ]; then if [ -n "$goenv_latest" ]; then
ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'." ynh_print_info --message="\`goenv latest' command already available in \`$goenv_latest'."
pushd "${goenv_latest%/*/*}" pushd "${goenv_latest%/*/*}"
if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then if git remote -v 2>/dev/null | grep "https://github.com/momo-lab/xxenv-latest.git"; then
ynh_print_info --message="Trying to update xxenv-latest with git..." ynh_print_info --message="Trying to update xxenv-latest with git..."
git pull -q origin master git pull -q origin master
fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${goenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest"
fi fi
popd
else
ynh_print_info --message="Installing xxenv-latest with git..."
mkdir -p "${goenv_install_dir}/plugins"
git clone -q https://github.com/momo-lab/xxenv-latest.git "${goenv_install_dir}/plugins/xxenv-latest"
fi
# Enable caching # Enable caching
mkdir -p "${goenv_install_dir}/cache" mkdir -p "${goenv_install_dir}/cache"
# Create shims directory if needed # Create shims directory if needed
mkdir -p "${goenv_install_dir}/shims" mkdir -p "${goenv_install_dir}/shims"
# Restore /usr/local/bin in PATH # Restore /usr/local/bin in PATH
PATH=$CLEAR_PATH PATH=$CLEAR_PATH
# And replace the old Go binary # And replace the old Go binary
test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go test -x /usr/bin/go_goenv && mv /usr/bin/go_goenv /usr/bin/go
# Install the requested version of Go # Install the requested version of Go
local final_go_version=$(goenv latest --print $go_version) local final_go_version=$(goenv latest --print $go_version)
ynh_print_info --message="Installation of Go-$final_go_version" ynh_print_info --message="Installation of Go-$final_go_version"
goenv install --skip-existing $final_go_version goenv install --skip-existing $final_go_version
# Store go_version into the config of this app # Store go_version into the config of this app
ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version ynh_app_setting_set --app=$YNH_APP_INSTANCE_NAME --key=go_version --value=$final_go_version
# Cleanup Go versions # Cleanup Go versions
ynh_cleanup_go ynh_cleanup_go
# Set environment for Go users # Set environment for Go users
echo "#goenv echo "#goenv
export GOENV_ROOT=$goenv_install_dir export GOENV_ROOT=$goenv_install_dir
export PATH=\"$goenv_install_dir/bin:$PATH\" export PATH=\"$goenv_install_dir/bin:$PATH\"
eval \"\$(goenv init -)\" eval \"\$(goenv init -)\"
#goenv" > /etc/profile.d/goenv.sh #goenv" >/etc/profile.d/goenv.sh
# Load the environment # Load the environment
eval "$(goenv init -)" eval "$(goenv init -)"
} }
# Remove the version of Go used by the app. # Remove the version of Go used by the app.
@ -303,20 +311,20 @@ eval \"\$(goenv init -)\"
# This helper will also cleanup Go versions # This helper will also cleanup Go versions
# #
# usage: ynh_remove_go # usage: ynh_remove_go
ynh_remove_go () { ynh_remove_go() {
local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version) local go_version=$(ynh_app_setting_get --app=$YNH_APP_INSTANCE_NAME --key=go_version)
# Load goenv path in PATH # Load goenv path in PATH
local CLEAR_PATH="$goenv_install_dir/bin:$PATH" local CLEAR_PATH="$goenv_install_dir/bin:$PATH"
# Remove /usr/local/bin in PATH in case of Go prior installation # Remove /usr/local/bin in PATH in case of Go prior installation
PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@') PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
# Remove the line for this app # Remove the line for this app
ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version ynh_app_setting_delete --app=$YNH_APP_INSTANCE_NAME --key=go_version
# Cleanup Go versions # Cleanup Go versions
ynh_cleanup_go ynh_cleanup_go
} }
# Remove no more needed versions of Go used by the app. # Remove no more needed versions of Go used by the app.
@ -326,39 +334,34 @@ ynh_remove_go () {
# If no app uses Go, goenv will be also removed. # If no app uses Go, goenv will be also removed.
# #
# usage: ynh_cleanup_go # usage: ynh_cleanup_go
ynh_cleanup_go () { ynh_cleanup_go() {
# List required Go versions # List required Go versions
local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$') local installed_apps=$(yunohost app list | grep -oP 'id: \K.*$')
local required_go_versions="" local required_go_versions=""
for installed_app in $installed_apps for installed_app in $installed_apps; do
do local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version")
local installed_app_go_version=$(ynh_app_setting_get --app=$installed_app --key="go_version") if [[ $installed_app_go_version ]]; then
if [[ $installed_app_go_version ]] required_go_versions="${installed_app_go_version}\n${required_go_versions}"
then
required_go_versions="${installed_app_go_version}\n${required_go_versions}"
fi
done
# Remove no more needed Go versions
local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/')
for installed_go_version in $installed_go_versions
do
if ! `echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1`
then
ynh_print_info --message="Removing of Go-$installed_go_version"
$goenv_install_dir/bin/goenv uninstall --force $installed_go_version
fi
done
# If none Go version is required
if [[ ! $required_go_versions ]]
then
# Remove goenv environment configuration
ynh_print_info --message="Removing of goenv"
ynh_secure_remove --file="$goenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/goenv.sh"
fi fi
done
# Remove no more needed Go versions
local installed_go_versions=$(goenv versions --bare --skip-aliases | grep -Ev '/')
for installed_go_version in $installed_go_versions; do
if ! $(echo ${required_go_versions} | grep "${installed_go_version}" 1>/dev/null 2>&1); then
ynh_print_info --message="Removing of Go-$installed_go_version"
$goenv_install_dir/bin/goenv uninstall --force $installed_go_version
fi
done
# If none Go version is required
if [[ ! $required_go_versions ]]; then
# Remove goenv environment configuration
ynh_print_info --message="Removing of goenv"
ynh_secure_remove --file="$goenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/goenv.sh"
fi
} }
#================================================= #=================================================