1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/garage_ynh.git synced 2024-09-03 18:36:32 +02:00
garage_ynh/scripts/config

84 lines
2.1 KiB
Bash

#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
data_dir=$(ynh_app_setting_get $app data_dir)
secret_node_id=$(ynh_app_setting_get $app data_dir)
if ! system_is_inside_container
then
nbd_index=$(cat $data_dir/nbd_index)
fi
set__weight() {
if system_is_inside_container
then
systemctl stop $app
old_weight="$(ynh_app_setting_get --app=$app --key=weight)"
if [ $old_weight -le $weight ]
then
qemu-img resize $data_dir/garage_data.qcow2 "$weight"G
qemu-nbd --connect /dev/nbd$nbd_index $data_dir/garage_data.qcow2
e2fsck -f -y /dev/nbd$nbd_index
resize2fs /dev/nbd$nbd_index
qemu-nbd --disconnect /dev/nbd$nbd_index
else
e2fsck -f -y /dev/nbd0
resize2fs /dev/nbd$nbd_index $weightG
qemu-nbd --disconnect /dev/nbd$nbd_index
qemu-img resize --shrink $data_dir/garage_data.qcow2 "$weight"G
fi
$install_dir/umount_disk.sh
systemctl start $app
sleep 3
fi
$garage layout assign $secret_node_id -c $weight 2>/dev/null
garage_layout_apply
ynh_app_setting_set --app=$app --key=weight --value=$weight
}
set__bootstrap_peers() {
garage_connect "$bootstrap_peers" 2>/dev/null
garage_layout_apply
ynh_app_setting_set --app=$app --key=bootstrap_peers --value=$bootstrap_peers
}
get__node() {
cat << EOF
ask:
en: "**Node Id** : $($garage node id -q) \n
*This id is a sensitive information and should not be shared with anyone else than other nodes of the cluster*"
style: "info"
EOF
}
get__status() {
status=$($garage status 2> /dev/null | sed -E 's/([a-z0-9]{16})/\n**\1**/g')
cat << EOF
ask:
en: "**Current garage layout**: \n
$status"
EOF
if echo "$status" | grep -q "FAILED NODES\|garage layout show"
then
cat << EOF
style: "danger"
EOF
else
cat << EOF
style: "success"
EOF
fi
}
#=================================================
# GENERIC FINALIZATION
#=================================================
ynh_app_config_run $1