11#! /usr/bin/env bash
22# must be bash because we source a bashrc file
3+ set -ex
34if [ -n " $1 " ]; then
45 CHARM_URL=" $1 "
56fi
4243mkdir -p /etc/apt/keyrings
4344curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/nodesource.gpg
4445echo " 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+
4772npm install -g npm@latest
4873npm --version
4974node --version
5075if command -v snap; then
5176 snap install powershell --classic
5277else
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
5782fi
5883cd ~
5984if [ ! -d " code" ]; then
@@ -67,7 +92,7 @@ chmod +x *.ps1 *.sh
6792CHARM_LINK_URL=" $CHARM_LINK_URL " ./provider.sh &
6893get_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
7398start_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
97122fi
123+ echo " Obtaining charm link"
98124response=$( curl -sL " $CHARM_LINK_URL " --data-urlencode " keys=$( ./identity charm keys --simple | tr ' \n' ' ,' | sed ' s/,$//' ) " )
99125
100126if [ -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
109133else
110134 echo " Failed to obtain charm link"
111135 exit 1
112136fi
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
116142chmod +x .init
143+ echo " Running .init"
144+ set +e
117145./.init
0 commit comments