|
| 1 | +#!/usr/bin/env python |
| 2 | +import os |
| 3 | +import json |
| 4 | + |
| 5 | +BASE = os.path.join(os.path.dirname(__file__), '..') |
| 6 | + |
| 7 | +TEMPLATE = """ |
1 | 8 | #!/bin/bash |
2 | | -# SPDX-License-Identifier: AGPL-3.0-only |
3 | | -VERSION="1.1.2" |
| 9 | +BASE_URL="https://fs.codegrade.com/v{{VERSION}}/linux" |
4 | 10 |
|
5 | 11 | err_echo() { |
6 | 12 | (>&2 echo "$@") |
|
20 | 26 | } |
21 | 27 |
|
22 | 28 | install_deps() { |
23 | | - sudo apt-get install -qy wget python3 fuse python3-requests libnotify4 gconf2 gconf-service libappindicator1 libxtst6 libnss3 |
| 29 | + sudo apt-get install -qy wget python3 fuse python3-requests libnotify4 gconf2 gconf-service libappindicator1 libxtst6 libnss3 python3-packaging |
24 | 30 | } |
25 | 31 |
|
26 | 32 | download_file() { |
27 | 33 | local url="$1" dst="$2" |
28 | 34 | if ! wget --quiet "$url" -O "$dst"; then |
29 | | - err_echo "Failed to download file: $url" |
| 35 | + err_echo "Failed to download file: ${url}, please check if a new version is available on https://codegrade.com/download-codegrade-filesystem" |
30 | 36 | exit 10 |
31 | 37 | fi |
32 | 38 | } |
|
63 | 69 | echo "Updating package list" |
64 | 70 | sudo apt update -q |
65 | 71 |
|
66 | | - printf "\\nInstalling dependencies\\n" |
| 72 | + printf "\\\\nInstalling dependencies\\\\n" |
67 | 73 | if ! install_deps; then |
68 | 74 | err_echo "Failed to install dependencies" |
69 | 75 | exit 4 |
70 | 76 | fi |
71 | 77 | tmpdir="$(mktemp -d)" |
72 | 78 | trap '[[ -n $tmpdir ]] && rm -rf "$tmpdir"' 0 1 2 3 15 |
73 | 79 |
|
74 | | - printf "\\nDownloading all needed files\\n" |
75 | | - download_file "https://codegra.de/static/fs/linux/python3-fusepy_NEWEST-1_all.deb" "$tmpdir/fusepy.deb" |
76 | | - if is_distro "Debian"; then |
77 | | - download_file "https://codegra.de/static/fs/debian/python3-codegrade-fs_${VERSION}-1_all.deb" "$tmpdir/backend.deb" |
78 | | - else |
79 | | - download_file "https://codegra.de/static/fs/ubuntu/python3-codegrade-fs_${VERSION}-1_all.deb" "$tmpdir/backend.deb" |
80 | | - fi |
81 | | - download_file "https://codegra.de/static/fs/linux/codegrade-fs_${VERSION}_$(get_arch).deb" "$tmpdir/frontend.deb" |
| 80 | + printf "\\\\nDownloading all needed files\\\\n" |
| 81 | + download_file "${BASE_URL}/python3-fusepy.deb" "$tmpdir/fusepy.deb" |
| 82 | + download_file "${BASE_URL}/python3-codegrade-fs_all.deb" "$tmpdir/backend.deb" |
| 83 | + download_file "${BASE_URL}/codegrade-fs_$(get_arch).deb" "$tmpdir/frontend.deb" |
82 | 84 |
|
83 | 85 | if _pip list | grep -- 'CodeGra.fs'; then |
84 | | - printf "\\nRemoving old versions\\n" |
| 86 | + printf "\\\\nRemoving old versions\\\\n" |
85 | 87 | _pip uninstall -y CodeGra.fs |
86 | 88 | fi |
87 | 89 |
|
88 | | - printf "\\nInstalling our version of fusepy\\n" |
| 90 | + printf "\\\\nInstalling our version of fusepy\\\\n" |
89 | 91 | sudo dpkg -i "$tmpdir/fusepy.deb" |
90 | | - printf "\\nInstalling the backend of the CodeGrade Filesystem\\n" |
| 92 | + printf "\\\\nInstalling the backend of the CodeGrade Filesystem\\\\n" |
91 | 93 | sudo dpkg -i "$tmpdir/backend.deb" |
92 | | - printf "\\nInstalling the frontend of the CodeGrade Filesystem\\n" |
| 94 | + printf "\\\\nInstalling the frontend of the CodeGrade Filesystem\\\\n" |
93 | 95 | sudo dpkg -i "$tmpdir/frontend.deb" |
94 | 96 | rm -rf "$tmpdir" |
95 | 97 | tmpdir="" |
96 | 98 |
|
97 | | - printf "\\nDone installing the file system\\n" |
| 99 | + printf "\\\\nDone installing the file system\\\\n" |
98 | 100 | } |
99 | 101 |
|
100 | 102 | main |
| 103 | +""".lstrip() |
| 104 | + |
| 105 | + |
| 106 | +def main(): |
| 107 | + with open(os.path.join(BASE, 'package.json'), 'r') as f: |
| 108 | + version = json.load(f)['version'] |
| 109 | + |
| 110 | + dist_dir = os.path.join(BASE, 'dist') |
| 111 | + os.makedirs(dist_dir, exist_ok=True) |
| 112 | + with open(os.path.join(dist_dir, 'install_linux.bash'), 'w') as f: |
| 113 | + f.write(TEMPLATE.replace('{{VERSION}}', version)) |
| 114 | + |
| 115 | + |
| 116 | +if __name__ == '__main__': |
| 117 | + main() |
0 commit comments