Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions debian/csi
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ SELF_UPDATE_FLAG="CSI_SELF_UPDATED"
HOSTS_FILE="/etc/hosts"
DOMAIN="clearskyinstitute.com"
BACKEND_PATTERN="[^[:space:]'\";)]+"
WRAPPER_WAIT_LINE_1='until [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; do sleep 1; done'
WRAPPER_WAIT_LINE_2='sleep 5'

# Work out which user's home to use when run via sudo
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
Expand Down Expand Up @@ -47,9 +49,10 @@ if [ "$EUID" -ne 0 ]; then
fi

self_update() {
local script_path remote_tmp script_name
local script_path remote_tmp script_name flag_value

if [ -n "$CSI_SELF_UPDATED" ]; then
flag_value=$(printenv "$SELF_UPDATE_FLAG" 2>/dev/null || true)
if [ -n "$flag_value" ]; then
return 0
fi

Expand Down Expand Up @@ -104,7 +107,9 @@ self_update() {
echo "A newer version of $script_name was found and installed."
echo "Restarting with the updated version..."

export CSI_SELF_UPDATED=1
printf -v "$SELF_UPDATE_FLAG" '%s' 1
export "$SELF_UPDATE_FLAG"

exec "$script_path" "$@"
}

Expand Down Expand Up @@ -132,6 +137,7 @@ patch_file() {
local file="$1"
local mode="$2"
local tmpfile
local tmpfile2
local cleanfile
local user

Expand All @@ -153,6 +159,20 @@ patch_file() {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
}" "$file" > "$tmpfile"
;;
xrandr_wrapper)
tmpfile2=$(mktemp) || {
rm -f "$tmpfile"
echo "Error: could not create temporary file."
exit 1
}

sed -E "/^[[:space:]]*exec=[[:space:]]*\\\$[[:space:]]*\\(/ {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
}" "$file" > "$tmpfile2"

grep -Fvx "$WRAPPER_WAIT_LINE_1" "$tmpfile2" | grep -Fvx "$WRAPPER_WAIT_LINE_2" > "$tmpfile"
rm -f "$tmpfile2"
;;
service)
sed -E "/^[[:space:]]*ExecStart=/ {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
Expand Down Expand Up @@ -250,7 +270,7 @@ fi
patch_file "$DESKTOP_FILE" "desktop"
patch_file "$AUTOSTART_FILE" "desktop"
patch_file "$RUNNER_FILE" "runner"
patch_file "$XRANDR_WRAPPER_FILE" "runner"
patch_file "$XRANDR_WRAPPER_FILE" "xrandr_wrapper"

if patch_file "$SERVICE_FILE" "service"; then
service_changed=1
Expand Down
43 changes: 41 additions & 2 deletions debian/hcdc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fi
BACKEND_PATTERN="[^[:space:]'\";)]+"
ENTRY="$HOSTS_IP $DOMAIN"
DESKTOP_EXEC_LINE="Exec=sh -c 'until [ -n \"\$DISPLAY\" ] || [ -n \"\$WAYLAND_DISPLAY\" ]; do sleep 1; done; sleep 5; exec /usr/local/bin/hamclock -b $BACKEND_TARGET'"
WRAPPER_WAIT_LINE_1='until [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; do sleep 1; done'
WRAPPER_WAIT_LINE_2='sleep 5'

# Work out which user's home to use when run via sudo
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
Expand Down Expand Up @@ -149,6 +151,7 @@ patch_file() {
local file="$1"
local mode="$2"
local tmpfile
local tmpfile2
local cleanfile
local user

Expand All @@ -162,8 +165,12 @@ patch_file() {
case "$mode" in
desktop)
sed -E "/^[[:space:]]*Exec=/ {
c\\
/hamclock-xrandr-wrapper/ b
/hamclock-runner/ b
/(^|[^[:alnum:]_/-])(\/usr\/local\/bin\/)?hamclock(-4k)?([[:space:]'\";)]|$)/ {
c\\
$DESKTOP_EXEC_LINE
}
}" "$file" > "$tmpfile"
;;
runner)
Expand All @@ -172,6 +179,38 @@ $DESKTOP_EXEC_LINE
s#(^|[^[:alnum:]_/-])(/usr/local/bin/)?(hamclock|hamclock-4k)([[:space:]'\";)]|$)#\1\2\3 -b $BACKEND_TARGET\4#
}" "$file" > "$tmpfile"
;;
xrandr_wrapper)
tmpfile2=$(mktemp) || {
rm -f "$tmpfile"
echo "Error: could not create temporary file."
exit 1
}

if grep -Eq '\$DISPLAY|\$WAYLAND_DISPLAY' "$file"; then
cat "$file" > "$tmpfile2"
else
awk -v wait1="$WRAPPER_WAIT_LINE_1" -v wait2="$WRAPPER_WAIT_LINE_2" '
NR == 1 && /^#!/ {
print
print wait1
print wait2
next
}
NR == 1 {
print wait1
print wait2
}
{ print }
' "$file" > "$tmpfile2"
fi

sed -E "/^[[:space:]]*exec=[[:space:]]*\\\$[[:space:]]*\\(/ {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
s#(^|[^[:alnum:]_/-])(/usr/local/bin/)?(hamclock|hamclock-4k)([[:space:]'\";)]|$)#\1\2\3 -b $BACKEND_TARGET\4#
}" "$tmpfile2" > "$tmpfile"

rm -f "$tmpfile2"
;;
service)
sed -E "/^[[:space:]]*ExecStart=/ {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
Expand Down Expand Up @@ -274,7 +313,7 @@ fi
patch_file "$DESKTOP_FILE" "desktop"
patch_file "$AUTOSTART_FILE" "desktop"
patch_file "$RUNNER_FILE" "runner"
patch_file "$XRANDR_WRAPPER_FILE" "runner"
patch_file "$XRANDR_WRAPPER_FILE" "xrandr_wrapper"

if patch_file "$SERVICE_FILE" "service"; then
service_changed=1
Expand Down
43 changes: 41 additions & 2 deletions debian/ohb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ fi
BACKEND_PATTERN="[^[:space:]'\";)]+"
ENTRY="$HOSTS_IP $DOMAIN"
DESKTOP_EXEC_LINE="Exec=sh -c 'until [ -n \"\$DISPLAY\" ] || [ -n \"\$WAYLAND_DISPLAY\" ]; do sleep 1; done; sleep 5; exec /usr/local/bin/hamclock -b $BACKEND_TARGET'"
WRAPPER_WAIT_LINE_1='until [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; do sleep 1; done'
WRAPPER_WAIT_LINE_2='sleep 5'

# Work out which user's home to use when run via sudo
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
Expand Down Expand Up @@ -149,6 +151,7 @@ patch_file() {
local file="$1"
local mode="$2"
local tmpfile
local tmpfile2
local cleanfile
local user

Expand All @@ -162,8 +165,12 @@ patch_file() {
case "$mode" in
desktop)
sed -E "/^[[:space:]]*Exec=/ {
c\\
/hamclock-xrandr-wrapper/ b
/hamclock-runner/ b
/(^|[^[:alnum:]_/-])(\/usr\/local\/bin\/)?hamclock(-4k)?([[:space:]'\";)]|$)/ {
c\\
$DESKTOP_EXEC_LINE
}
}" "$file" > "$tmpfile"
;;
runner)
Expand All @@ -172,6 +179,38 @@ $DESKTOP_EXEC_LINE
s#(^|[^[:alnum:]_/-])(/usr/local/bin/)?(hamclock|hamclock-4k)([[:space:]'\";)]|$)#\1\2\3 -b $BACKEND_TARGET\4#
}" "$file" > "$tmpfile"
;;
xrandr_wrapper)
tmpfile2=$(mktemp) || {
rm -f "$tmpfile"
echo "Error: could not create temporary file."
exit 1
}

if grep -Eq '\$DISPLAY|\$WAYLAND_DISPLAY' "$file"; then
cat "$file" > "$tmpfile2"
else
awk -v wait1="$WRAPPER_WAIT_LINE_1" -v wait2="$WRAPPER_WAIT_LINE_2" '
NR == 1 && /^#!/ {
print
print wait1
print wait2
next
}
NR == 1 {
print wait1
print wait2
}
{ print }
' "$file" > "$tmpfile2"
fi

sed -E "/^[[:space:]]*exec=[[:space:]]*\\\$[[:space:]]*\\(/ {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
s#(^|[^[:alnum:]_/-])(/usr/local/bin/)?(hamclock|hamclock-4k)([[:space:]'\";)]|$)#\1\2\3 -b $BACKEND_TARGET\4#
}" "$tmpfile2" > "$tmpfile"

rm -f "$tmpfile2"
;;
service)
sed -E "/^[[:space:]]*ExecStart=/ {
s/[[:space:]]+-b[[:space:]]+$BACKEND_PATTERN//g
Expand Down Expand Up @@ -274,7 +313,7 @@ fi
patch_file "$DESKTOP_FILE" "desktop"
patch_file "$AUTOSTART_FILE" "desktop"
patch_file "$RUNNER_FILE" "runner"
patch_file "$XRANDR_WRAPPER_FILE" "runner"
patch_file "$XRANDR_WRAPPER_FILE" "xrandr_wrapper"

if patch_file "$SERVICE_FILE" "service"; then
service_changed=1
Expand Down