generated from YunoHost/example_ynh
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path_common.sh
108 lines (90 loc) · 4.1 KB
/
_common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
#=================================================
# COMMON VARIABLES
#=================================================
ruby_version="3.2.2"
nodejs_version="18"
# Workaround for Mastodon on Bullseye
# See https://github.com/mastodon/mastodon/issues/15751#issuecomment-873594463
if [ "$(lsb_release --codename --short)" = "bullseye" ]; then
case $YNH_ARCH in
amd64) arch="x86_64";;
arm64) arch="aarch64";;
armel|armhf) arch="arm";;
i386) arch="i386";;
esac
ld_preload="LD_PRELOAD=/usr/lib/$arch-linux-gnu/libjemalloc.so"
else
ld_preload=""
fi
#=================================================
# PERSONAL HELPERS
#=================================================
check_password_policy() {
password="$1"
# 12 caractères minimum, au moins une lettre majuscule, une lettre minuscule, un chiffre et un caractère spécial
msg=""
if (( ${#password} < 10 )); then
msg="is too short"
elif [[ $password != *[[:digit:]]* ]]; then
msg="does not contain any digit"
elif [[ $password != *[[:lower:]]* ]]; then
msg="does not contain any lower case letter"
elif [[ $password != *[[:upper:]]* ]]; then
msg="does not contain any upper case letter"
elif [[ "$password" =~ ^[0-9a-zA-Z]*$ ]]; then
msg="does not contain any special character"
fi
if [ -n "$msg" ]; then
ynh_die "Password should have min 12 chars, at least one lowercase, one uppercase, one digit and one special character, but it $msg."
fi
}
env_ruby() {
ynh_exec_as "$app" "$ynh_ruby_load_path" "$@"
}
fabmanager_build_ruby() {
pushd "$install_dir"
ynh_use_ruby
$ynh_gem update --system --no-document
$ynh_gem install bundler rake --no-document
env_ruby bin/bundle config --global frozen 1
env_ruby bin/bundle config set without 'development test doc'
env_ruby bin/bundle config set path 'vendor/bundle'
env_ruby bin/bundle install
env_ruby bin/bundle binstubs --all
popd
}
fabmanager_build_ui() {
pushd "$install_dir"
ynh_use_nodejs
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn install
env_ruby bash -c "set -a; source '$install_dir/.env'; set +a ; RAILS_ENV=production bin/bundle exec rake assets:precompile"
ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" yarn cache clean --all
popd
}
fabmanager_seed_db() {
pushd "$install_dir"
ynh_replace_string --match_string="DateTime.current" --replace_string="DateTime.current - 1.days" --target_file="$install_dir/db/seeds.rb"
# Need superuser for the extensions configuration…
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
env_ruby bash -c "set -a; source '$install_dir/.env'; set +a ; RAILS_ENV=production ADMIN_EMAIL='$admin_mail' ADMIN_PASSWORD='$password' bin/bundle exec rails db:schema:load"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
env_ruby bash -c "set -a; source '$install_dir/.env'; set +a ; RAILS_ENV=production ADMIN_EMAIL='$admin_mail' ADMIN_PASSWORD='$password' bin/bundle exec rails db:seed"
popd
}
fabmanager_migrate_db() {
pushd "$install_dir"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH SUPERUSER;"
env_ruby bash -c "set -a; source '$install_dir/.env'; set +a ; RAILS_ENV=production bin/bundle exec rails db:migrate"
ynh_psql_execute_as_root --database="$db_name" --sql="ALTER USER $db_user WITH NOSUPERUSER;"
popd
}
fabmanager_configure_email() {
ynh_psql_execute_as_root --database="$db_name" --sql="INSERT INTO history_values (setting_id,value, created_at,updated_at) VALUES ((select id from settings where name='email_from'), '${mail_user}@${mail_domain}', NOW(),NOW());"
}
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================