2
0

_common.sh 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. #!/bin/bash
  2. #=================================================
  3. # BACKUP
  4. #=================================================
  5. HUMAN_SIZE () { # Transforme une taille en Ko en une taille lisible pour un humain
  6. human=$(numfmt --to=iec --from-unit=1K $1)
  7. echo $human
  8. }
  9. CHECK_SIZE () { # Vérifie avant chaque backup que l'espace est suffisant
  10. file_to_analyse=$1
  11. backup_size=$(du --summarize "$file_to_analyse" | cut -f1)
  12. free_space=$(df --output=avail "/home/yunohost.backup" | sed 1d)
  13. if [ $free_space -le $backup_size ]
  14. then
  15. ynh_print_err "Espace insuffisant pour sauvegarder $file_to_analyse."
  16. ynh_print_err "Espace disponible: $(HUMAN_SIZE $free_space)"
  17. ynh_die "Espace nécessaire: $(HUMAN_SIZE $backup_size)"
  18. fi
  19. }
  20. #=================================================
  21. # PACKAGE CHECK BYPASSING...
  22. #=================================================
  23. IS_PACKAGE_CHECK () { # Détermine une exécution en conteneur (Non testé)
  24. return $(uname -n | grep -c 'pchecker_lxc')
  25. }
  26. #=================================================
  27. # EXPERIMENTAL HELPERS
  28. #=================================================
  29. # INFOS
  30. # n (Node version management) utilise la variable PATH pour stocker le path de la version de node à utiliser.
  31. # C'est ainsi qu'il change de version
  32. # ynh_install_nodejs installe la version de nodejs demandée en argument, avec n
  33. # ynh_use_nodejs active une version de nodejs dans le script courant
  34. # 3 variables sont mises à disposition, et 2 sont stockées dans la config de l'app
  35. # - nodejs_path: Le chemin absolu de cette version de node
  36. # Utilisé pour des appels directs à node.
  37. # - nodejs_version: Simplement le numéro de version de nodejs pour cette application
  38. # - nodejs_use_version: Un alias pour charger une version de node dans le shell courant.
  39. # Utilisé pour démarrer un service ou un script qui utilise node ou npm
  40. # Dans ce cas, c'est $PATH qui contient le chemin de la version de node. Il doit être propagé sur les autres shell si nécessaire.
  41. n_install_dir="/opt/node_n"
  42. node_version_path="/opt/node_n/n/versions/node"
  43. # N_PREFIX est le dossier de n, il doit être chargé dans les variables d'environnement pour n.
  44. export N_PREFIX="$n_install_dir"
  45. ynh_install_n () {
  46. echo "Installation of N - Node.js version management" >&2
  47. # Build an app.src for n
  48. mkdir -p "../conf"
  49. echo "SOURCE_URL=https://github.com/tj/n/archive/v2.1.7.tar.gz
  50. SOURCE_SUM=2ba3c9d4dd3c7e38885b37e02337906a1ee91febe6d5c9159d89a9050f2eea8f" > "../conf/n.src"
  51. # Download and extract n
  52. ynh_setup_source "$n_install_dir/git" n
  53. # Install n
  54. (cd "$n_install_dir/git"
  55. PREFIX=$N_PREFIX make install 2>&1)
  56. }
  57. ynh_use_nodejs () {
  58. nodejs_version=$(ynh_app_setting_get $app nodejs_version)
  59. load_n_path="[[ :$PATH: == *\":$n_install_dir/bin:\"* ]] || PATH=\"$n_install_dir/bin:$PATH\"; N_PREFIX="$n_install_dir""
  60. nodejs_use_version="$n_install_dir/bin/n -q $nodejs_version"
  61. # "Load" a version of node
  62. eval $load_n_path; $nodejs_use_version
  63. # Get the absolute path of this version of node
  64. nodejs_path="$(n bin $nodejs_version)"
  65. # Make an alias for node use
  66. ynh_node_exec="eval $load_n_path; n use $nodejs_version"
  67. }
  68. ynh_install_nodejs () {
  69. # Use n, https://github.com/tj/n to manage the nodejs versions
  70. nodejs_version="$1"
  71. local n_install_script="https://git.io/n-install"
  72. # Create $n_install_dir
  73. mkdir -p "$n_install_dir"
  74. # Load n path in PATH
  75. CLEAR_PATH="$n_install_dir/bin:$PATH"
  76. # Remove /usr/local/bin in PATH in case of node has already setup.
  77. PATH=$(echo $CLEAR_PATH | sed 's@/usr/local/bin:@@')
  78. # Move an existing node binary, to avoid to block n.
  79. test -x /usr/bin/node && mv /usr/bin/node /usr/bin/node_n
  80. test -x /usr/bin/npm && mv /usr/bin/npm /usr/bin/npm_n
  81. # If n is not previously setup, install it
  82. if ! test n --version > /dev/null 2>&1
  83. then
  84. ynh_install_n
  85. fi
  86. # Modify the default N_PREFIX in n script
  87. ynh_replace_string "^N_PREFIX=\${N_PREFIX-.*}$" "N_PREFIX=\${N_PREFIX-$N_PREFIX}" "$n_install_dir/bin/n"
  88. # Restore /usr/local/bin in PATH
  89. PATH=$CLEAR_PATH
  90. # And replace the old node binary.
  91. test -x /usr/bin/node_n && mv /usr/bin/node_n /usr/bin/node
  92. test -x /usr/bin/npm_n && mv /usr/bin/npm_n /usr/bin/npm
  93. # Install the requested version of nodejs
  94. n $nodejs_version
  95. # Find the last "real" version for this major version of node.
  96. real_nodejs_version=$(find $node_version_path/$nodejs_version* -maxdepth 0 | sort --version-sort | tail --lines=1)
  97. real_nodejs_version=$(basename $real_nodejs_version)
  98. # Create a symbolic link for this major version. If the file doesn't already exist
  99. if [ ! -e "$node_version_path/$nodejs_version" ]
  100. then
  101. ln --symbolic --force --no-target-directory $node_version_path/$real_nodejs_version $node_version_path/$nodejs_version
  102. fi
  103. # Store the ID of this app and the version of node requested for it
  104. echo "$YNH_APP_ID:$nodejs_version" | tee --append "$n_install_dir/ynh_app_version"
  105. # Store nodejs_version into the config of this app
  106. ynh_app_setting_set $app nodejs_version $nodejs_version
  107. # Build the update script and set the cronjob
  108. ynh_cron_upgrade_node
  109. ynh_use_nodejs
  110. }
  111. ynh_remove_nodejs () {
  112. ynh_use_nodejs
  113. # Remove the line for this app
  114. sed --in-place "/$YNH_APP_ID:$nodejs_version/d" "$n_install_dir/ynh_app_version"
  115. # If none another app uses this version of nodejs, remove it.
  116. if ! grep --quiet "$nodejs_version" "$n_install_dir/ynh_app_version"
  117. then
  118. n rm $nodejs_version
  119. fi
  120. # If none another app uses n, remove n
  121. if [ ! -s "$n_install_dir/ynh_app_version" ]
  122. then
  123. ynh_secure_remove "$n_install_dir"
  124. ynh_secure_remove "/usr/local/n"
  125. sed --in-place "/N_PREFIX/d" /root/.bashrc
  126. fi
  127. }
  128. ynh_cron_upgrade_node () {
  129. # Build the update script
  130. cat > "$n_install_dir/node_update.sh" << EOF
  131. #!/bin/bash
  132. version_path="$node_version_path"
  133. n_install_dir="$n_install_dir"
  134. # Log the date
  135. date
  136. # List all real installed version of node
  137. all_real_version="\$(find \$version_path/* -maxdepth 0 -type d | sed "s@\$version_path/@@g")"
  138. # Keep only the major version number of each line
  139. all_real_version=\$(echo "\$all_real_version" | sed 's/\..*\$//')
  140. # Remove double entries
  141. all_real_version=\$(echo "\$all_real_version" | sort --unique)
  142. # Read each major version
  143. while read version
  144. do
  145. echo "Update of the version \$version"
  146. sudo \$n_install_dir/bin/n \$version
  147. # Find the last "real" version for this major version of node.
  148. real_nodejs_version=\$(find \$version_path/\$version* -maxdepth 0 | sort --version-sort | tail --lines=1)
  149. real_nodejs_version=\$(basename \$real_nodejs_version)
  150. # Update the symbolic link for this version
  151. sudo ln --symbolic --force --no-target-directory \$version_path/\$real_nodejs_version \$version_path/\$version
  152. done <<< "\$(echo "\$all_real_version")"
  153. EOF
  154. chmod +x "$n_install_dir/node_update.sh"
  155. # Build the cronjob
  156. cat > "/etc/cron.daily/node_update" << EOF
  157. #!/bin/bash
  158. $n_install_dir/node_update.sh >> $n_install_dir/node_update.log
  159. EOF
  160. chmod +x "/etc/cron.daily/node_update"
  161. }
  162. #=================================================
  163. # Start or restart a service and follow its booting
  164. #
  165. # usage: ynh_check_starting "Line to match" [Log file] [Timeout] [Service name]
  166. #
  167. # | arg: Line to match - The line to find in the log to attest the service have finished to boot.
  168. # | arg: Log file - The log file to watch
  169. # | arg: Service name
  170. # /var/log/$app/$app.log will be used if no other log is defined.
  171. # | arg: Timeout - The maximum time to wait before ending the watching. Defaut 300 seconds.
  172. ynh_check_starting () {
  173. local line_to_match="$1"
  174. local service_name="${4:-$app}"
  175. local app_log="${2:-/var/log/$service_name/$service_name.log}"
  176. local timeout=${3:-300}
  177. ynh_clean_check_starting () {
  178. # Stop the execution of tail.
  179. kill -s 15 $pid_tail 2>&1
  180. ynh_secure_remove "$templog" 2>&1
  181. }
  182. echo "Starting of $service_name" >&2
  183. systemctl stop $service_name
  184. local templog="$(mktemp)"
  185. # Following the starting of the app in its log
  186. tail -F -n0 "$app_log" > "$templog" &
  187. # Get the PID of the tail command
  188. local pid_tail=$!
  189. systemctl start $service_name
  190. local i=0
  191. for i in `seq 1 $timeout`
  192. do
  193. # Read the log until the sentence is found, that means the app finished to start. Or run until the timeout
  194. if grep --quiet "$line_to_match" "$templog"
  195. then
  196. echo "The service $service_name has correctly started." >&2
  197. break
  198. fi
  199. echo -n "." >&2
  200. sleep 1
  201. done
  202. if [ $i -eq $timeout ]
  203. then
  204. echo "The service $service_name didn't fully started before the timeout." >&2
  205. fi
  206. echo ""
  207. ynh_clean_check_starting
  208. }
  209. #=================================================
  210. ynh_print_log () {
  211. echo "${1}"
  212. }
  213. # Print an info on stdout
  214. #
  215. # usage: ynh_print_info "Text to print"
  216. # | arg: text - The text to print
  217. ynh_print_info () {
  218. ynh_print_log "[INFO] ${1}"
  219. }
  220. # Print a warning on stderr
  221. #
  222. # usage: ynh_print_warn "Text to print"
  223. # | arg: text - The text to print
  224. ynh_print_warn () {
  225. ynh_print_log "[WARN] ${1}" >&2
  226. }
  227. # Print a error on stderr
  228. #
  229. # usage: ynh_print_err "Text to print"
  230. # | arg: text - The text to print
  231. ynh_print_err () {
  232. ynh_print_log "[ERR] ${1}" >&2
  233. }
  234. # Execute a command and print the result as an error
  235. #
  236. # usage: ynh_exec_err command to execute
  237. # usage: ynh_exec_err "command to execute | following command"
  238. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
  239. #
  240. # | arg: command - command to execute
  241. ynh_exec_err () {
  242. ynh_print_err "$(eval $@)"
  243. }
  244. # Execute a command and print the result as a warning
  245. #
  246. # usage: ynh_exec_warn command to execute
  247. # usage: ynh_exec_warn "command to execute | following command"
  248. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
  249. #
  250. # | arg: command - command to execute
  251. ynh_exec_warn () {
  252. ynh_print_warn "$(eval $@)"
  253. }
  254. # Execute a command and force the result to be printed on stdout
  255. #
  256. # usage: ynh_exec_warn_less command to execute
  257. # usage: ynh_exec_warn_less "command to execute | following command"
  258. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
  259. #
  260. # | arg: command - command to execute
  261. ynh_exec_warn_less () {
  262. eval $@ 2>&1
  263. }
  264. # Execute a command and redirect stdout in /dev/null
  265. #
  266. # usage: ynh_exec_quiet command to execute
  267. # usage: ynh_exec_quiet "command to execute | following command"
  268. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
  269. #
  270. # | arg: command - command to execute
  271. ynh_exec_quiet () {
  272. eval $@ > /dev/null
  273. }
  274. # Execute a command and redirect stdout and stderr in /dev/null
  275. #
  276. # usage: ynh_exec_fully_quiet command to execute
  277. # usage: ynh_exec_fully_quiet "command to execute | following command"
  278. # In case of use of pipes, you have to use double quotes. Otherwise, this helper will be executed with the first command, then be send to the next pipe.
  279. #
  280. # | arg: command - command to execute
  281. ynh_exec_fully_quiet () {
  282. eval $@ > /dev/null 2>&1
  283. }
  284. # Remove any logs for all the following commands.
  285. #
  286. # usage: ynh_print_OFF
  287. # WARNING: You should be careful with this helper, and never forgot to use ynh_print_ON as soon as possible to restore the logging.
  288. ynh_print_OFF () {
  289. set +x
  290. }
  291. # Restore the logging after ynh_print_OFF
  292. #
  293. # usage: ynh_print_ON
  294. ynh_print_ON () {
  295. set -x
  296. # Print an echo only for the log, to be able to know that ynh_print_ON has been called.
  297. echo ynh_print_ON > /dev/null
  298. }
  299. #=================================================
  300. # Install or update the main directory yunohost.multimedia
  301. #
  302. # usage: ynh_multimedia_build_main_dir
  303. ynh_multimedia_build_main_dir () {
  304. wget -nv https://github.com/YunoHost-Apps/yunohost.multimedia/archive/master.zip 2>&1
  305. unzip -q master.zip
  306. ./yunohost.multimedia-master/script/ynh_media_build.sh
  307. }
  308. # Add a directory in yunohost.multimedia
  309. # This "directory" will be a symbolic link to a existing directory.
  310. #
  311. # usage: ynh_multimedia_addfolder "Source directory" "Destination directory"
  312. #
  313. # | arg: Source directory - The real directory which contains your medias.
  314. # | arg: Destination directory - The name and the place of the symbolic link, relative to "/home/yunohost.multimedia"
  315. ynh_multimedia_addfolder () {
  316. local source_dir="$1"
  317. local dest_dir="$2"
  318. ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --source="$source_dir" --dest="$dest_dir"
  319. }
  320. # Move a directory in yunohost.multimedia, and replace by a symbolic link
  321. #
  322. # usage: ynh_multimedia_movefolder "Source directory" "Destination directory"
  323. #
  324. # | arg: Source directory - The real directory which contains your medias.
  325. # It will be moved to "Destination directory"
  326. # A symbolic link will replace it.
  327. # | arg: Destination directory - The new name and place of the directory, relative to "/home/yunohost.multimedia"
  328. ynh_multimedia_movefolder () {
  329. local source_dir="$1"
  330. local dest_dir="$2"
  331. ./yunohost.multimedia-master/script/ynh_media_addfolder.sh --inv --source="$source_dir" --dest="$dest_dir"
  332. }
  333. # Allow an user to have an write authorisation in multimedia directories
  334. #
  335. # usage: ynh_multimedia_addaccess user_name
  336. #
  337. # | arg: user_name - The name of the user which gain this access.
  338. ynh_multimedia_addaccess () {
  339. local user_name=$1
  340. groupadd -f multimedia
  341. usermod -a -G multimedia $user_name
  342. }
  343. #=================================================
  344. # Create a dedicated fail2ban config (jail and filter conf files)
  345. #
  346. # usage: ynh_add_fail2ban_config log_file filter [max_retry [ports]]
  347. # | arg: log_file - Log file to be checked by fail2ban
  348. # | arg: failregex - Failregex to be looked for by fail2ban
  349. # | arg: max_retry - Maximum number of retries allowed before banning IP address - default: 3
  350. # | arg: ports - Ports blocked for a banned IP address - default: http,https
  351. ynh_add_fail2ban_config () {
  352. # Process parameters
  353. logpath=$1
  354. failregex=$2
  355. max_retry=${3:-3}
  356. ports=${4:-http,https}
  357. test -n "$logpath" || ynh_die "ynh_add_fail2ban_config expects a logfile path as first argument and received nothing."
  358. test -n "$failregex" || ynh_die "ynh_add_fail2ban_config expects a failure regex as second argument and received nothing."
  359. finalfail2banjailconf="/etc/fail2ban/jail.d/$app.conf"
  360. finalfail2banfilterconf="/etc/fail2ban/filter.d/$app.conf"
  361. ynh_backup_if_checksum_is_different "$finalfail2banjailconf" 1
  362. ynh_backup_if_checksum_is_different "$finalfail2banfilterconf" 1
  363. sudo tee $finalfail2banjailconf <<EOF
  364. [$app]
  365. enabled = true
  366. port = $ports
  367. filter = $app
  368. logpath = $logpath
  369. maxretry = $max_retry
  370. EOF
  371. sudo tee $finalfail2banfilterconf <<EOF
  372. [INCLUDES]
  373. before = common.conf
  374. [Definition]
  375. failregex = $failregex
  376. ignoreregex =
  377. EOF
  378. ynh_store_file_checksum "$finalfail2banjailconf"
  379. ynh_store_file_checksum "$finalfail2banfilterconf"
  380. systemctl restart fail2ban
  381. local fail2ban_error="$(journalctl -u fail2ban | tail -n50 | grep "WARNING.*$app.*")"
  382. if [ -n "$fail2ban_error" ]
  383. then
  384. echo "[ERR] Fail2ban failed to load the jail for $app" >&2
  385. echo "WARNING${fail2ban_error#*WARNING}" >&2
  386. fi
  387. }
  388. # Remove the dedicated fail2ban config (jail and filter conf files)
  389. #
  390. # usage: ynh_remove_fail2ban_config
  391. ynh_remove_fail2ban_config () {
  392. ynh_secure_remove "/etc/fail2ban/jail.d/$app.conf"
  393. ynh_secure_remove "/etc/fail2ban/filter.d/$app.conf"
  394. sudo systemctl restart fail2ban
  395. }
  396. #=================================================
  397. # Read the value of a key in a ynh manifest file
  398. #
  399. # usage: ynh_read_manifest manifest key
  400. # | arg: manifest - Path of the manifest to read
  401. # | arg: key - Name of the key to find
  402. ynh_read_manifest () {
  403. manifest="$1"
  404. key="$2"
  405. python3 -c "import sys, json;print(json.load(open('$manifest', encoding='utf-8'))['$key'])"
  406. }
  407. # Exit without error if the package is up to date
  408. #
  409. # This helper should be used to avoid an upgrade of a package
  410. # when it's not needed.
  411. #
  412. # To force an upgrade, even if the package is up to date,
  413. # you have to set the variable YNH_FORCE_UPGRADE before.
  414. # example: sudo YNH_FORCE_UPGRADE=1 yunohost app upgrade MyApp
  415. #
  416. # usage: ynh_abort_if_up_to_date
  417. ynh_abort_if_up_to_date () {
  418. local force_upgrade=${YNH_FORCE_UPGRADE:-0}
  419. local package_check=${PACKAGE_CHECK_EXEC:-0}
  420. local version=$(ynh_read_manifest "/etc/yunohost/apps/$YNH_APP_INSTANCE_NAME/manifest.json" "version" || echo 1.0)
  421. local last_version=$(ynh_read_manifest "../manifest.json" "version" || echo 1.0)
  422. if [ "$version" = "$last_version" ]
  423. then
  424. if [ "$force_upgrade" != "0" ]
  425. then
  426. echo "Upgrade forced by YNH_FORCE_UPGRADE." >&2
  427. unset YNH_FORCE_UPGRADE
  428. elif [ "$package_check" != "0" ]
  429. then
  430. echo "Upgrade forced for package check." >&2
  431. else
  432. ynh_die "Up-to-date, nothing to do" 0
  433. fi
  434. fi
  435. }
  436. #=================================================
  437. # Send an email to inform the administrator
  438. #
  439. # usage: ynh_send_readme_to_admin app_message [recipients]
  440. # | arg: app_message - The message to send to the administrator.
  441. # | arg: recipients - The recipients of this email. Use spaces to separate multiples recipients. - default: root
  442. # example: "root admin@domain"
  443. # If you give the name of a YunoHost user, ynh_send_readme_to_admin will find its email adress for you
  444. # example: "root admin@domain user1 user2"
  445. ynh_send_readme_to_admin() {
  446. local app_message="${1:-...No specific information...}"
  447. local recipients="${2:-root}"
  448. # Retrieve the email of users
  449. find_mails () {
  450. local list_mails="$1"
  451. local mail
  452. local recipients=" "
  453. # Read each mail in argument
  454. for mail in $list_mails
  455. do
  456. # Keep root or a real email address as it is
  457. if [ "$mail" = "root" ] || echo "$mail" | grep --quiet "@"
  458. then
  459. recipients="$recipients $mail"
  460. else
  461. # But replace an user name without a domain after by its email
  462. if mail=$(ynh_user_get_info "$mail" "mail" 2> /dev/null)
  463. then
  464. recipients="$recipients $mail"
  465. fi
  466. fi
  467. done
  468. echo "$recipients"
  469. }
  470. recipients=$(find_mails "$recipients")
  471. local mail_subject="☁️🆈🅽🅷☁️: \`$app\` was just installed!"
  472. local mail_message="This is an automated message from your beloved YunoHost server.
  473. Specific information for the application $app.
  474. $app_message
  475. ---
  476. Automatic diagnosis data from YunoHost
  477. $(yunohost tools diagnosis | grep -B 100 "services:" | sed '/services:/d')"
  478. # Send the email to the recipients
  479. echo "$mail_message" | mail -a "Content-Type: text/plain; charset=UTF-8" -s "$mail_subject" "$recipients"
  480. }
  481. #=================================================
  482. # Reload (or other actions) a service and print a log in case of failure.
  483. #
  484. # usage: ynh_system_reload service_name [action]
  485. # | arg: service_name - Name of the service to reload
  486. # | arg: action - Action to perform with systemctl. Default: reload
  487. ynh_system_reload () {
  488. local service_name=$1
  489. local action=${2:-reload}
  490. # Reload, restart or start and print the log if the service fail to start or reload
  491. systemctl $action $service_name || ( journalctl --lines=20 -u $service_name >&2 && false)
  492. }
  493. #=================================================
  494. ynh_debian_release () {
  495. lsb_release --codename --short
  496. }
  497. is_stretch () {
  498. if [ "$(ynh_debian_release)" == "stretch" ]
  499. then
  500. return 0
  501. else
  502. return 1
  503. fi
  504. }
  505. is_jessie () {
  506. if [ "$(ynh_debian_release)" == "jessie" ]
  507. then
  508. return 0
  509. else
  510. return 1
  511. fi
  512. }
  513. #=================================================
  514. #============= FUTURE YUNOHOST HELPER ============
  515. #=================================================
  516. # Delete a file checksum from the app settings
  517. #
  518. # $app should be defined when calling this helper
  519. #
  520. # usage: ynh_remove_file_checksum file
  521. # | arg: file - The file for which the checksum will be deleted
  522. ynh_delete_file_checksum () {
  523. local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_'
  524. ynh_app_setting_delete $app $checksum_setting_name
  525. }