Skip to content

Commit 5682244

Browse files
committed
import: fallback to user-writable ~/.ok_computer/packages.conf when target not writable (bundle-safe)
1 parent 29ffb93 commit 5682244

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/import_installed.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,33 @@ fi
2727

2828
echo -e "${BLUE}Using config file:${NC} ${PACKAGES_CONF}"
2929

30+
# If the chosen PACKAGES_CONF is not writable (e.g. inside a bundled binary's
31+
# temporary directory), fall back to a user-writable location under $HOME
32+
if [ -f "${PACKAGES_CONF}" ]; then
33+
if [ ! -w "${PACKAGES_CONF}" ]; then
34+
echo -e "${YELLOW}Warning:${NC} ${PACKAGES_CONF} is not writable. Falling back to user config."
35+
USER_DIR="${HOME}/.ok_computer"
36+
mkdir -p "${USER_DIR}"
37+
NEW_CONF="${USER_DIR}/packages.conf"
38+
if [ ! -f "${NEW_CONF}" ] && [ -f "${SCRIPT_DIR}/packages.conf" ]; then
39+
# seed from repository packages.conf if available
40+
cp "${SCRIPT_DIR}/packages.conf" "${NEW_CONF}" || true
41+
fi
42+
PACKAGES_CONF="${NEW_CONF}"
43+
echo -e "${BLUE}Using fallback config file:${NC} ${PACKAGES_CONF}"
44+
fi
45+
else
46+
# If the file doesn't exist, check whether we can create it in place; if not, use fallback
47+
parent_dir=$(dirname "${PACKAGES_CONF}")
48+
if [ ! -w "${parent_dir}" ]; then
49+
echo -e "${YELLOW}Warning:${NC} Cannot create ${PACKAGES_CONF} in ${parent_dir}. Falling back to user config."
50+
USER_DIR="${HOME}/.ok_computer"
51+
mkdir -p "${USER_DIR}"
52+
PACKAGES_CONF="${USER_DIR}/packages.conf"
53+
echo -e "${BLUE}Using fallback config file:${NC} ${PACKAGES_CONF}"
54+
fi
55+
fi
56+
3057
# Check availability functions (simplified versions of app.sh)
3158
check_homebrew_api() {
3259
local app=$1

0 commit comments

Comments
 (0)