yunohost-gitea_ynh/scripts/_common.sh

95 lines
3.6 KiB
Bash
Raw Normal View History

2018-02-25 21:45:24 +01:00
#=================================================
# SET ALL CONSTANTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
dbname=$app
dbuser=$app
final_path="/opt/$app"
DATADIR="/home/$app"
REPO_PATH="$DATADIR/repositories"
DATA_PATH="$DATADIR/data"
# 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
if [ -n "$(uname -m | grep 64)" ]; then
architecture="x86-64"
elif [ -n "$(uname -m | grep 86)" ]; then
architecture="i386"
2019-02-15 16:00:22 +01:00
elif [ -n "$(uname -m | grep armv7)" ]; then
architecture="armv7"
2018-02-25 21:45:24 +01:00
elif [ -n "$(uname -m | grep arm)" ]; then
architecture="arm"
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"
mkdir -p "$REPO_PATH"
mkdir -p "$DATA_PATH/avatars"
mkdir -p "$DATA_PATH/attachments"
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+")
2019-06-09 21:05:14 +02:00
ynh_backup_if_checksum_is_different --file "$final_path/custom/conf/app.ini"
2018-02-25 21:45:24 +01:00
2018-06-07 12:45:26 +02:00
cp ../conf/app.ini "$final_path/custom/conf"
2018-06-07 14:42:39 +02:00
usermod -s /bin/bash $app
2018-02-25 21:45:24 +01:00
if [ "$path_url" = "/" ]
then
2019-06-09 21:05:14 +02:00
ynh_replace_string --match_string __URL__ --replace_string "$domain" --target_file "$final_path/custom/conf/app.ini"
2018-02-25 21:45:24 +01:00
else
2019-09-10 21:26:06 +02:00
ynh_replace_string --match_string __URL__ --replace_string "$domain${path_url%/}" --target_file "$final_path/custom/conf/app.ini"
2018-02-25 21:45:24 +01:00
fi
2019-06-09 21:05:14 +02:00
ynh_replace_string --match_string __REPOS_PATH__ --replace_string "$REPO_PATH" --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __DB_PASSWORD__ --replace_string "$dbpass" --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __DB_USER__ --replace_string "$dbuser" --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __DOMAIN__ --replace_string "$domain" --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __KEY__ --replace_string "$key" --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __DATA_PATH__ --replace_string "$DATA_PATH" --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __PORT__ --replace_string $port --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __APP__ --replace_string $app --target_file "$final_path/custom/conf/app.ini"
ynh_replace_string --match_string __SSH_PORT__ --replace_string $ssh_port --target_file "$final_path/custom/conf/app.ini"
2018-02-25 21:45:24 +01:00
2019-06-09 21:05:14 +02:00
ynh_store_file_checksum --file "$final_path/custom/conf/app.ini"
2018-02-25 21:45:24 +01:00
}
set_permission() {
chown -R $app:$app "$final_path"
chown -R $app:$app "/home/$app"
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"
2018-02-25 21:45:24 +01:00
chmod u=rwX,g=rX,o= "/home/$app"
chmod u=rwX,g=rX,o= "/var/log/$app"
}
set_access_settings() {
2020-03-25 16:33:19 +01:00
if [ "$is_public" == '1' ];
then
2020-03-25 16:33:19 +01:00
ynh_permission_update --permission "main" --add "visitors"
fi
}