Skip to content

Commit ebc70a6

Browse files
committed
oops
1 parent 5c65210 commit ebc70a6

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

sources/identity/init.template.sh

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
# must be bash because we source a bashrc file
3+
set -ex
34
if [ -n "$1" ]; then
45
CHARM_URL="$1"
56
fi
@@ -42,18 +43,42 @@ fi
4243
mkdir -p /etc/apt/keyrings
4344
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg
4445
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_21.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
45-
apt update
46-
apt install -y curl nodejs npm ucspi-tcp unzip xxd
46+
DEBIAN_FRONTEND=noninteractive apt update
47+
DEBIAN_FRONTEND=noninteractive apt dist-upgrade -yq
48+
DEBIAN_FRONTEND=noninteractive apt autoremove -y
49+
DEBIAN_FRONTEND=noninteractive apt autoclean -y
50+
DEBIAN_FRONTEND=noninteractive apt install -y curl nodejs npm ucspi-tcp unzip xxd unattended-upgrades
51+
AUTO_UPGRADES_FILE="/etc/apt/apt.conf.d/20auto-upgrades"
52+
REQUIRED_LINES=(
53+
'APT::Periodic::Update-Package-Lists "1";'
54+
'APT::Periodic::Download-Upgradeable-Packages "1";'
55+
'APT::Periodic::AutocleanInterval "7";'
56+
'APT::Periodic::Unattended-Upgrade "1";'
57+
)
58+
add_line_if_not_present() {
59+
local line="$1"
60+
local file="$2"
61+
grep -qF -- "$line" "$file" || echo "$line" >> "$file"
62+
}
63+
if [ ! -f "$AUTO_UPGRADES_FILE" ]; then
64+
echo "$AUTO_UPGRADES_FILE does not exist, creating it..."
65+
touch "$AUTO_UPGRADES_FILE"
66+
fi
67+
for line in "${REQUIRED_LINES[@]}"; do
68+
add_line_if_not_present "$line" "$AUTO_UPGRADES_FILE"
69+
done
70+
echo "The $AUTO_UPGRADES_FILE has been updated."
71+
4772
npm install -g npm@latest
4873
npm --version
4974
node --version
5075
if command -v snap; then
5176
snap install powershell --classic
5277
else
53-
apt install -y libicu72
54-
curl -O https://github.com/PowerShell/PowerShell/releases/download/v7.4.1/powershell_7.4.1-1.deb_amd64.deb
78+
DEBIAN_FRONTEND=noninteractive apt install -y libicu72
79+
curl -LO https://github.com/PowerShell/PowerShell/releases/download/v7.4.1/powershell_7.4.1-1.deb_amd64.deb
5580
dpkg -i powershell_7.4.1-1.deb_amd64.deb
56-
apt install -f
81+
DEBIAN_FRONTEND=noninteractive apt install -f
5782
fi
5883
cd ~
5984
if [ ! -d "code" ]; then
@@ -67,7 +92,7 @@ chmod +x *.ps1 *.sh
6792
CHARM_LINK_URL="$CHARM_LINK_URL" ./provider.sh &
6893
get_http_status() {
6994
local url=$1
70-
curl -o /dev/null -s -w "%{http_code}\n" "$url"
95+
curl -Lo /dev/null -s -w "%{http_code}\n" "$url"
7196
}
7297

7398
start_time=$(date +%s)
@@ -84,8 +109,8 @@ while : ; do
84109
http_status=$(get_http_status "$CHARM_LINK_URL")
85110
echo "Checking URL: $CHARM_LINK_URL - HTTP status: $http_status"
86111

87-
if [ "$http_status" -eq 405 ]; then
88-
echo "Verified charm link url is working, breaking loop."
112+
if [ "$http_status" -ne 000 ]; then
113+
echo "Verified charm link url is responding, breaking loop."
89114
break
90115
fi
91116

@@ -95,23 +120,26 @@ if [ "$elapsed_time" -ge 60 ]; then
95120
echo "Failed to obtain charm link"
96121
exit 1
97122
fi
123+
echo "Obtaining charm link"
98124
response=$(curl -sL "$CHARM_LINK_URL" --data-urlencode "keys=$(./identity charm keys --simple | tr '\n' ',' | sed 's/,$//')")
99125

100126
if [ -n "$response" ]; then
101127
extracted_value=$(echo "$response" | sed -n 's/.*HTTP\/1\.1 200 \(.*\)\r.*/\1/p')
102128

103-
if [ -n "$extracted_value" ]; then
129+
if [ -z "$extracted_value" ]; then
104130
echo "Unexpected response: $extracted_value"
105131
exit 1
106132
fi
107-
108-
CHARM_LINK=$response
109133
else
110134
echo "Failed to obtain charm link"
111135
exit 1
112136
fi
137+
set -ex
138+
CHARM_LINK=$extracted_value
113139
./identity charm link -d "$CHARM_LINK"
114140
./identity charm kv sync
115141
./identity charm kv get dt.identity.init > .init
116142
chmod +x .init
143+
echo "Running .init"
144+
set +e
117145
./.init

sources/identity/provider.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ random() {
66
echo $(dd if=/dev/urandom bs=1 count=64 2>/dev/null | xxd -p)
77
}
88
if [ -z "$CHARM_DIR" ]; then
9-
CHARM_DIR=~$USER/code/source/identity/data/charms/$(random)
9+
CHARM_DIR=~/code/source/identity/data/charms/$(random)
1010
fi
1111
if [ -n "$2" ]; then
1212
INIT_URL=$2
@@ -55,7 +55,7 @@ sed -i "s|{{CHARM_LINK_URL}}|$CHARM_LINK_URL|g" ./provider/static/init
5555
./identity charm kv set dt.identity.secret.TURSO_AUTH_TOKEN "$TURSO_AUTH_TOKEN"
5656
./identity charm kv set dt.identity.init <<EOF
5757
#!/usr/bin/env pwsh
58-
cd ~\$USER/code/source/identity
58+
cd ~/code/source/identity
5959
./identity charm kv sync
6060
TURSO_HOST=$(./identity charm kv get dt.identity.secret.TURSO_HOST)
6161
export TURSO_HOST

sources/identity/provider/pages/link.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ for key in "${!FORM_DATA[@]}"; do
1313

1414
mkdir -p "$(dirname "$LINK_CODE_PATH")"
1515

16-
~/code/src/identity/identity charm link -d -o "$LINK_CODE_PATH" -k "${FORM_DATA[$key]}" > /dev/null 2>&1
16+
~/code/src/identity/identity charm link -d -o "$LINK_CODE_PATH" -k "${FORM_DATA[$key]}" > /dev/null 2>&1 &
1717
max_wait=60 # seconds
1818
wait_interval=1 # seconds
1919
elapsed_time=0

0 commit comments

Comments
 (0)