yunohost-gitea_ynh/scripts/_common.sh

71 lines
2.1 KiB
Bash
Raw Normal View History

2018-02-25 21:45:24 +01:00
#=================================================
# SET ALL CONSTANTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
dbname=$app
2022-04-01 22:54:46 +02:00
db_user=$app
2018-02-25 21:45:24 +01:00
final_path="/opt/$app"
2022-04-23 19:40:27 +02:00
datadir="/home/yunohost.app/$app"
repos_path="$datadir/repositories"
data_path="$datadir/data"
ssh_path="$datadir/.ssh"
2018-02-25 21:45:24 +01:00
# Detect the system architecture to download the right tarball
# NOTE: `uname -m` is more accurate and universal than `arch`
# See https://en.wikipedia.org/wiki/Uname
2020-12-07 16:10:16 +01:00
if [ -n "$(uname -m | grep arm64)" ] || [ -n "$(uname -m | grep aarch64)" ]; then
architecture="arm64"
elif [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
2018-02-25 21:45:24 +01:00
elif [ -n "$(uname -m | grep 86)" ]; then
2020-12-07 16:10:16 +01:00
architecture="i386"
2019-02-15 16:00:22 +01:00
elif [ -n "$(uname -m | grep armv7)" ]; then
2020-12-07 16:10:16 +01:00
architecture="armv7"
2018-02-25 21:45:24 +01:00
elif [ -n "$(uname -m | grep arm)" ]; then
2020-12-07 16:10:16 +01:00
architecture="arm"
2018-02-25 21:45:24 +01:00
else
2019-08-01 14:01:59 +02:00
ynh_die --message "Unable to detect your achitecture, please open a bug describing \
2018-02-25 21:45:24 +01:00
your hardware and the result of the command \"uname -m\"." 1
fi
#=================================================
# DEFINE ALL COMMON FONCTIONS
#=================================================
create_dir() {
mkdir -p "$final_path/data"
mkdir -p "$final_path/custom/conf"
2022-04-23 19:40:27 +02:00
mkdir -p "$ssh_path"
mkdir -p "$repos_path"
mkdir -p "$data_path/avatars"
mkdir -p "$data_path/attachments"
2018-02-25 21:45:24 +01:00
mkdir -p "/var/log/$app"
}
config_nginx() {
if [ "$path_url" != "/" ]
then
2019-09-10 21:26:06 +02:00
ynh_replace_string --match_string "^#sub_path_only" --replace_string "" --target_file "../conf/nginx.conf"
2018-02-25 21:45:24 +01:00
fi
ynh_add_nginx_config
}
2018-04-24 16:41:36 +02:00
config_gitea() {
2019-02-15 19:56:46 +01:00
ssh_port=$(grep -P "Port\s+\d+" /etc/ssh/sshd_config | grep -P -o "\d+")
2022-04-01 22:54:46 +02:00
ynh_add_config --template="app.ini" --destination="$final_path/custom/conf/app.ini"
2018-02-25 21:45:24 +01:00
}
set_permission() {
chown -R $app:$app "$final_path"
2022-04-23 19:40:27 +02:00
chown -R $app:$app "$datadir"
2018-02-25 21:45:24 +01:00
chown -R $app:$app "/var/log/$app"
2018-06-19 10:18:50 +02:00
2018-02-25 21:45:24 +01:00
chmod u=rwX,g=rX,o= "$final_path"
2018-06-19 10:18:50 +02:00
chmod u=rwx,g=rx,o= "$final_path/gitea"
2019-01-25 15:45:19 +01:00
chmod u=rwx,g=rx,o= "$final_path/custom/conf/app.ini"
2022-04-23 19:40:27 +02:00
chmod u=rwX,g=rX,o= "$datadir"
2018-02-25 21:45:24 +01:00
chmod u=rwX,g=rX,o= "/var/log/$app"
2022-10-11 21:48:39 +02:00
chmod u=rwx,g=,o= "$ssh_path"
2018-02-25 21:45:24 +01:00
}