1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/code-server_ynh.git synced 2024-09-03 18:16:28 +02:00
This commit is contained in:
Tagada 2022-01-16 19:45:31 +00:00
parent cf401f7447
commit 67211cd546
6 changed files with 62 additions and 33 deletions

View file

@ -1 +1 @@
EXTENSIONS_GALLERY='{"serviceUrl": "https://open-vsx.org/vscode/gallery","itemUrl": "https://open-vsx.org/vscode/item"}'
EXTENSIONS_GALLERY='__EXTENSIONS_GALLERY__'

View file

@ -1,5 +1,5 @@
bind-addr: 127.0.0.1:__PORT__
auth: none
auth: __AUTH__
cert: false
disable-telemetry: true
disable-update-check: true

View file

@ -9,21 +9,23 @@ version = "1.0"
[main]
name = "Main configuration"
services = ["__APP__"]
[main.auth]
name = "Authentication"
[main.auth.type]
[main.auth.auth]
ask = "Auth type"
type = "select"
choices = ["none", "password"]
default = "none"
bind: ":/opt/yunohost/__APP__/config.yaml"
optional = false
bind = ":/opt/yunohost/__APP__/config.yaml"
[main.auth.password]
ask = "Password"
type = "password"
visible = "main.auth.type == 'password'"
optional = true
visible = "auth == 'password'"
[main.extensions]
name = "Extensions"
@ -33,10 +35,10 @@ services = ["__APP__"]
ask = "Extensions Gallery"
type = "string"
example = "{\"serviceUrl\": \"https://open-vsx.org/vscode/gallery\",\"itemUrl\": \"https://open-vsx.org/vscode/item\"}"
optional = false
bind = ":/opt/yunohost/__APP__/code-server.env"
[main.extensions.enable_proposed_api]
ask = "Enable Proposed API"
type = "tags"
optional = true
bind = "enable-proposed-api:/opt/yunohost/__APP__/config.yaml"

View file

@ -4,6 +4,9 @@
# COMMON VARIABLES
#=================================================
extensions_gallery="{\"serviceUrl\": \"https://open-vsx.org/vscode/gallery\",\"itemUrl\": \"https://open-vsx.org/vscode/item\"}"
auth="none"
#=================================================
# PERSONAL HELPERS
#=================================================

View file

@ -21,7 +21,11 @@ final_path=$(ynh_app_setting_get $app final_path)
#=================================================
get__password() {
echo YNH_NULL
echo ""
}
get__enable_proposed_api() {
echo "$(awk '/enable-proposed-api:/ {print $2}' $final_path/config.yaml)"
}
#=================================================
@ -33,13 +37,26 @@ get__password() {
#=================================================
set__password() {
hashed_password="$(printf "$password" | sha256sum | cut -d' ' -f1)"
if [ $password ]
then
hashed_password="$(printf "$password" | sha256sum | cut -d' ' -f1)"
sed -i "/hashed-password:.*/d" "$final_path/config.py"
sed -i "/hashed-password:.*/d" "$final_path/config.yaml"
echo "hashed-password: $hashed_password" >> "$final_path/config.py"
echo "hashed-password: $hashed_password" >> "$final_path/config.yaml"
ynh_store_file_checksum --file="$final_path/config.yaml"
ynh_app_setting_set $app hashed_password $hashed_password
ynh_app_setting_set $app hashed_password "$hashed_password"
fi
}
set__enable_proposed_api() {
sed -i "/enable-proposed-api:.*/d" "$final_path/config.yaml"
echo "enable-proposed-api: $enable_proposed_api" >> "$final_path/config.yaml"
ynh_store_file_checksum --file="$final_path/config.yaml"
ynh_app_setting_set $app enable_proposed_api "$enable_proposed_api"
}
#=================================================

View file

@ -21,8 +21,10 @@ admin=$(ynh_app_setting_get --app=$app --key=admin)
port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
auth_type=$(ynh_app_setting_get --app=$app --key=auth_type)
auth=$(ynh_app_setting_get --app=$app --key=auth)
hashed_password=$(ynh_app_setting_get --app=$app --key=hashed_password)
enable_proposed_api=$(ynh_app_setting_get --app=$app --key="enable_proposed_api")
extensions_gallery=$(ynh_app_setting_get --app=$app --key="extensions_gallery")
#=================================================
# CHECK VERSION
@ -58,27 +60,31 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
# Upgrade from 3.11.0~ynh1
extension_service_url=$(ynh_app_setting_get --app=$app --key="extension_service_url")
extension_item_url=$(ynh_app_setting_get --app=$app --key="extension_item_url")
if [ "$extension_service_url" ] && [ "$extension_item_url" ]
if ynh_compare_current_package_version -c le -v "3.11.0~ynh1"
then
echo "EXTENSIONS_GALLERY='{\"serviceUrl\": \"$extension_service_url\",\"itemUrl\": \"$extension_item_url\"}'" > "$final_path/code-server.env"
extension_service_url=$(ynh_app_setting_get --app=$app --key="extension_service_url")
extension_item_url=$(ynh_app_setting_get --app=$app --key="extension_item_url")
ynh_app_setting_delete --app=$app --key="extension_service_url"
ynh_app_setting_delete --app=$app --key="extension_item_url"
fi
if [ "$extension_service_url" ] && [ "$extension_item_url" ]
then
extensions_gallery="{\"serviceUrl\": \"$extension_service_url\",\"itemUrl\": \"$extension_item_url\"}"
enable_proposed_api=$(ynh_app_setting_get --app=$app --key="enable_proposed_api")
ynh_app_setting_set --app=$app --key="extensions_gallery" --value="$extensions_gallery"
if [ "$enable_proposed_api" ]
then
ynh_print_warn --message="Custom enable-proposed-api detected. You'll have to enable them through application config panel."
ynh_print_warn --message="enable-proposed-api was set to: $enable_proposed_api"
ynh_app_setting_delete --app=$app --key="extension_service_url"
ynh_app_setting_delete --app=$app --key="extension_item_url"
fi
ynh_app_setting_delete --app=$app --key="enable_proposed_api"
if [ "$enable_proposed_api" ]
then
ynh_print_warn --message="Custom enable-proposed-api. You have to enable again them through application config panel."
ynh_print_warn --message="enable-proposed-api was set to: $enable_proposed_api"
ynh_app_setting_delete --app=$app --key="enable_proposed_api"
fi
ynh_secure_remove --file=$final_path
mkdir -p $final_path
fi
#=================================================
@ -117,14 +123,15 @@ ynh_add_nginx_config
ynh_script_progression --message="Updating a configuration file..." --time --weight=1
ynh_add_config --template="config.yaml" --destination="$final_path/config.yaml"
ynh_add_config --template="code-server.env" --destination="$final_path/code-server.env"
if [ $auth == "password" ]
if [ "$auth" == "password" ]
then
echo "hashed-password: $hashed_password" >> "$final_path/config.py"
echo "hashed-password: $hashed_password" >> "$final_path/config.yaml"
fi
chmod 440 "$final_path/config.yaml"
chown root:$admin "$final_path/config.yaml"
chmod 440 "$final_path/config.yaml" "$final_path/code-server.env"
chown root:$admin "$final_path/config.yaml" "$final_path/code-server.env"
#=================================================
# SETUP SYSTEMD