{"action":"closed","issue":{"url":"https://api.github.com/repos/lukas2511/letsencrypt.sh/issues/67","labels_url":"https://api.github.com/repos/lukas2511/letsencrypt.sh/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/lukas2511/letsencrypt.sh/issues/67/comments","events_url":"https://api.github.com/repos/lukas2511/letsencrypt.sh/issues/67/events","html_url":"https://github.com/lukas2511/letsencrypt.sh/issues/67","id":124434861,"number":67,"title":"Dependency on HOME which may not be set","user":{"login":"samueldr","id":132835,"avatar_url":"https://avatars.githubusercontent.com/u/132835?v=3","gravatar_id":"","url":"https://api.github.com/users/samueldr","html_url":"https://github.com/samueldr","followers_url":"https://api.github.com/users/samueldr/followers","following_url":"https://api.github.com/users/samueldr/following{/other_user}","gists_url":"https://api.github.com/users/samueldr/gists{/gist_id}","starred_url":"https://api.github.com/users/samueldr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samueldr/subscriptions","organizations_url":"https://api.github.com/users/samueldr/orgs","repos_url":"https://api.github.com/users/samueldr/repos","events_url":"https://api.github.com/users/samueldr/events{/privacy}","received_events_url":"https://api.github.com/users/samueldr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-31T05:46:15Z","updated_at":"2016-01-08T19:26:27Z","closed_at":"2016-01-08T19:26:27Z","body":"The [current script](https://github.com/lukas2511/letsencrypt.sh/blob/f090fbcf7f773c82676e54e37336cffe2fbd7139/letsencrypt.sh#L41) uses `${HOME}`, when in some cases it might not be set in the environment. The use case where it happens is using letsencrypt.sh as a systemd service/timer set.\r\n\r\nThis causes this issue:\r\n\r\n    letsencrypt.sh[]: [...]/letsencrypt.sh: line 30: HOME: unbound variable\r\n\r\nAs this is used to find plausible config file locations, I wouldn't know what's the best way to avoid this issue. The `${HOME}` location *might* be important for some cases, for mine it isn't.\r\n\r\nAs a stop-gap solution (for anybody setting up a systemd timer), it can be set explicitly.\r\n\r\n    [...]\r\n    [Service]\r\n    Environment=\"HOME=/root/\"\r\n    [...]\r\n\r\nPersonally, I would use `~` instead of `${HOME}` which does always resolve to the current user's home, even when neither `${HOME}` or `${USER}` are in the environment. There is one caveat with the use of `~`, its properties around quoting are different than those of variables. I have not tested with a folder with spaces as a home folder, but I would guess that it would be even rarer than an execution of the script with a barebones environment. I think that with the current use, the quoting would still be fine, as long as it is used like so, unquoted: `~/.letsencrypt.sh`.\r\n\r\n * * *\r\n\r\nHere's a test case: `/usr/local/bin/tildeexpansion.sh`\r\n\r\n    #!/bin/bash\r\n    \r\n    unset HOME\r\n    \r\n    set -e\r\n    set -u\r\n    \r\n    echo ~\r\n    echo ~/.letsencrypt.sh\r\n    \r\n    echo \"${HOME:-$(echo ~)}\"\r\n    echo \"${HOME:-$(echo ~)}/.letsencrypt.sh\"\r\n    \r\n    echo \"${HOME:-~}\"\r\n    echo \"${HOME:-~}/.letsencrypt.sh\"\r\n    \r\n    echo \"${HOME}\"\r\n    echo \"${HOME}/.letsencrypt.sh\"\r\n\r\nTo run as a systemd service: `/etc/systemd/system/tildeexpansion.service`\r\n\r\n    [Unit]\r\n    Description=Tests tilde expansion\r\n    \r\n    [Service]\r\n    Type=oneshot\r\n    ExecStart=/usr/local/bin/tildeexpansion.sh\r\n\r\nIt can be run with `sudo systemctl daemon-reload; sudo systemctl start tildeexpansion`. `/usr/local/bin/tildeexpansion.sh` needs to be executable. The output can be looked at using `sudo journalctl --unit tildeexpansion`. This test case service *will* fail since the exit code of the script is a failure.\r\n\r\nReferences:\r\n  * http://mywiki.wooledge.org/BashPitfalls#echo_.22.2BAH4.22\r\n  * http://mywiki.wooledge.org/BashPitfalls#export_foo.3D.2BAH4-.2Fbar\r\n  * https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html"}}