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__ bind-addr: 127.0.0.1:__PORT__
auth: none auth: __AUTH__
cert: false cert: false
disable-telemetry: true disable-telemetry: true
disable-update-check: true disable-update-check: true

View file

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

View file

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

View file

@ -21,7 +21,11 @@ final_path=$(ynh_app_setting_get $app final_path)
#================================================= #=================================================
get__password() { 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() { 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) port=$(ynh_app_setting_get --app=$app --key=port)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
datadir=$(ynh_app_setting_get --app=$app --key=datadir) 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) 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 # 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 ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1
if ynh_compare_current_package_version -c le -v "3.11.0~ynh1"
# 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" ]
then 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" if [ "$extension_service_url" ] && [ "$extension_item_url" ]
ynh_app_setting_delete --app=$app --key="extension_item_url" then
fi 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" ] ynh_app_setting_delete --app=$app --key="extension_service_url"
then ynh_app_setting_delete --app=$app --key="extension_item_url"
ynh_print_warn --message="Custom enable-proposed-api detected. You'll have to enable them through application config panel." fi
ynh_print_warn --message="enable-proposed-api was set to: $enable_proposed_api"
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 fi
#================================================= #=================================================
@ -117,14 +123,15 @@ ynh_add_nginx_config
ynh_script_progression --message="Updating a configuration file..." --time --weight=1 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="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 then
echo "hashed-password: $hashed_password" >> "$final_path/config.py" echo "hashed-password: $hashed_password" >> "$final_path/config.yaml"
fi fi
chmod 440 "$final_path/config.yaml" chmod 440 "$final_path/config.yaml" "$final_path/code-server.env"
chown root:$admin "$final_path/config.yaml" chown root:$admin "$final_path/config.yaml" "$final_path/code-server.env"
#================================================= #=================================================
# SETUP SYSTEMD # SETUP SYSTEMD