Skip to content

Commit

Permalink
Confirm environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Cp0204 committed May 5, 2024
1 parent bd5aa00 commit ab83598
Showing 1 changed file with 69 additions and 61 deletions.
130 changes: 69 additions & 61 deletions app/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,84 @@ index_html_bak="${index_html}.bak"
start() {
echo "Starting..."

# Copy mod_store
if [[ ! -d "$mod_store_dir" ]]; then
echo "Creating directory ${mod_store_dir}"
mkdir -p "$mod_store_dir"
cp -r /app/mod/* "$mod_store_dir"
echo -e "Delete this folder and it will be recreated when the new version of the container is started.\n删除本文件夹,新版本容器启动时将重建。" >> "${mod_store_dir}/Get_New_MODs.txt"
fi
# Confirm environment
if [[ -f "$index_html" ]]; then
echo "Running on: CasaOS"

# Process mapping directory
for dir in "$mod_dir" "$icon_dir"; do
#Creating directory
if [[ ! -d "$dir" ]]; then
echo "Creating directory ${dir}"
mkdir -p "$dir"
fi
# Creating symlink
symlink_dir="${www_dir}/${dir##*/}"
if [[ ! -d "$symlink_dir" ]]; then
echo "Creating symlink ${dir} to ${symlink_dir}"
ln -s "$dir" "$symlink_dir"
# Copy mod_store
if [[ ! -d "$mod_store_dir" ]]; then
echo "Creating directory ${mod_store_dir}"
mkdir -p "$mod_store_dir"
cp -r /app/mod/* "$mod_store_dir"
echo -e "Delete this folder and it will be recreated when the new version of the container is started.\n删除本文件夹,新版本容器启动时将重建。" >>"${mod_store_dir}/Get_New_MODs.txt"
fi
done

# Create symlink for www_dir in config_dir
# www_link="${config_dir}/www"
# if [[ ! -d "$www_link" ]]; then
# echo "Creating symlink ${www_dir} to ${www_link}"
# ln -s "$www_dir" "$www_link"
# fi
# Process mapping directory
for dir in "$mod_dir" "$icon_dir"; do
#Creating directory
if [[ ! -d "$dir" ]]; then
echo "Creating directory ${dir}"
mkdir -p "$dir"
fi
# Creating symlink
symlink_dir="${www_dir}/${dir##*/}"
if [[ ! -d "$symlink_dir" ]]; then
echo "Creating symlink ${dir} to ${symlink_dir}"
ln -s "$dir" "$symlink_dir"
fi
done

# Backup index.html
if [[ ! -f "$index_html_bak" ]]; then
cp "$index_html" "$index_html_bak"
echo "Backup index.html"
else
cp "$index_html_bak" "$index_html"
fi
# Create symlink for www_dir in config_dir
# www_link="${config_dir}/www"
# if [[ ! -d "$www_link" ]]; then
# echo "Creating symlink ${www_dir} to ${www_link}"
# ln -s "$www_dir" "$www_link"
# fi

# Backup index.html
if [[ ! -f "$index_html_bak" ]]; then
cp "$index_html" "$index_html_bak"
echo "Backup index.html"
else
cp "$index_html_bak" "$index_html"
fi

# Build tags for mods
js_tags=""
css_tags=""
for mod_path in "$mod_dir"/*; do
mod_js_path="${mod_path}/mod.js"
mod_css_path="${mod_path}/mod.css"
if [[ -f "$mod_js_path" ]]; then
echo "Reading ${mod_js_path}"
js_tags+="<script type=\"text/javascript\" src=\"mod/${mod_path##*/}/mod.js\"></script>\n"
# Build tags for mods
js_tags=""
css_tags=""
for mod_path in "$mod_dir"/*; do
mod_js_path="${mod_path}/mod.js"
mod_css_path="${mod_path}/mod.css"
if [[ -f "$mod_js_path" ]]; then
echo "Reading ${mod_js_path}"
js_tags+="<script type=\"text/javascript\" src=\"mod/${mod_path##*/}/mod.js\"></script>\n"
fi
if [[ -f "$mod_css_path" ]]; then
echo "Reading ${mod_css_path}"
css_tags+="<link href=\"/mod/${mod_path##*/}/mod.css\" rel=\"stylesheet\">\n"
fi
done
if [[ -z "$js_tags" ]]; then
js_tags="\n<!-- CasaMOD is loaded, but no js found -->\n"
else
js_tags="\n<!-- CasaMOD js -->\n${js_tags}"
fi
if [[ -f "$mod_css_path" ]]; then
echo "Reading ${mod_css_path}"
css_tags+="<link href=\"/mod/${mod_path##*/}/mod.css\" rel=\"stylesheet\">\n"
#echo "$js_tags"
if [[ -z "$css_tags" ]]; then
css_tags="\n<!-- CasaMOD is loaded, but no css found -->\n"
else
css_tags="\n<!-- CasaMOD css -->\n${css_tags}"
fi
done
if [[ -z "$js_tags" ]]; then
js_tags="\n<!-- CasaMOD is loaded, but no js found -->\n"
else
js_tags="\n<!-- CasaMOD js -->\n${js_tags}"
fi
#echo "$js_tags"
if [[ -z "$css_tags" ]]; then
css_tags="\n<!-- CasaMOD is loaded, but no css found -->\n"
#echo "$css_tags"

# Modify index.html
sed -i "s|<title>|${css_tags}<title>|" "$index_html"
sed -i "s|<\/body>|${js_tags}<\/body>|" "$index_html"
echo "Modified index.html"

else
css_tags="\n<!-- CasaMOD css -->\n${css_tags}"
echo "Not supported on current systems."
fi
#echo "$css_tags"

# Modify index.html
sed -i "s|<title>|${css_tags}<title>|" "$index_html"
sed -i "s|<\/body>|${js_tags}<\/body>|" "$index_html"
echo "Modified index.html"

echo "Keep Running..."
while true; do
Expand Down

0 comments on commit ab83598

Please sign in to comment.